Mat*_*tte 3 matlab image image-processing
我在立方体的图像上执行了一些操作,我获得了立方体边缘的二进制图像,这些图像在某些地方断开连接.我获得的图像如下所示:
我想加入双方使其成为一个封闭的人物.我尝试了以下方法:
BW = im2bw(image,0.5);
BW = imdilate(BW,strel('square',5));
figure,imshow(BW);
Run Code Online (Sandbox Code Playgroud)
但这只会使图像变粗.它没有连接边缘.我也尝试了bwmorph()和其他各种功能,但它不起作用.任何人都可以建议任何功能或步骤来连接边缘?谢谢
这可能是一种方法 -
%// Read in the input image
img = im2bw(imread('http://i.imgur.com/Bl7zhcn.jpg'));
%// There seems to be white border, which seems to be non-intended and
%// therefore could be removed
img = img(5:end-4,5:end-4);
%// Thin input binary image, find the endpoints in it and connect them
im1 = bwmorph(img,'thin',Inf);
[x,y] = find(bwmorph(im1,'endpoints'));
for iter = 1:numel(x)-1
two_pts = [y(iter) x(iter) y(iter+1) x(iter+1)];
shapeInserter = vision.ShapeInserter('Shape', 'Lines', 'BorderColor', 'White');
rectangle = int32(two_pts);
im1 = step(shapeInserter, im1, rectangle);
end
figure,imshow(im1),title('Thinned endpoints connected image')
%// Dilate the output image a bit
se = strel('diamond', 1);
im2 = imdilate(im1,se);
figure,imshow(im2),title('Dilated Thinned endpoints connected image')
%// Get a convex shaped blob from the endpoints connected and dilate image
im3 = bwconvhull(im2,'objects',4);
figure,imshow(im3),title('Convex blob corresponding to previous output')
%// Detect the boundary of the convex shaped blob and
%// "attach" to the input image to get the final output
im4 = bwboundaries(im3);
idx = im4{:};
im5 = false(size(im3));
im5(sub2ind(size(im5),idx(:,1),idx(:,2))) = 1;
img_out = img;
img_out(im5==1 & img==0)=1;
figure,imshow(img_out),title('Final output')
Run Code Online (Sandbox Code Playgroud)
调试图像 -
归档时间: |
|
查看次数: |
2868 次 |
最近记录: |