imcrop won't work

조회 수: 11 (최근 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