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

add format specifier to color view #125

Open
CarloLucibello opened this issue Mar 18, 2020 · 2 comments
Open

add format specifier to color view #125

CarloLucibello opened this issue Mar 18, 2020 · 2 comments

Comments

@CarloLucibello
Copy link

CarloLucibello commented Mar 18, 2020

with most of the julia machine learning ecosystem working with image tensors in WHC or WHCN format, maybe it could be convenient to add a string argument to colorview to specify the input tensor format:

x = rand(32, 32, 3, 1000)  # batch of images in WHCN format

imgs = colorview(RGB, permutedims(x, (3, 2, 1, 4)))  # current 

imgs = colorview(RGB, x, "WHCN")  # proposed
@johnnychen94
Copy link
Member

johnnychen94 commented Mar 18, 2020

The roles of colorview and channelview are to lazily convert between numerical array and array of structs/Colorants. It has no prior information about x if it's a plain array, so adding this feature in ImageCore isn't a good idea to me.

Said that, if x is AxisArray, which are cases we do have prior information about the dims of x, it's okay to support this functionality in ImageAxes, but my guess is that might not make things easier unless the whole processing pipeline is built upon AxisArrays. I mean, if you don't label the dims of x clearly, there's no way to guarantee that it works as expected.

@timholy
Copy link
Member

timholy commented Mar 18, 2020

I think we could add signaling types to do this. We need the return type of colorview to be inferrable, though. We could see if constant-propagation works for colorview(RGB, x, :WHCN) but more likely we'd want to define a dummy wrapper type so this is colorview(RGB, WHCN(x)).
It would only be a few lines of code to define WHC and WHCN types. Any others come to mind?

Keep in mind that colorview will never guarantee stridedness etc, because as @johnnychen94 says it's specifically to return a view.

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

No branches or pull requests

3 participants