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 a channelwise macro #817

Closed
johnnychen94 opened this issue Aug 23, 2019 · 5 comments
Closed

add a channelwise macro #817

johnnychen94 opened this issue Aug 23, 2019 · 5 comments
Labels
enhancement Adds a new feature.

Comments

@johnnychen94
Copy link
Member

johnnychen94 commented Aug 23, 2019

I don't have a specific implementation in mind, but the following usage is really common:

cv_x = channelview(x)
cv_y = channelview(y)
cv_z = foo(cv_x, cv_y)
z = colorview(colortype(eltype(x)), cv_z)

If we could replace this as something like...

@channelwise z = foo(x, y)

Similarly, replace

cv_x = channelview(x)
cv_y = channelview(y)
rst = psnr(cv_x, cv_y)

as

rst = @channelwise psnr(x, y)

This is a very draft idea.

@Tokazama
Copy link

Is the main advantage here more concise code?

@johnnychen94
Copy link
Member Author

johnnychen94 commented Aug 24, 2019

That's one and the main advantage.

To support N-D array, in JuliaImages we take pixels as array elements. This is a great design, however, this would cause confusion when someone directly calls a function without channelview it.

For example, for RGB images, Minkowski{2} distance isn't equivalent to Euclidean distance. JuliaImages/ImageDistances.jl#16 (comment)

Introducing this macro would make this situation easy to explain and easy to avoid. "Okay, you forgot to use it channelwisely"

If both channelwised version and non-channelwised version can be called in one line; it's much easier to spell 😃 .

@AliMalik9599
Copy link

Hey @johnnychen94 I am planning on working on this if it hasn't been added. I am relatively new to Julia, any tips on getting started? Thanks!

@johnnychen94
Copy link
Member Author

johnnychen94 commented Jul 26, 2020

I believe some understanding of the color systems of JuliaImages, and the metaprogramming would be sufficient for you to start with. Actually, there's a WIP PR for this JuliaImages/ImageCore.jl#105 that you can use as a reference. Part of the reason I didn't continue it is because I wasn't very familiar with macros and I am still not. 😢

Speaking of performance, this @channelview is probably not a good option (see the comments
JuliaImages/ImageCore.jl#105 (comment)) , but I should say we need benchmarks to say so.

@johnnychen94
Copy link
Member Author

Abusing channelview has the tendency to goes against our best practice and thus hurt the performance so now I realize that we shouldn't provide this.

I'm closing this in favor of the docs JuliaImages/juliaimages.github.io#206 and alternative JuliaImages/ImageCore.jl#170

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

No branches or pull requests

3 participants