Not understanding a simple code.

1 view (last 30 days)
I am new in image processing and matlab as well. After searching for hours, I have failed to find what this code actually does.
I = imread('6.tif');
I = I(1:200,1:200,:);
I understand the first line is reading the image file. but the next one is confusing to me.
Please any one help me to get this. any broad explanation will be helpful for me.

Accepted Answer

Image Analyst
Image Analyst on 20 Feb 2014
It gets rows 1 to 200, and columns 1 to 200, and all 3 color channels (the third index, that's what the : means. It means "all").
  4 Comments
Image Analyst
Image Analyst on 20 Feb 2014
Edited: Image Analyst on 20 Feb 2014
Here is more robust code:
I = imread('6.tif');
[rows, columns, numberOfColorChannels] = size(I);
if numberOfColorChannels == 3
I = rgb2gray(I);
if rows > 200 && columns > 200
I = I(1:200,1:200,:); % Crop all 3 channels.
end
else
if rows > 200 && columns > 200
I = I(1:200,1:200); % Crop single channel.
end
end
Abdur Rahim
Abdur Rahim on 20 Feb 2014
Great work! I have got what is going on!!

Sign in to comment.

More Answers (0)

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!