Reputation: 103
I want to use imcrop to crop images in matlab. But, sometimes it results the images which has one size more than what I want. Basically, my question is same as this. http://www.mathworks.se/matlabcentral/answers/46737-how-do-i-make-the-imcrop-function-accurate-to-the-pixel But, even this is not solved. Please help!
Upvotes: 1
Views: 4660
Reputation: 103
I could not really resolve the problem. But, I applied a simple work around. I used imcrop to crop with the desired sizes. And then resize the cropped image to desired size again.
Upvotes: 2
Reputation: 5664
imcrop
does return the "right size", i.e. the size specified in its documentation. A rectangle r1 = [20 20 40 30]
is always not sometimes 21 by 11 pixels wide.
If your expectation of what the right size should be is different, you could index the rectangle differently. If you want a rectangle with pixel (20,20) as its upper left edge and 20 pixels tall and 10 pixels wide, you can specify r1 = [20, 20, 39, 29]
.
imcrop
works like this because it operates on image data consisting of pixels. Pixels are being indexed, not points in space. Mathematically, a point has no width and no height, but a pixel has the width and height of one pixel.
To provide an extreme example, r2 = [5, 6, 8, 9]
includes the pixels from row 5 to 6 and column 8 to 9, and is thus 2 by 2 pixels wide.
Upvotes: 2