关于imcrop的一点注意事项

今天使用imcrop(img,RECT)的形式时,输出的图像总是比设置的RECT尺寸大一个像素。

网上没有说的很清楚的,查了一下matlab的help,有了点结论,仅个人理解,大家谨慎取用。


关于imcrop这个函数,matlab的help里有这么一段话。


Remarks
-------
Because RECT is specified in terms of spatial coordinates, the WIDTH
and HEIGHT 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 that are completely or partially enclosed by the
rectangle.


红体字的意思是说,参数RECT的宽和高,并不总是与输出图像的尺寸相一致。

下面举了个例子,用[20 20 40 30]为参数RECT,输出图像的尺寸是(31,41)。

这是因为RECT左上点是落在(20,20)这个像素点的中心,右下点落在(50,60)像素点的中心。(也就是这两个像素各有半个点被包含在RECT中)

但是结果图像会输出所有的,完全包含或部分包含在RECT中的像素点。即,(20,20)所在的一行列图像以及(50,60)一行列图像都会包含在结果图像中。

这就是为什么我们imcrop输出的图像总与RECT设置的宽和高不一致的原因。


另外要注意,坐标不要出现0,即使出现0,matlab也不会报错,但是依然会占用一行列。


个人理解。

你可能感兴趣的:(关于imcrop的一点注意事项)