问题描述
我想问一下MATLAB poly2mask
函数中使用的图像坐标系中的原点是什么.
I would like to ask that what's the origin pixel in the image coordinate system used in poly2mask
function in MATLAB.
在OpenCV中有人问过它,想知道在MATLAB中是否相同.让我重复这个人的问题:
It's been asked by others in OpenCV and wonder if it's the same in MATLAB. Let me repeat the person's question:
另一个是(0,0)是左上像素的左上角,所以左上像素的中心是(0.5,0.5),图像的中心是(cols/2,行/2).
The other one is that (0,0) is the upper left corner of the upper left pixel, so the center of the upper left pixel is (0.5, 0.5) and the center of the image is (cols / 2, rows / 2).
我的问题是MATLAB的poly2mask
函数采用哪种系统?
My question is which system is adopted in poly2mask
function in MATLAB?
推荐答案
MATLAB使用基于1的索引,而不是基于0的索引.因此,左上像素的中心为(1,1). poly2mask
遵循相同的约定,在MathWorks上非常一致.
MATLAB uses 1-based indexing, not 0-based indexing. Consequently, the top-left pixel has the center at (1,1). poly2mask
follows the same convention, they're pretty consistent at the MathWorks.
此实验显示以下内容:
>> poly2mask([0.8,1.2,1.2,0.8],[0.8,0.8,1.2,1.2],3,5)
ans =
3×5 logical array
1 0 0 0 0
0 0 0 0 0
0 0 0 0 0
我在(1,1)点附近绘制了一个多边形,遮罩显示了标记的左上像素.如果在(0.5,0.5)点周围绘制多边形,则不会标记任何像素:
I drew a polygon closely around the (1,1) point, and the mask shows the top-left pixel marked. If you draw a polygon around the (0.5,0.5) point, no pixel is marked:
>> poly2mask([0.8,1.2,1.2,0.8]-0.5,[0.8,0.8,1.2,1.2]-0.5,3,5)
ans =
3×5 logical array
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
容易出错的一件事是轴的顺序.第一个索引是y,第二个索引是x.但是图像处理工具箱(和其他地方)中的许多函数都将坐标表示为(x,y),而不是(y,x).例如:
The one thing that is easy to make mistakes with is the order of the axes. The first index is y the second is x. But many functions in the Image Processing Toolbox (and elsewhere) take coordinates as (x,y), rather than as (y,x). For example:
>> poly2mask([0.8,1.2,1.2,0.8]+1,[0.8,0.8,1.2,1.2],3,5)
ans =
3×5 logical array
0 1 0 0 0
0 0 0 0 0
0 0 0 0 0
在这里,x = 2,y = 1,并且设置了像素ans(1,2)
!
Here, x = 2 and y = 1, and the pixel ans(1,2)
is set!
这篇关于Poly2Mask Matlab的基本坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!