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

Multiplication between RGB types seems to be missing #119

Closed
a-r-n-o-l-d opened this issue Jan 10, 2020 · 7 comments
Closed

Multiplication between RGB types seems to be missing #119

a-r-n-o-l-d opened this issue Jan 10, 2020 · 7 comments

Comments

@a-r-n-o-l-d
Copy link

julia> RGB{Float64}(1, 1, 1) * RGB{Float64}(1, 1, 1)
ERROR: MethodError: no method matching *(::RGB{Float64}, ::RGB{Float64})
Closest candidates are:
  *(::Any, ::Any, ::Any, ::Any...) at operators.jl:529
  *(::Real, ::AbstractRGB) at /home/afertin/.julia/packages/ColorVectorSpace/wI546/src/ColorVectorSpace.jl:123
  *(::AbstractRGB, ::Real) at /home/afertin/.julia/packages/ColorVectorSpace/wI546/src/ColorVectorSpace.jl:147
  ...
Stacktrace:
 [1] top-level scope at none:0

If I add:

import Base.*, ColorVectorSpace.color_rettype, ColorVectorSpace.multype
(*)(a::AbstractRGB{S}, b::AbstractRGB{T}) where {S,T} = color_rettype(a,b){multype(S,T)}(red(a)*red(b), green(a)*green(b), blue(a)*blue(b))

therefore, I can multiply two RGB images.

@timholy
Copy link
Member

timholy commented Jan 10, 2020

Why is channelwise the right definition of rgb1*rgb2? What if someone else thinks it should be the channelwise dot product? And someone else thinks it's the outer product,

[r1*r2 r1*g2 r1*b2;
 g1*r2 g1*g2 g1*b2;
 b1*r2 b1*g2 b1*b2]

@a-r-n-o-l-d
Copy link
Author

OK I understand the ambiguity here. I was surprised, because channelwise product is more common in image processing libraries. Sorry about that.

@timholy
Copy link
Member

timholy commented Jan 10, 2020

julia> using Colors

julia> chantimes(c1, c2) = mapc(*, c1, c2)
chantimes (generic function with 1 method)

julia> c1, c2 = rand(RGB{Float32}), rand(RGB{Float32})
(RGB{Float32}(0.5848855f0,0.29970312f0,0.60462904f0), RGB{Float32}(0.57155025f0,0.32285166f0,0.91198397f0))

julia> chantimes(c1, c2)
RGB{Float32}(0.33429143f0,0.09675965f0,0.551412f0)

julia> using TestImages

julia> img = testimage("lighthouse");

julia> chantimes.(img, img)

If this is not discoverable, a democard would be wonderful!

@timholy
Copy link
Member

timholy commented Jan 10, 2020

Actually, it also occurs to me that we might have enough operators to distinguish this: (\cdot), *, and (\otimes). Assuming all these are broadcastable then perhaps we could define this operation. What do others think?

@johnnychen94
Copy link
Member

johnnychen94 commented Jan 11, 2020

Assuming all these are broadcastable then perhaps we could define this operation.

Great idea and I think it would be really useful! Although for me the only problem is that I can't type these symbols in vscode 😂

@timholy
Copy link
Member

timholy commented Jan 11, 2020

julia-vscode/julia-vscode#613 suggests you might try this extension: https://marketplace.visualstudio.com/items?itemName=GuidoTapia2.unicode-math-vscode

@timholy
Copy link
Member

timholy commented Jan 21, 2021

Closed by #131

@timholy timholy closed this as completed Jan 21, 2021
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