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?
满意答案
这取决于允许的成本密集程度。 一个简单的方法是:
(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)
Matlab操纵边缘(Matlab manipulate edges)
使用线条边缘进行Matlab图像分割(Matlab image segmentation by using line edges)
在图像matlab中定义物体边缘(Defining object edges in images matlab)
matlab:找到图片中对象的外边缘(matlab: find outer edges of objects in a picture)
Matlab - 直方图边缘和截断(Matlab - Histogram edges and cut off)
Matlab:canny边缘检测器(Matlab: canny edge detector)
matlab:去除小边缘并简化组织学图像(matlab: remove small edges and simplify an histology image)
MatLab - 有许多边缘矢量的histc(MatLab - histc with many edges vector)
如何检测图像中的边缘,并创建一个蒙版(matlab)(How to detect edges in a image, and create a mask (matlab))
相关文章
更多《MATLAB及应用》扫描版 [PDF]
《MATLAB智能算法30个案例分析》扫描版[PDF]
《模式识别与智能计算:MATLAB技术实现(第2版)》扫描版[PDF]
《数字图像处理与机器视觉:Visual C++与Matlab实现》扫描版[PDF]
经典的机器学习方面源代码库(非常全,数据挖掘,计算机视觉,模式识别,信息检索相关领域都适用的了)
经典的机器学习方面源代码库(非常全,数据挖掘,计算机视觉,模式识别,信息检索相关领域都适用的了)
机器学习之开源库大总结
经典的机器学习方面源代码库(转载)
机器学习之开源库大总结
经典的机器学习方面源代码库(非常全数据挖掘,计算机视觉,模式识别,信息检索相关领域都适用的了)
最新问答
更多Python / IPython奇怪的不可重现列表索引超出范围错误(Python/IPython strange non reproducible list index out of range error)
故事板从表格单元中延伸出来并显示其详细信息披露按钮(storyboard segue from a tablecell an its Detail Disclosure Button)
我们可以将Gherkin功能文件与testcomplete集成(Can we integrate Gherkin feature files with testcomplete)
TrustAllCertificatesCallback被忽略(TrustAllCertificatesCallback is ignored)
返回嵌套元素的索引(Return index of nested element)
在数组中重新编号元素的有效方法(Efficient way of re-numbering elements in an array)
Express app定义的`static`文件夹无法正常工作(Express app defined `static` folder not working properly)
Javascript错误:未捕获TypeError:无法读取null的属性'value'[duplicate](Javascript error: Uncaught TypeError: Cannot read property 'value' of null [duplicate])
使用node.js和socket.io每秒广播一次(Using node.js and socket.io to broadcast every second)
如何让XMLSerializer将命名空间添加到嵌套对象中的属性?(How do I get the XMLSerializer to add namespaces to attributes in nested objects?)
Copyright ©2023 656463.com All Rights Reserved.滇ICP备2022006988号-50
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们,本站将尽快处理。谢谢合作!