使用MATLAB从图像中删除对象

时间:2014-09-18 17:43:50

标签: matlab image-processing

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

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

原始图片:

original image

应该删除的红色圆圈区域:

red circled area should be removed

1 个答案:

答案 0 :(得分:3)

尝试使用Extent的{​​{1}}属性。以下是一些初步结果:

regionprops

enter image description here