Nat*_*man 11 matlab plot geometry image
我在MATLAB中有一个图像:
im = rgb2gray(imread('some_image.jpg');
% normalize the image to be between 0 and 1
im = im/max(max(im));
Run Code Online (Sandbox Code Playgroud)
我做了一些处理,产生了一些我想强调的要点:
points = some_processing(im);
Run Code Online (Sandbox Code Playgroud)
哪里points是一个矩阵大小相同im与那些在兴趣点.
现在我想在图像中绘制一个圆圈,其中所有的位置points都是1.
MATLAB中有没有这样做的功能?我能想到的最好的是:
[x_p, y_p] = find (points);
[x, y] = meshgrid(1:size(im,1), 1:size(im,2))
r = 5;
circles = zeros(size(im));
for k = 1:length(x_p)
circles = circles + (floor((x - x_p(k)).^2 + (y - y_p(k)).^2) == r);
end
% normalize circles
circles = circles/max(max(circles));
output = im + circles;
imshow(output)
Run Code Online (Sandbox Code Playgroud)
这似乎有点不优雅.有没有办法画出类似于line函数的圆圈?
gno*_*ice 21
[x_p,y_p] = find(points);
imshow(im); %# Display your image
hold on; %# Add subsequent plots to the image
plot(y_p,x_p,'o'); %# NOTE: x_p and y_p are switched (see note below)!
hold off; %# Any subsequent plotting will overwrite the image!
Run Code Online (Sandbox Code Playgroud)
您还可以调整的情节标记的这些属性:MarkerEdgeColor,MarkerFaceColor,MarkerSize.
如果您想要保存新图像并在其上绘制标记,您可以查看我给出的关于在保存图像时保持图像尺寸的问题的答案.
注意:使用IMSHOW(或IMAGE等)绘制图像数据时,行和列的正常解释基本上会被翻转.通常,数据的第一维(即行)被认为是位于x轴上的数据,这可能是您使用FIND函数x_p返回的第一组值的原因.但是,IMSHOW沿y轴显示图像数据的第一维,因此在这种情况下,FIND返回的第一个值最终为y坐标值.