如何在matlab中将图像的像素坐标x和y转换为图像?

use*_*472 0 matlab pixel image-processing coordinates

我有一组向量x和y,它包含图像的像素坐标.我需要使用Matlab将这些值转换为图像.我该如何使用这些值?哪个功能最适合它?我使用的代码是:

I = imread('D:\majorproject\image\characters\ee.jpg');

imshow(I)

BW =im2bw(I);

BW=imcomplement(BW);

imshow(BW)

dim = size(BW);

col = round(dim(2)/2)-90;

row = find(BW(:,col), 1 );

boundary = bwtraceboundary(BW,[row, col],'N');

imshow(I)

hold on;

plot(boundary(:,2),boundary(:,1),'0','LineWidth',3);

BW_filled = imfill(BW,'holes');

boundaries = bwboundaries(BW_filled);

for k=1:10

   b = boundaries{k};

   plot(b(:,2),b(:,1),'g','LineWidth',3);
end
Run Code Online (Sandbox Code Playgroud)

从中我得到了坐标值.谢谢.

ray*_*ica 5

避免使用循环并考虑使用sub2ind索引到输出图像. sub2ind(x,y)坐标转换为线性索引,以便您可以使用单个命令索引所需的内容:

img = false(size(I));
img(sub2ind(size(I), y, x)) = true;
imshow(img);
Run Code Online (Sandbox Code Playgroud)

这里xy表示行的坐标,假设他们开始在1.如果xy的坐标,只需简单更换输入参数:

img = false(size(I));
img(sub2ind(size(I), x, y)) = true;
imshow(img);
Run Code Online (Sandbox Code Playgroud)

此外,I您的图像是否被读入imread.由于您希望拥有与尺寸相同的图像I,我们当然可以利用这一事实来创建输出图像.


或者,您可以使用sparse直接索引到矩阵并将位置设置为1,然后转换回full logical矩阵:

img = sparse(y, x, true, size(I,1), size(I,2));
%img = sparse(x, y, true, size(I,1), size(I,2)); %// Use this if x is row and y is column
img = full(img);
imshow(img);
Run Code Online (Sandbox Code Playgroud)