如何将点列表转换为二进制矩阵?希望该操作适用于640x640图像。这是一个例子:
% the points
p = [2 2;2 3;3 3]
% the images is 4x4
img=zeros(4,4)
% set img to 1 for all points in p
???这是个问题吗?
%得到二进制图像 img =
0 0 0 0
0 1 0 0
0 1 1 0
0 0 0 0
答案 0 :(得分:0)
您可以这样做:
img(sub2ind(size(img), p(:,2), p(:,1))) = 1;
例如:
p = [2 2;2 3;3 3];
img = zeros(4,4);
img(sub2ind(size(img), p(:,2), p(:,1))) = 1
这会给你:
img =
0 0 0 0
0 1 0 0
0 1 1 0
0 0 0 0
答案 1 :(得分:0)
这个怎么样:
linearInd = sub2ind(size(img), p(:,2), p(:,1));
img(linearInd) = 1;