3 ms·
> My example of this is the Colors.jl package. Images, rather than being 3D arrays of floats/ints, instead become 2D arrays of RGB/HSV. But you can't do any ari
by markkitti 4y ago
> My example of this is the Colors.jl package. Images, rather than being 3D arrays of floats/ints, instead become 2D arrays of RGB/HSV. But you can't do any arithmetic on RGB/HSV values, you need ColorVectorSpace.jl for that. I'm sure it makes sense, but I can't help but feel as if sense is taking precedence over the programmer's experience in many of these packages.
If you just used Images.jl, it would load both Colors.jl and ColorVectorSpace.jl.
Let's say you obtained one of the matrices of RGB values, but you wanted a 3D array of numbers. `channelview` will provide you with a no-copy representation of the image as exactly that.
```
julia> using Images, TestImages
julia> img = testimage("barbara_color.png");
julia> typeof(img)
Matrix{RGB{N0f8}} (alias for Array{RGB{Normed{UInt8, 8}}, 2})
julia> channelview(img) |> ndims
3
```
While it took getting used to, have an image processing framework that explicitly has a concept of color instead of generically mapping everything into an array is actually quite useful. Having a 2D array representing a 2D image is conceptually quite nice.
Also you can do arithmetic on RGB or HSV types directly.
```
julia> (RGB(1,0,0) + RGB(0,1,0))/2
RGB{Float32}(0.5f0,0.5f0,0.0f0)
```