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

后端 未结 1 821
终归单人心
终归单人心 2021-01-12 19:03
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 <

相关标签:
1条回答
  • 2021-01-12 19:35

    :, in this context means 'all'.

    red = a(:,:,1)
    

    is equivalent to

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

    where end is automatically replaced by the number of elements in the respective dimension by Matlab.

    So if a is a 23-by-55-by-3 array,

    a(:,:,1) 
    

    is

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

    That means, this takes all rows, all columns from the first 'plane' of a. Since a RGB image is composed of a red, green, and a blue plane (in this order), a(:,:,1) is the red component of the image.

    0 讨论(0)
提交回复
热议问题