Images as arrays
JuliaImages
are two-dimensional arrays, and every pixel can be either scalar or a one-dimensional array:
- Grayscale images represent pixels as scalar values and they are called
Gray
RGB
is a three-dimensional array which represents each point in three different colors, such as red, green, and bluePNG
images with a transparent background are calledRGBA
Accessing pixels
When you use a load
command in Julia, it reads the image and encodes it in RGB
. In the following example, we will see how Julia manages information for a single pixel:
using Images img = load("sample-images/cats-3061372_640.jpg") img[1:1, 1:1, :]
After Julia executes the preceding set of commands, you should expect to see the following output:
julia> img[1:1, 1:1, :]
1×1×1 Array{RGB4{N0f8},3}:
[:, :, 1] =
RGB4{N0f8}(0.349,0.282,0.212)
Pay attention to the last line. Our pixel is composed of an RGB
object with 0.349,0.282,0.212
being the values corresponding to the values for each of the three channels.
You will...