imcrop won't work

5 ビュー (過去 30 日間)
jack
jack 2016 年 1 月 20 日
編集済み: Thorsten 2016 年 1 月 20 日
Hi guys,
I have the following problem:
I have a binary image and i have tried to imcrop the image by rect which is [1029,535,1,1] but the output of imcrop is empty.
Why is that and is there a work around so that it can be used for matrixes of 3-D, 4-D or n-D?
Thanks in advance.
  1 件のコメント
Guillaume
Guillaume 2016 年 1 月 20 日
What is the size of your image?

サインインしてコメントする。

回答 (2 件)

Thorsten
Thorsten 2016 年 1 月 20 日
編集済み: Thorsten 2016 年 1 月 20 日
I = rand(1000, 2000);
rect = [1029,535,1,1];
Ic = imcrop(I, rect)
The thing to remember is that the rect is given by [xmin, ymin, width, height], so x comes first, but the matrix is indexed as row, col, so y/row comes first...
Note that imcrop basically does nothing else than
Ic = I(ymin:ymin+height, xmin:xmin+width);

Image Analyst
Image Analyst 2016 年 1 月 20 日
編集済み: Image Analyst 2016 年 1 月 20 日
Jack, the array is [left, top, width, height]. You have [1029,535,1,1] which means you're probably starting out with the upper left corner way down in the bottom right corner of your image (which may or may not be fine). It's fine if your image is a lot bigger than 535 rows by 1029 columns. But the main problem is that your width and height are 1 so you're getting only a single pixel. And that one pixel may be black for all I know.
Also pay attention to what Thorsten said - mixing up rows,columns with x,y is an extremely common beginner mistake. They're reverse order of each other.
If you want to crop out a 535 row by 1029 column chunk of the upper left corner of the image, you want [1, 1, 1029, 535]
imcrop() works for 2D images. It works for 3D if the image is an RGB image but not if it's a volumetric image. For higher dimensions, use indexing like
croppedArray = array(i1low:i1high, i2low:i2high, i3low:i3high, i4low:i4high); % etc.
  1 件のコメント
Thorsten
Thorsten 2016 年 1 月 20 日
編集済み: Thorsten 2016 年 1 月 20 日
Small correction: you get a 2x2 matrix for a rect [xmin xmax 1 1], not a single pixel.

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by