Hi I have a problem croping an image. This is my code but everytime it throws me an error that says "Index exceeds matrix dimensions". In matlab2008 it worked fine, I really don´t know why in matlab2014 throws me this error.
[filename pathname] = uigetfile({'*.jpg';'*.bmp';'*.tiff'},'File Selector');
images = strcat(pathname, filename);
axes(handles.axes1);
imshow(images);
axes(handles.axes2);
im = imread (images);
e1a1=im(200:1000,2:500);
imagesc(e1a1);

 採用された回答

Image Analyst
Image Analyst 2015 年 11 月 26 日

0 投票

The image in R2008 was either bigger than 1000 by 500, or it was grayscale. You're either now using a smaller image, or a color one.
fullFileName = fullfile(pathname, filename);
im = imread(fullFileName );
[rows, columns, numberOfColorChannels] = size(im);
if rows < 1000 && columns < 500
message = sprintf('Error: this image is too small.\nIt has %d rows and %d columns\nand needs at least\n1000 rows and at least 500 columns', rows, columns);
uiwait(errordlg(message));
return;
end
if numberOfColorChannels > 3
% Color image
e1a1 = im(200:1000, 2:500, :);
else
% Grayscale image
e1a1 = im(200:1000, 2:500);
end

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeImages についてさらに検索

質問済み:

2015 年 11 月 26 日

回答済み:

2015 年 11 月 26 日

Community Treasure Hunt

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

Start Hunting!

Translated by