Not understanding a simple code.
1 view (last 30 days)
Show older comments
Abdur Rahim
on 20 Feb 2014
Commented: Abdur Rahim
on 20 Feb 2014
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.
0 Comments
Accepted Answer
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
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
More Answers (0)
See Also
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!