![]() |
如何在MATLAB中的图像上画圆?
我在MATLAB中有一张图片:
im = rgb2gray(imread('some_image.jpg'); % normalize the image to be between 0 and 1 im = im/max(max(im)); 我已经进行了一些处理,得出了许多要强调的要点: points = some_processing(im); 其中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) 这似乎有点不雅。有没有办法绘制类似于line功能的圆? 回答: 您可以使用带有[URL="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/lineseriesproperties.html#Marker"]圆形标记点[/URL]的普通[URL="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/plot.html"]PLOT[/URL]命令: [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! 您还可以调整绘图标记的其他这些属性: [URL="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/lineseriesproperties.html#MarkerEdgeColor"]MarkerEdgeColor[/URL] , [URL="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/lineseriesproperties.html#MarkerFaceColor"]MarkerFaceColor[/URL] , [URL="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/lineseriesproperties.html#MarkerSize"]MarkerSize[/URL] 。 如果随后要保存新图像并在其上绘制标记,则可以查看[URL="https://stackoverflow.com/questions/1848176/how-do-i-save-a-plotted-image-and-maintain-the-original-image-size-in-matlab/1848995#1848995"]这个答案,我回答了[/URL]一个有关从图形保存图像时保持图像尺寸的问题。 [B]注意:[/B]使用[URL="http://www.mathworks.com/access/helpdesk/help/toolbox/images/imshow.html"]IMSHOW[/URL] (或[URL="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/image.html"]IMAGE[/URL]等)绘制图像数据时,对行和列的常规解释实际上会发生翻转。通常,数据的第一维(即行)被认为是x轴上的数据,这可能就是为什么将x_p用作[URL="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/find.html"]FIND[/URL]函数返回的第一组值的原因。但是,IMSHOW在[I]y轴上[/I]显示图像数据的第一维,因此在这种情况下,FIND返回的第一值最终成为[I]y坐标值[/I] 。 [url=https://stackoverflow.com/questions/1860760]更多&回答...[/url] |
所有时间均为北京时间。现在的时间是 02:03。 |
Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.