通过组合其各个部分获得整线 [英] Getting whole line by combining its parts

查看:119
本文介绍了通过组合其各个部分获得整线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张图片,我的目标是获得用红线显示的整条线。我正在使用matlab,我不想使用 IM2 = imdilate(IM,SE)函数。

I have an image and my aim is to get whole line which is shown with red line. I am working with matlab and I don't want to use IM2 = imdilate(IM,SE) function.

是否有任何功能或方法可以做到这一点?

Is there any function or method to do that?

图片:

注意:抱歉红线不好。我用油漆画了它。

Note: Sorry for bad red line. I drew it with paint.

编辑:

原始图片如下:

推荐答案

以下是我在中间步骤中使用 imdilate 后的所有内容 -

Here's what I have after using imdilate at an intermediate step -

%// Read in image and convert to a binary one
im = imread('Line.jpg');
bw = im2bw(im);

%// There seems to be a thin white boundary across the image, make it false(black)
bw1 = false(size(bw));
bw1(5:end-5,5:end-5) = bw(5:end-5,5:end-5);

bw1(biggest_blob(bw1)) = 0; %// remove biggest blob (bottom left corner one)

SE = strel('disk', 11, 8); %// structuring element for dilation
bw2 = imdilate(bw1,SE); %// dilate the image
bw3 = bwmorph(bw2,'thin',Inf); %// thin it
out = biggest_blob(bw3); %// out of many thinned lines, select the biggest one

请记住删除后面的动机代码开头的最大blob是,如果没有被删除,我们就会得到最大的斑点附着在我们试图连接/组合的岛屿斑点上,因此会弄乱所需的输出。

Please remember that the motive behind removing the biggest blob at the start of the codes is that without that being removed, we would have gotten the biggest blob being attached to the island blobs that we were trying to connect/combine and thus would have messed up the desired output.

相关功能(取自 选择最大的对象图像 ) -

Associated function (taken from Select largest object in an image) -

function out = biggest_blob(BW)

%// Find and labels blobs in the binary image BW
[L, num] = bwlabel(BW, 8); 

%// Count of pixels in each blob, basically this should give the area of each blob
counts = sum(bsxfun(@eq,L(:),1:num)); 

%// Get the label(ind) cooresponding to blob with the maximum area 
%// which would be the biggest blob
[~,ind] = max(counts);

%// Get only the logical mask of the biggest blob by comparing all labels 
%// to the label(ind) of the biggest blob
out = (L==ind);

return;

结果 -

这篇关于通过组合其各个部分获得整线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆