检测 RGB 图像中几乎圆形的形状
信息处理
图像处理
图像分割
边缘检测
2022-02-04 05:13:53
1个回答
图像本身有点模糊。树木的整个边缘不可见。树存在的唯一线索似乎是阴影。所以我建议使用阴影信息和分水岭变换和局部阈值。我在这里做过类似的练习。结果不是那么完美,但它会给出一些想法。以下是步骤。1. 寻找阴影, 2. 向太阳方向扩展阴影 3. 创建阴影蒙版 4. 模糊图像 5. 分水岭变换 6. 分别对每个分水岭段设置阈值 7. 用霍夫变换拟合圆
im=imread('P0Yvl.png');
imOrig=im;
% Grayscale
im=rgb2gray(im);
% Shadows
shadow=im<60;
[xs,ys]=find(shadow);
% Grow shadow towards sun direction
% Create structural element for dilation
str_element_initial=flip(eye(25));
str_element_initial(:,1:12)=0;
shadow2=zeros(size(str_element_initial));
for i=1:7
shadow2 = shadow2 | imresize(imrotate(str_element_initial,40-i*10),size(str_element_initial))>.1;
end
mask_shadow=imdilate(shadow,shadow2);
mask_shadow=mask_shadow-shadow;
% Plot shadow mask and initial shadow locations
figure,imagesc(mask_shadow);axis image;
hold on, plot(ys,xs,'r.')
% Blur image
im2=imfilter(im,fspecial('gaussian',[21 21],3));
% Watershed transform
L = watershed(max(im2(:))-im2);
[xw,yw]=find(L==0);
figure,imagesc(imOrig),axis image
hold on, plot(yw,xw,'r.','MarkerSize',1)
% Threshold each segment individually
tmp=zeros(size(im));
for i=1:max(L(:))
mask=L==i;
ind=find(mask);
thr =multithresh(im(ind),1);
tmp(ind)=im(ind)>thr*.8;
end
% Remove detections that don't have shadow
trees=tmp & mask_shadow;
trees=bwareaopen(trees,10);
% Find circles with Hough transform
[centers, radii, metric] = imfindcircles(trees,[5 25]);
% Result
figure,imagesc(imOrig),axis image
viscircles(centers, radii,'EnhanceVisibility',0,'LineStyle','-','LineWidth',1);
其它你可能感兴趣的问题



