MATLAB Answers

how do i make the imcrop function accurate to the pixel?

19 views (last 30 days)
mat
mat on 26 Aug 2012
Edited: Image Analyst on 5 Jan 2014
hi,
there is a tip in the help browser imcrop section which says:
"Because rect is specified in terms of spatial coordinates, the width and height elements of rect do not always correspond exactly with the size of the output image. For example, suppose rect is [20 20 40 30], using the default spatial coordinate system. The upper-left corner of the specified rectangle is the center of the pixel (20,20) and the lower-right corner is the center of the pixel (50,60). The resulting output image is 31-by-41, not 30-by-40, because the output image includes all pixels in the input image that are completely or partially enclosed by the rectangle."
is there a way to overcome this accuracy issue and get pixel precise output?
thanks a lot,

Answers (1)

Image Analyst
Image Analyst on 26 Aug 2012
Subtract 1 from the width and height. I agree that "center-to-center" pixel measurements can be confusing when you would really like "whole" pixels. For example, how long is this stretch of 1 pixels:
0 0 0 0 0
0 1 1 1 0
0 0 0 0 0
Is it 3 long, or 2 long? It depends on if you're considering whole pixels or going from center to center, respectively.
And they aren't always consistent on how they do it (just look at bwarea vs regionprops). I'll bring it up with them. (I've already discussed with them the annoyances we sometimes face with functions dealing with 0-1 instead of gray levels.)
  2 Comments
Image Analyst
Image Analyst on 5 Jan 2014
No. They don't always act on my suggestions, and when they do they don't let me know in advance and I find out afterwards, like when they review my list and say "Oh, we implemented that 2 versions ago." But is my answer good enough for you to mark it as "Accepted"?

Sign in to comment.

Categories

Tags

Community Treasure Hunt

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

Start Hunting!