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

本秂侑毒 提交于 2020-01-11 05:19:05

问题


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 : in the last three lines mean? (The above snippet is from "Image Processing" by Dhananjay Theckedath.)


回答1:


:, 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.



来源:https://stackoverflow.com/questions/3955203/what-does-the-following-colon-mean-in-matlab-syntax

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!