MatLab - 用于分隔图像中的触摸对象的分割

Ped*_*ues 3 matlab function image-processing image-segmentation watershed

我正在使用函数regionprops来检测无人机拍摄的图像上的树木数量. 原始图像

首先,我使用Blue NDVI移除了地面: 图片BNDVI

带阈值的图片: 具有阈值的图像

然后我使用函数regionprops来检测图像上的树数: Regionprops

但是区域15存在问题,因为该区域上的所有树都是连接的,并且它检测为一棵树.我尝试使用Watershed Segmentation将该区域的树分开,但它不起作用:

分水岭分割

我这样做是错误的吗?是否有更好的方法来分离树木?

如果有人能帮我解决这个问题,我将不胜感激.这是没有地面的区域15: 15区

如果有帮助,这里是Gradient Magnitude图像: 在此输入图像描述

Ozc*_*can 7

问这个问题已经有一段时间了.我希望答案还为时不晚.我看到在类似问题中使用分水岭分割的一般问题.有时物体是分开的,不像在这个例子中那样彼此接触.在这种情况下,仅模糊图像就足以使用分水岭分割.有时物体彼此靠近并相互接触,因此物体的边界不像这个例子那样清晰.在这种情况下,使用距离变换 - >模糊 - >分水岭有帮助.在这个问题中,逻辑方法应该是使用距离变换.然而,这次由于树木上和附近的阴影,边界不清晰.在这种情况下,最好使用任何有助于在此处分离对象的信息或强调对象本身.

在这个问题中,我建议使用颜色信息来强调树像素.
这是MATLAB代码和结果.

im=imread('https://i.stack.imgur.com/aBHUL.jpg');
im=im(58:500,86:585,:);
imOrig=im;

%% Emphasize trees

im=double(im);
r=im(:,:,1);
g=im(:,:,2);
b=im(:,:,3);

tmp=((g-r)./(r-b));

figure
subplot(121);imagesc(tmp),axis image;colorbar
subplot(122);imagesc(tmp>0),axis image;colorbar

%% Transforms

% Distance transform
im_dist=bwdist(tmp<0);

% Blur
sigma=10;
kernel = fspecial('gaussian',4*sigma+1,sigma);
im_blured=imfilter(im_dist,kernel,'symmetric');

figure
subplot(121);imagesc(im_dist),axis image;colorbar
subplot(122);imagesc(im_blured),axis image;colorbar

% Watershed
L = watershed(max(im_blured(:))-im_blured);
[x,y]=find(L==0);

figure
subplot(121);
imagesc(imOrig),axis image
hold on, plot(y,x,'r.','MarkerSize',3)

%% Local thresholding 

trees=zeros(size(im_dist));
centers= [];
for i=1:max(L(:))    
    ind=find(L==i & im_blured>1);
    mask=L==i;

    [thr,metric] =multithresh(g(ind),1);
    trees(ind)=g(ind)>thr*1;

    trees_individual=trees*0;
    trees_individual(ind)=g(ind)>thr*1;

    s=regionprops(trees_individual,'Centroid');
    centers=[centers; cat(1,[],s.Centroid)];
end

subplot(122);
imagesc(trees),axis image
hold on, plot(y,x,'r.','MarkerSize',3)

subplot(121);
hold on, plot(centers(:,1),centers(:,2),'k^','MarkerFaceColor','r','MarkerSize',8)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

在此输入图像描述

在此输入图像描述