【问题标题】:Removing Objects from an image using MATLAB使用 MATLAB 从图像中删除对象
【发布时间】:2014-10-29 09:33:54
【问题描述】:

我试图根据颜色强度从地图中提取道路,但我无法清楚地划分道路,因为某些建筑物的强度与某些道路相同。现在我正试图移除那些建筑​​物。为此,我尝试在对象中使用“最大内接圆”的概念,因为建筑物中的内接圆将大于道路。但是,到目前为止,我的尝试无法做到这一点。这是我写的代码。

clc
clear all
x=imread('http://i.imgur.com/R80JmEH.jpg?1');
x1=rgb2gray(x);
imshow(x1)
x1(x1<240)=0;
T=graythresh(x1);
y=im2bw(x1,T);
figure;imshow(y)
y1= imfill(y,'holes');
figure; imshow(y1)
BW2 = bwareaopen(y1,10);
figure;imshow(BW2);
s = regionprops(BW2, x1, {'Centroid','WeightedCentroid'});
figure;imshow(BW2)
title('Weighted (red) and Unweighted (blue) Centroid Locations');
hold on
numObj = numel(s);
for k = 1 : numObj
plot(s(k).WeightedCentroid(1), s(k).WeightedCentroid(2), 'r*');
plot(s(k).Centroid(1), s(k).Centroid(2), 'bo');
end
hold off

原图:

应删除的红色圆圈区域:

【问题讨论】:

  • 为什么要删除部分问题?您应该保留它原来的样子,以便人们将来可以参考它。

标签: matlab image-processing


【解决方案1】:

尝试使用regionpropsExtent 属性。以下是一些初步结果:

clc
clear all
img=imread('map.JPG');
img=rgb2gray(img);
img(img<200) = 255;
figure(1), imshow(img);
img(img<240) = 0; 
img=im2bw(img);
figure(2),imshow(img);

img = imfill(img,'holes');
img = imerode(img,strel('disk',1));
figure(3),imshow(img)

cc = bwconncomp(img);
l = labelmatrix(cc);
rp = regionprops(cc,'Extent');
idx = ([rp.Extent] < .2);
img_filt = ismember(l,find(idx));
figure(4), imshow(img_filt,[]);

【讨论】:

    猜你喜欢
    • 2012-01-28
    • 1970-01-01
    • 2013-12-04
    • 1970-01-01
    • 2016-08-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-09
    相关资源
    最近更新 更多