MatLab - 分割以分离图像中的触摸对象 [英] MatLab - Segmentation to separate touching objects in an image

查看:23
本文介绍了MatLab - 分割以分离图像中的触摸对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

首先我使用蓝色 NDVI 移除地面:

具有阈值的图像:

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

但是区域 15 有问题,因为该区域上的所有树都是连接的,它检测为一棵树.我尝试使用

我这样做是不是用错了方法?有没有更好的方法来分离树木?

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

如果有帮助,这里是梯度幅值图像:

解决方案

问这个问题已经有一段时间了.我希望现在给出答案还为时不晚.我看到在类似问题中使用分水岭分割的一般问题.有时对象是分开的,不会相互接触

I'm using the function regionprops to detect the number of trees on a image taked by drone.

First I removed the ground using Blue NDVI:

Image with threshold:

Then I used the function regionprops to detect the number of trees on image:

But there are a problem on region 15, because all trees on that region are connected and it detects as one tree. I tried to separate the trees on that region using Watershed Segmentation, but its not working:

Am I doing this the wrong way? Is there a better method to separate the trees?

If anyone can help me with this problem I will appreciate. Here is the region 15 without the ground:

If it helps, here is the Gradient Magnitude image:

解决方案

It has been some time since this question was asked. I hope it is not too late for an answer. I see a general problem of using watershed segmentation in similar questions. Sometimes the objects are apart, not touching each other like in this example . In such cases, only blurring the image is enough to use watershed segmentation. Sometimes the objects are located closely and touch each other, thus the boundaries of objects are not clear like in this example. In such cases, using distance transform-->blur-->watershed helps. In this question, the logical approach should be using distance transform. However, this time the boundaries are not clear due to shadows on and nearby the trees. In such cases, it is good to use any information that helps to separate the objects as in here or emphasise objects itself.

In this question, I suggest using colour information to emphasise tree pixels.
Here are the MATLAB codes and results.

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)

这篇关于MatLab - 分割以分离图像中的触摸对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆