Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing Objects from an image using MATLAB

I was trying to do road extraction from a map based on color intensity, but I couldn't segment the roads clearly, as some buildings have same intensity as some of the roads. Now I'm trying to remove those buildings. To do this, I'm trying to use the idea of "maximum inscribed circle" in an object as the inscribed circle in a building will be larger than a road. However, I am not able to do this with my attempts so far. Here is the code I have written.

clc
clear all
x=imread('https://i.sstatic.net/Fa7Pk.jpg');
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:

original image

Red circled areas that should be removed:

red circled area should be removed


1 Answers

Try using the Extent property of regionprops. Here are some preliminary results:

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,[]);

enter image description here

like image 152
JustinBlaber Avatar answered Jul 04 '26 22:07

JustinBlaber