【发布时间】:2017-01-27 15:29:28
【问题描述】:
我了解像素元素存储在单元格的中心。但是,我需要使用边缘和角落的坐标而不是中心坐标。
该代码可用于提取下图中显示的所有内部节点。
%obtain the pixel width
pixelsPerInch = get(0, 'ScreenPixelsPerInch');
mmPerInch = 25.4;
mmPerPixel = mmPerInch / pixelsPerInch;
[nrow, ncol] = size(Img);
for ii = 1: nrow - 1
for jj = 1: ncol - 1
% determine the distance of each pixel from the origin
x_mm(jj) = jj * mmPerPixel;
y_mm(ii) = ii * mmPerPixel;
% determine the nodal coordinates
node_x(jj) = (x_mm(jj) + (mmPerPixel/2))/mmPerPixel;
node_y(ii) = (y_mm(ii) + (mmPerPixel/2))/mmPerPixel;
end
end
%%%%% merge the x and y-coords
[node_y, node_x] = meshgrid(node_y, node_x);
my_nodes = [node_y(:), node_x(:)];
为了找到任何节点上方、下方或两侧的边缘中心,所需要做的就是根据一个人打算去的方向,从 node_x 和 node_y 中加上或减去 1/2。例如,要找到任何节点上方的边,请执行以下操作:
jx = node_x;
iy = node_y - 0.5;
人们也可以通过决定是否从兴趣点的 x 和 y 坐标中加/减 1/2 来找到每个兴趣节点的像素中心。
【问题讨论】:
-
不确定 Matlab 的人是做什么的,但是使用 ImageMagick,您只需将
1/2添加到每个坐标... imagemagick.org/Usage/draw/#coordinates跨度> -
@MarkSetchell 取决于 OP 希望他的最终输出是什么样子(在他的显示器上可能以
mm或inches为单位),这还不够。在从图像矩阵中的像素坐标中添加/减去1/2后,您必须进行一些后期处理,以将其转换为有意义的距离单位。 -
这仅对应于半个像素的移位。在许多应用中,区别是无关紧要的。在其他情况下,无需调整单个坐标,只需在适用的情况下对结果进行后处理即可。