在图像上圈选周边检测(Circle packing periphery detection on an image)

编程入门 行业动态 更新时间:2024-10-28 12:27:00
图像上圈选周边检测(Circle packing periphery detection on an image)

我有一个图像如下

圈包装

我创建了一个matlab代码,可以检测圆周上的像素并创建一个整型掩码,以便我可以将它导入到C ++代码中。 这是主要算法的一小部分。 (我使用imread并将图像存储在NXN阵列中

for i=1:nx for j=1:ny if (wholeGeom(j,i) == 255) B(j,i) = 1; elseif ((wholeGeom(j,i) == 0)&& ... ((i==1||i==nx) && j>1 && j<nx)&& ... (wholeGeom(j+1,i)==255 || ... wholeGeom(j-1,i)==255) ) B(j,i) = 2; elseif ((wholeGeom(j,i) == 0)&& ... ((j==1||j==nx) && i>1 && i<nx)&& ... (wholeGeom(j,i+1)==255 || ... wholeGeom(j,i-1)==255) ) B(j,i) = 2; elseif ((wholeGeom(j,i) == 0)&& ... (i>1 && j>1 && i<nx && j<nx)&& ... (wholeGeom(j+1,i)==255 || ... wholeGeom(j-1,i)==255 ||... wholeGeom(j,i+1)==255 ||... wholeGeom(j,i-1)==255) ) else B(j,i) = 0;

这对我很好。 我的输出如下

BounceBack节点

我只是想知道是否有更有效的方法来做到这一点,尤其是在matlab上....任何建议,将不胜感激

I have an image as following

Circle packing

I have created a matlab code that would detect the pixels on the circumference and create a integer mask so I can import it in a C++ code. Here is a snippet of main algo. (I use imread and store the image in a N X N array

for i=1:nx for j=1:ny if (wholeGeom(j,i) == 255) B(j,i) = 1; elseif ((wholeGeom(j,i) == 0)&& ... ((i==1||i==nx) && j>1 && j<nx)&& ... (wholeGeom(j+1,i)==255 || ... wholeGeom(j-1,i)==255) ) B(j,i) = 2; elseif ((wholeGeom(j,i) == 0)&& ... ((j==1||j==nx) && i>1 && i<nx)&& ... (wholeGeom(j,i+1)==255 || ... wholeGeom(j,i-1)==255) ) B(j,i) = 2; elseif ((wholeGeom(j,i) == 0)&& ... (i>1 && j>1 && i<nx && j<nx)&& ... (wholeGeom(j+1,i)==255 || ... wholeGeom(j-1,i)==255 ||... wholeGeom(j,i+1)==255 ||... wholeGeom(j,i-1)==255) ) else B(j,i) = 0;

This works well for me. My output is as follows

BounceBack Nodes

I was just wondering if there is a more efficient way to do this, especially on matlab.... Any recommendations would be appreciated

最满意答案

事实上,形态操作是你的朋友。 形态学操作是处理二进制图像的非常快速的工具。 您可以使用imdilate来“扩大”图像,即“加厚”图像中的所有对象。

% Load image wholeGeom = rgb2gray(imread('https://i.stack.imgur.com/Jt4TC.png')); % Threshold to make image binary wholeGeom = wholeGeom > 128; % Dilate image, i.e. add 1 pixel to each side of an object borders = imdilate(wholeGeom, [0,1,0;1,1,1;0,1,0]); % Set borders to 2 and everything inside object to 1 result = 2*borders - wholeGeom;

结果(放大以使边框更清晰可见):

结果

Indeed, morphological operations are your friend. Morphological operations are a very fast tool to work on binary images. You can use imdilate to "dilate" an image, i.e. "thicken" all objects in the image.

% Load image wholeGeom = rgb2gray(imread('https://i.stack.imgur.com/Jt4TC.png')); % Threshold to make image binary wholeGeom = wholeGeom > 128; % Dilate image, i.e. add 1 pixel to each side of an object borders = imdilate(wholeGeom, [0,1,0;1,1,1;0,1,0]); % Set borders to 2 and everything inside object to 1 result = 2*borders - wholeGeom;

Result (zoomed in to make border more visible):

result

更多推荐

本文发布于:2023-07-04 06:33:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1019766.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图像   Circle   上圈选   packing   detection

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!