You may have already noticed that, in the previous example, when you load a colorful image in Julia, it is stored as a two-dimensional array of RGB4 objects. Let's look into it again in the following code:
julia> img[1:1, 1:1, :]
1×1×1 Array{RGB4{N0f8},3}:
[:, :, 1] =
RGB4{N0f8}(0.349,0.282,0.212)
Everything is good unless you want to edit the content of a specific pixel. This is achieved by decomposing RGB4 into multiple channels using the channelview function, shown as follows:
using Images, ImageView
img = load("sample-images/cats-3061372_640.jpg")
img_channel_view = channelview(img)
img_channel_view
You should be able to see an output similar to the following in your Julia REPL:
julia> img_channel_view
3×360×640 ChannelView(::Array{RGB4{N0f8},2}) with element type FixedPointNumbers.Normed{UInt8,8}:
[:, :, 1] =
0.349N0f8 0.353N0f8 0.345N0f8 0.329N0f8 ...
Done! Now, every pixel is represented by three distinct values, and we can use a matrix operation to change the content of the pixels. Let's update all of the colors with a value over 0.7 so that they are 0.9:
using Images, ImageView
img = load("sample-images/cats-3061372_640.jpg")
img_channel_view = channelview(img)
img_channel_view[img_channel_view .> 0.7] = 0.9
imshow(img)
This will result in the background colors changing:
We will look into more complicated examples and create Instagram-like filters later in this chapter.