poly2mask matlab 的基本坐标

Base coordinate for poly2mask matlab

请问MATLAB中poly2mask函数使用的图像坐标系中的原点像素是多少

别人在OpenCV里问过,不知道在MATLAB里是不是一样。让我重复这个人的问题:

In general there may be two kinds of such systems, for the first (0,0) is defined as the center of the upper left pixel, which means the upper left corner of the upper left pixel is (-0,5, -0.5) and the center of the image is ((cols - 1) / 2, (rows - 1) / 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函数采用的是什么系统?

MATLAB 使用从 1 开始的索引,而不是从 0 开始的索引。因此,top-left 像素的中心位于 (1,1)。 poly2mask 遵循相同的约定,它们在 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) 点附近画了一个多边形,蒙版显示了标记的 top-left 像素。如果围绕(0.5,0.5)点绘制多边形,没有标记像素:

>> 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)。例如:

>> 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)