gpt4 book ai didi

matlab - 通过组合其部分获得整条线

转载 作者:太空宇宙 更新时间:2023-11-03 19:59:45 24 4
gpt4 key购买 nike

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

有什么功能或方法可以做到这一点吗?

图像: enter image description here

注意:抱歉,红线不好。我用颜料画的。

编辑:

原图如下:

最佳答案

这是我在中间步骤使用 imdilate 后得到的结果 -

%// 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 背后的动机是,如果不删除它,我们就会将最大的 Blob 附加到我们试图连接/组合的岛 Blob 上,从而弄乱了所需的输出。

关联函数(取自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;

结果-

enter image description here

关于matlab - 通过组合其部分获得整条线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26818240/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com