【问题标题】:How to change color of edge in MATLAB?如何在 MATLAB 中改变边缘的颜色?
【发布时间】:2018-05-03 19:50:36
【问题描述】:

我有一个脚本,它获取图像并应用一些边缘检测方法,例如 canny、sobel 和 log。当我运行该文件时,会在边缘为白色的地方绘制一个图形。

有没有办法将边缘的颜色更改为首选颜色?

function cw1
  im0 = imread('lighthouse.png');
  im = rgb2gray(im0);
  im3 = edge(im,'canny');
  im4 = edge(im, 'sobel');
  im5 = edge(im, 'log');
  im2 = my_edge1(im);
  subplot(3,2,1), subimage(im); title ('Original'); axis off
  subplot(3,2,2), subimage(im2); title ('My Edge'); axis off
  subplot(3,2,3), subimage(im3); title ('Canny'); axis off
  subplot(3,2,4), subimage(im4); title ('Sobel'); axis off
  subplot(3,2,5), subimage(im5); title ('Log'); axis off
end

【问题讨论】:

标签: image matlab colors matlab-figure edge-detection


【解决方案1】:

这个问题的定义并不完全明确,但无论如何我都会尽力提供帮助。这是一个使用绿色边缘的演示:

function q47394633
  im = rgb2gray(imread('peppers.png'));
  e = edge(im); % logical matrix, where "true" indicates an edge.
  g = reshape(uint8([0 255 0]),[1,1,3]) .* uint8(e); % Turn the above to RGB while making
  figure();                                          % only the green channel nonzero.
  subplot(3,1,1); imshow(e);    % Show white edges
  subplot(3,1,2); imshow(g);    % Show green edges
  subplot(3,1,3); imshow(im+g); % Show green edges on the image
end

【讨论】:

  • 是的,这就是我想问的。
  • 好。如果此回答对您有所帮助,请考虑accepting it 标记此问题已解决。
  • @Rajan 看到g = reshape(uint8([0 255 0]),[1,1,3]) .* uint8(e); 的行了吗?现在而不是g 放入g2...g5,而不是e 放入im2...im5 然后,如果你想绘制边缘使用g2...g5,如果你想要灰度图像上的边缘使用im+g2...g5,并且如果你想要彩色图像的边缘 - 使用im0+g2...g5。关于您的代码,它应该出现在您的问题中,而不是评论中。这次我为你添加了它(问题),但请确保你从一开始就添加它。
  • g2 到 g5 和 im2 到 im5 是否需要重复
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-17
  • 2016-11-29
  • 2012-07-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多