Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduce StructArrays #170

Open
johnnychen94 opened this issue Aug 11, 2021 · 10 comments · May be fixed by #179
Open

introduce StructArrays #170

johnnychen94 opened this issue Aug 11, 2021 · 10 comments · May be fixed by #179

Comments

@johnnychen94
Copy link
Member

We only have native support for an array of struct layout, the struct of array layout uses channelview/colorview but it losses the colorant information.

We might want to introduce StructArray to do some internal memory layout shifting without affecting the interface; it's still array of colorant but storing in a struct of array layout.

img = testimage("mandril")
out = StructArray(img)

out  == img # true

Of course, need some more sophiscate benchmark to decide this.

@kimikage
Copy link

One concern is that we do not recommend direct access to the fields of the AbstractRGB types.

@johnnychen94
Copy link
Member Author

One concern is that we do not recommend direct access to the fields of the AbstractRGB types.

There are some justified use cases for this (e.g., filtering, per-channel algorithms), if StructArray simplifies the development without loss of performance then we should advertise it and perhaps providing native support inside JuliaImages.

I'm also considering hyperspectral images where pixel doesn't necessarily have traditionally colorant information. @maxfreu wondering if you have tried this package before?

@kimikage
Copy link

@Tokazama might also be interested in this...?
xref: JuliaImages/Images.jl#908

@kimikage
Copy link

WRT the interoperability between planar and packed (interleaved) formats, I was looking for a good way to handle chroma subsampling.

Chroma subsampling requires more sophisticated processing than StructArray, since it is not limited to a one-to-one correspondence between components and pixels. Chroma subsampling has many minor variations, so "I” have abandoned comprehensive support for it. However, it would be nice if it was supported (in a separate package from ImageCore.jl).

@Tokazama
Copy link
Contributor

There are some really nice things about StructArray, but there are also some limitations that I don't see going away.
Perhaps it's enough to put a quick line in the docs on how to do this conversion by hand, because it should be a couple lines of code at the most.

@johnnychen94
Copy link
Member Author

There are some really nice things about StructArray, but there are also some limitations that I don't see going away.

Would you mind explaining this a bit more? I'm not sure what specific limitations you're talking about. The unavoidable extra memory allocation, or something else?

@maxfreu
Copy link

maxfreu commented Aug 12, 2021

@maxfreu wondering if you have tried this package before?

Yes, for rearranging storage layout of particles in 3D space in an MD sim. I can imagine how it could help e.g. with efficient transformations of keypoints in augmentor, but I do not yet see how it helps with multispectral images. But I'm clearly lacking experience here.

@timholy
Copy link
Member

timholy commented Aug 12, 2021

I'm also considering hyperspectral images where pixel doesn't necessarily have traditionally colorant information.

ColorTypes.jl was designed with this possibility in mind; in particular, the @makealpha macro was designed to allow you to add alpha-channel variants to custom types. For a particular camera you presumably know the characteristics of the hyperspectral output, and hence one could define

struct MyHSCamera <: Color{N0f16,8}
    channeldata::NTuple{8,N0f16}
end

and implement a few traits, and you'd theoretically be good to go.

@Tokazama
Copy link
Contributor

I'm mostly referring to allocations, but it also depends on a lot of the Tables ecosystem. The only benefit this provides over MappedArrays is that it allows you to access each channel using getproperty syntax.

@timholy
Copy link
Member

timholy commented Aug 30, 2021

I've also noticed performance gaps between reinterpretc(RGB{T}, PermutedDimsArray(img, (3, 1, 2))) and a more direct implementation of HWC images. StructArrays might be able to help there, not sure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants