经过一些预处理、边缘检测和细化后,我得到了以下图像,图像类型为 double
为了去除区域内的孤立像素,我使用膨胀作为
se90 = strel('line', 2, 90);
se0 = strel('line', 2, 0);
BWsdil = imdilate(Edge, [se90 se0]);
垂直扩张后水平扩张
实际上我想分割在矩形(类椭圆结构)内标记的对象。
值得注意的是,如果我增加阈值,黑色矩形在膨胀过程中会破裂,我将丢失底部矩形中的片段。如果我继续这个结果,我最终会出错,甚至基本的分割算法在没有预处理的情况下也无法工作。请帮忙
如果我对梯度图像进行连接分量分析,您能否建议任何其他技术来改进掩码。我将得到椭圆的边框而不是椭圆,如图所示
我尝试了霍夫变换,但我得到了一些不好的结果
close all;clear all
I=imread('Sub1.png');
load edge
rotI = imrotate(I,33,'crop');
[H,T,R] = hough(Edge);
imshow(H,[],'XData',T,'YData',R,...
'InitialMagnification','fit');
xlabel('\theta'), ylabel('\rho');
axis on, axis normal, hold on;
P = houghpeaks(H,25,'threshold',ceil(0.3*max(H(:))));
x = T(P(:,2)); y = R(P(:,1));
plot(x,y,'s','color','white');
lines = houghlines(Edge,T,R,P,'FillGap',5,'MinLength',7);
figure, imshow(rotI), hold on
max_len = 0;
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');
% Plot beginnings and ends of lines
plot(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','yellow');
plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','red');
% Determine the endpoints of the longest line segment
len = norm(lines(k).point1 - lines(k).point2);
if ( len > max_len)
max_len = len;
xy_long = xy;
end
end