Matlab操纵边缘(Matlab manipulate edges)

我正在做一个图像处理项目。 我有一个灰度图像和检测到边缘与Canny边缘检测。 现在我想通过过滤不必要的边来操纵结果。 我想保持接近水平的边缘并删除接近垂直的边缘。

如何删除接近垂直的边缘?


I'm working on an image processing project. I have a grayscale image and detected edges with Canny edge detection. Now I would like to manipulate the result by filtering the unnecessary edges. I would like to keep the edges which are close to horizontal and delete edges which are close to vertical.

How can I delete the close to vertical edges?

2023-02-05 17:02

满意答案

这取决于允许的成本密集程度。 一个简单的方法是:

(1)使用Sobel-Filters对图像进行卷积(给出Dx,Dy)。

对于每个canny-edge-pixel:

(2)标准化(Dx,Dy),st在您拥有边缘方向的每个像素中。

(3)用你想要移除的方向计算内积(在你的情况下为(0,1))。

(4)如果内积的绝对值小于某个阈值,则移除像素。

例:

img = ...;
canny_img = ...;
removeDir = [0;1];
% convolute with sobel masks
sobelX = [1, 0, -1; 2, 0, -2; 1, 0, -1];
sobelY = sobelX';
DxImg = conv2(img,sobelX,'same');
DyImg = conv2(img,sobelY,'same');
% for each canny-edge-pixel:
for lin = 1:size(img,1) % <-> y
    for col = 1:size(img,2) % <-> x
        if canny_img(lin,col)
            % normalize direction
            normDir = [DxImg(lin,col); DyImg(lin,col)];
            normDir = normDir / norm(normDir,2);
            % inner product
            innerP = normDir' * removeDir;
            % remove edge?
            if abs(innerP) < cos(45/180*pi) % 45° threshold
                canny_img(lin,col) = 0;
            end
        end
    end
end

根据您的要求,您可以对其进行大量优化。


It depends on how cost-intensive it is allowed to be. One easy way to do would be:

(1) Convolute your image with Sobel-Filters (gives Dx, Dy).

For each canny-edge-pixel:

(2) Normalize (Dx, Dy), s.t. in every pixel you have the direction of your edge.

(3) Compute the inner products with the direction you want to remove (in your case (0,1)).

(4) If the absolut value of the inner product is smaller than some threshold remove the pixel.

Example:

img = ...;
canny_img = ...;
removeDir = [0;1];
% convolute with sobel masks
sobelX = [1, 0, -1; 2, 0, -2; 1, 0, -1];
sobelY = sobelX';
DxImg = conv2(img,sobelX,'same');
DyImg = conv2(img,sobelY,'same');
% for each canny-edge-pixel:
for lin = 1:size(img,1) % <-> y
    for col = 1:size(img,2) % <-> x
        if canny_img(lin,col)
            % normalize direction
            normDir = [DxImg(lin,col); DyImg(lin,col)];
            normDir = normDir / norm(normDir,2);
            % inner product
            innerP = normDir' * removeDir;
            % remove edge?
            if abs(innerP) < cos(45/180*pi) % 45° threshold
                canny_img(lin,col) = 0;
            end
        end
    end
end

You can optimize it a lot due to your requirements.

相关问答

更多

检测边界/边缘 - MATLAB(Detecting boundaries/edges - MATLAB)

我不认为它更简洁,但你可以使用min和max: % Take the minimum between edges and 1000 edges = min(edges, 1000) % Take the maximum between edges and 1 edges = max(edges, 1) I don't think it is really more concise, but you can use min and max: % Take the minimum between e...

Matlab操纵边缘(Matlab manipulate edges)

这取决于允许的成本密集程度。 一个简单的方法是: (1)使用Sobel-Filters对图像进行卷积(给出Dx,Dy)。 对于每个canny-edge-pixel: (2)标准化(Dx,Dy),st在您拥有边缘方向的每个像素中。 (3)用你想要移除的方向计算内积(在你的情况下为(0,1))。 (4)如果内积的绝对值小于某个阈值,则移除像素。 例: img = ...; canny_img = ...; removeDir = [0;1]; % convolute with sobel masks ...

使用线条边缘进行Matlab图像分割(Matlab image segmentation by using line edges)

这些是边缘工件。 Canny在内部使用渐变,并且不清楚如何在图像边界处计算渐变(它们在matlab的edge内也是模糊的)。 只需裁剪BW图像。 编辑: edge高斯模糊的sigma默认值为1.41像素。 因此,如果您裁剪大约两倍和另外2个像素来计算用于计算每个边缘的渐变(总共5个像素)的sobel内核(我的意思是图像的边缘,而不是检测到的边缘),您将摆脱边缘文物。 喜欢这个 BW_cropped = BW(5:end-5,5:end-5) 如果图像处理涉及查找图像中某些位置的位置,则将这5个像...

在图像matlab中定义物体边缘(Defining object edges in images matlab)

在MATLAB中类似的功能将是边界 a similar function in matlab would be bwboundaries

matlab:找到图片中对象的外边缘(matlab: find outer edges of objects in a picture)

要处理与图像边缘相交的轮廓,可以使用bwconncomp将背景与bwconncomp的轮廓分开。 然后,您可以仅通过bwperim获取外围,而不是edge ,但这只是一种变化。 I = imread('asEW3.jpg'); t1=graythresh(I); k1=im2bw(I,t1); k1=~k1; se = strel('disk',1); k0=imfill(~k1,'holes'); % new cc = bwconncomp(k0); ...

Matlab - 直方图边缘和截断(Matlab - Histogram edges and cut off)

编辑3和4 :由于您使用的是没有histogram Matlab R2013b,请使用hist的bin-number组合语法来绘制: [n, centers] = hist(data, 15) 请注意,这会返回中心 ,而不是区域的边缘 。 对于箭头,如果R2013b支持,则可以使用annotation 。 或者(有点hackish): line([0.6 0.6], [1750 1250]) plot(0.6, 1250, 'Marker, 'v') text(0.6, 1750, '\lamb...

Matlab:canny边缘检测器(Matlab: canny edge detector)

要在Matlab中找到Canny边缘检测器的实现,您只需打开文件( edit edge ),因为该函数不是内置的。 这样,您可以检查Matlab版本中使用的过滤和渐变方案。 To find the implementation of the Canny edge detector in Matlab, you can simply open the file (edit edge), since the function isn't built-in. This way, you can chec...

matlab:去除小边缘并简化组织学图像(matlab: remove small edges and simplify an histology image)

由于边界模糊,红色和绿色强度之间的微小差异,这是一项非常具有挑战性的工作。 如果你想非常精确地实现分割并满足一些医疗要求,Shai的k-means 加图切割可能是极少数选项之一( EM算法可能是另一种选择)。 如果您有一个包含许多相似图像的大型数据库,则某些机器学习方法可能有所帮助。 否则,我只是编写了一个非常简单的代码来粗略地为您提取内部红色区域。 由于还包括一些绿色区域,因此边界不准确。 I1=I; I=rgb2hsv(I); I=I(:,:,1); % the channel with re...

MatLab - 有许多边缘矢量的histc(MatLab - histc with many edges vector)

如果将数组转换为单元数组,则可以尝试 a = {1 ; 7 ; 13}; edges = {[ 1, 3, 6 ];[ 1, 4, 15] ; [1, 20, 30]}; [~, indexes] = cellfun(@histc, a, edges,'uniformoutput', false) 这导致了 indexes = [1] [2] [1] 〜编辑〜 要将矩阵转换为单元格数组,可以使用num2cell : a = num2cell(a); edges...

如何检测图像中的边缘,并创建一个蒙版(matlab)(How to detect edges in a image, and create a mask (matlab))

NKN绝对明白了,我唯一想指出的是你在y方向上使用sobel内核,如果你想在x轴上有效地执行边缘检测,内核是 Sobel_x = [1 0 -1; 2 0 -2; 1 0 -1]; 另请注意,还有许多其他更好的探测器,例如Canny探测器。 我强烈建议你看一下。 关于你的第二个问题,我不确定你在问什么,但看起来你想要一个标准化的梯度幅度矩阵。 为了得到它,你必须首先(惊喜!)计算梯度矩阵: G=sqrt(G_x.^2 + G_y.^2); 在获得G_x和G_y的情况下,在您的情况下使用Sobe...

相关文章

更多

《MATLAB及应用》扫描版 [PDF]

中文名: MATLAB及应用 作者: 胡鹤飞 图书分类: 软件 资源格式: PDF ...

《MATLAB智能算法30个案例分析》扫描版[PDF]

中文名: MATLAB智能算法30个案例分析 作者: 史峰 王辉 郁磊 胡斐 ...

《模式识别与智能计算:MATLAB技术实现(第2版)》扫描版[PDF]

中文名: 模式识别与智能计算:MATLAB技术实现(第2版) 作者: 杨淑莹 图书分类: ...

《数字图像处理与机器视觉:Visual C++与Matlab实现》扫描版[PDF]

中文名: 数字图像处理与机器视觉:Visual C++与Matlab实现 作者: 张铮 图 ...

经典的机器学习方面源代码库(非常全,数据挖掘,计算机视觉,模式识别,信息检索相关领域都适用的了)

今天给大家介绍一下经典的开源机器学习软件: 编程语言:搞实验个人认为当然matlab最灵活了(但是正版 ...

机器学习之开源库大总结

机器学习之开源库大总结   研究数据挖掘和机器学习有一段时间了,对数据挖掘来说,商用软件有SAS、Cl ...

经典的机器学习方面源代码库(转载)

编 程语言:搞实验个人认为当然matlab最灵活了(但是正版很贵),但是更为前途的是python(nu ...

机器学习之开源库大总结

  研究数据挖掘和机器学习有一段时间了,对数据挖掘来说,商用软件有SAS、Clementine、Ora ...

最新问答

更多

Python / IPython奇怪的不可重现列表索引超出范围错误(Python/IPython strange non reproducible list index out of range error)

你得到IndexError的原因是你的输入文件显然不是完全用制表符分隔的。 这就是为什么当您尝试访问它时, splits[1]没有任何内容。 您的代码可以使用一些重构。 首先,你正在重复使用if -checks,这是不必要的。 这只是将cds0到7个字符,这可能不是你想要的。 我将以下内容放在一起,以演示如何重构您的代码,使其变得更加pythonic和干燥。 我无法保证它能够与您的数据集一起使用,但我希望它可以帮助您了解如何以不同的方式执行操作。 to_sort = [] # W

故事板从表格单元中延伸出来并显示其详细信息披露按钮(storyboard segue from a tablecell an its Detail Disclosure Button)

我不认为你可以链接一个特定的细节披露按钮瓦特/赛格。 我的故事板是非常程序化的B / C我使用了很多定制CGRect等。 所以我倾向于使用这样的东西: -(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath { [self performSegueWithIdentifier:@"ViewControllerIdentifer"

我们可以将Gherkin功能文件与testcomplete集成(Can we integrate Gherkin feature files with testcomplete)

TestComplete不支持Gherkin功能文件。 但是,TestComplete具有SDK,因此可以自己为此创建扩展。 TestComplete does not support Gherkin feature files. However, TestComplete has SDK so it is possible to create an extension for this by yourself.

TrustAllCertificatesCallback被忽略(TrustAllCertificatesCallback is ignored)

我没有做过这样的事情,但看看我认为可以看出错误的例子。 试试这个代码: static class Program { static void Main() { var tcpclient = new TcpClient("remote.example.com", 443); var tcpstream = tcpclient.GetStream(); var sslstream = new SslStream(tcpstream,

返回嵌套元素的索引(Return index of nested element)

您需要获取父li元素的索引。 否则,您将获得列表项内锚点的索引,该索引始终为零。 $(this.parentNode).index(); You need to get the index of the parent li element. Otherwise you are getting the index of the anchor inside the list item, which will always be zero. $(this.parentNode).index();

在数组中重新编号元素的有效方法(Efficient way of re-numbering elements in an array)

您需要多次迭代列表,我认为没有办法解决这个问题。 毕竟,在开始更改元素(第二遍)之前,首先必须确定不同元素的数量(第一遍)。 但是请注意,由于对index的重复调用而not in列表中具有O(n),因此可能具有最多O(n ^ 2)的不同元素的数量。 或者,您可以使用dict而不是value_map的list 。 字典比列表具有更快的查找速度,因此,复杂性应该确实在O(n)的数量级上。 您可以使用(1)字典理解来确定旧值到新值的映射,以及(2)用于创建更新子项的列表理解。 value_map =

Express app定义的`static`文件夹无法正常工作(Express app defined `static` folder not working properly)

选项1 你可以改变这一行: app.use( express.static(__dirname + '/puplic')); //my public folder. 至 app.use('/oneTime', express.static(__dirname + '/puplic')); //my public folder 选项2 我假设你在公共文件夹中有一个js文件夹,然后你需要更改你的HTML代码:

使用node.js和socket.io每秒广播一次(Using node.js and socket.io to broadcast every second)

对于计时器值,请在服务器端本身每秒更新本地计时器。 每当有任何用户进来时,给他这个值以及计时器的总值。 然后客户端将根据dandavis评论在本地启动自己的计时器,但在服务器端保留一些间隔,如15或10秒,服务器将广播当前计时器值,以便客户端相应地进行同步。 简而言之,服务器将每隔10(n:你决定)秒后广播,但它将在本地每秒更新定时器变量。 每当客户端进入时,它将获得总计时器值和当前计时器值。 广播当前出价的休息功能可以以正常方式完成。 For timer value, keep updatin

如何让XMLSerializer将命名空间添加到嵌套对象中的属性?(How do I get the XMLSerializer to add namespaces to attributes in nested objects?)

IXmlSerializable也许? 注意我还添加了(对A ): [XmlElement("A", Namespace = "http://www.example.com/namespace")] public TestSoapHeaderTypeValuePair A {...} 代码如下: public class TestSoapHeaderTypeValuePair : IXmlSerializable { private string _type; private