gpt4 book ai didi

MatLab - 分割以分离图像中的触摸对象

转载 作者:太空宇宙 更新时间:2023-11-03 20:13:46 24 4
gpt4 key购买 nike

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

首先,我使用 Blue NDVI 去除了地面: Image BNDVI

带阈值的图像: Image with Threshold

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

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

Watershed segmentation

我做错了吗?有没有更好的方法来分离树?

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

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

最佳答案

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

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

im=imread('/image/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)

enter image description here

enter image description here

enter image description here

关于MatLab - 分割以分离图像中的触摸对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42374463/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com