Hi all
I’m new to Julia, working on a script to perform flat field correction on images (as an introductory project, coming from python).
using TestImages, Images, Statistics
img = testimage("mandrill")
Now, looking at the following operations:
-
test = img.*0.5
→ works -
test = img.+img
andtest = img.-img
→ works -
test = img.*img
andtest = img./img
→ doesn’t work:
ERROR: MethodError: no method matching *(::RGB{Normed{UInt8,8}}, ::RGB{Normed{UInt8,8}})
Closest candidates are:
*(::Any, ::Any, ::Any, ::Any...) at operators.jl:529
*(::Normed, ::AbstractRGB{T}) where T<:Normed at C:\Users\paulyk\.juliapro\JuliaPro_v1.4.1-1\packages\ColorVectorSpace\B9KU5\src\ColorVectorSpace.jl:130
*(::Real, ::AbstractRGB{T}) where T<:Normed at C:\Users\paulyk\.juliapro\JuliaPro_v1.4.1-1\packages\ColorVectorSpace\B9KU5\src\ColorVectorSpace.jl:126
...
Stacktrace:
[1] _broadcast_getindex_evalf at .\broadcast.jl:631 [inlined]
[2] _broadcast_getindex at .\broadcast.jl:604 [inlined]
[3] getindex at .\broadcast.jl:564 [inlined]
[4] copy at .\broadcast.jl:854 [inlined]
[5] materialize(::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{2},Nothing,typeof(*),Tuple{Array{RGB{Normed{UInt8,8}},2},Array{RGB{Normed{UInt8,8}},2}}}) at .\broadcast.jl:820
[6] top-level scope at none:0
Consequently, statistics like test = median(img, dims=(1,2))
also don’t work with a similar error. Any ideas why? I am able to get it working by “converting” to channelview:
img_chanview = channelview(img)
test = img_chanview.*img_chanview
median = median(channelview(img),dims=(2,3))
That works, however this whole process seems to be much slower compared to reading images in as numpy arrays in python and doing similar operations. My RGB files are 36 MP and I need to recombine frames like this. I am working on a laptop Windows 10, intel i7-6600U CPU, the whole process of reading images, converting/operating and writing back to image file took roughly 4.5 sec/image in python but using channelview around 15 sec/image in Julia, so I’m trying to understand how to do it as efficiently as possible.
Best regards
Klaas