2
$\begingroup$

enter image description here I want to extract circular trees from this rgb image, I've tried circular hough and segmentation techniques but in vain. Any help?

$\endgroup$

1 Answer 1

2
$\begingroup$

The image itself is somehow blurred a little. Whole edges of trees are not visible. The only clue of tree existence seems like shadows. So I suggest using shadow information and watershed transform and local thresholding. I have done similar exercise in here. The result is not that perfect but it will give some idea. Here are the steps. 1. Find shadows, 2. Expand shadows towards sun direction 3. Create shadow mask 4. Blur the image 5. Watershed transform 6. Threshold each watershed segment individually 7. Fit circle with Hough transform

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.')

enter image description here

% 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)

enter image description here

% 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);

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.