What does the following colon (:) mean in MATLAB syntax?

a = imread('autumn.tif'); a = double(a); [row col dim] = size(a); red = a(:, :, 1); green = a(:, :, 2); blue = a(:, :, 3); 

What does the colon mean : in the last three lines? (The above snippet is from "Image Processing" by Dhananjay Theckedath.)

+6
syntax image-processing matlab
source share
1 answer

: , in this context means "everything."

 red = a(:,:,1) 

equivalently

 red = a(1:end,1:end,1) 

where end automatically replaced by the number of elements in the corresponding Matlab size.

So, if a is an array of 23 by 55 by 3,

 a(:,:,1) 

there is

 a(1:23, 1:55, 1) 

This means that it occupies all rows, all columns from the first "plane" a . Since an RGB image consists of a red, green, and blue plane (in that order), a(:,:,1) is the red component of the image.

+19
source share

All Articles