Removing Objects from an Image Using MATLAB
I tried to extract a road from a map based on color intensity, but I could not segment the roads clearly as some buildings have the same intensity as some of the roads. Now I am trying to remove these buildings. To do this, I'm trying to use the idea of โโa "maximum inscribed circle" in the object, since the inscribed circle in the building will be larger than the road. However, I cannot do this with my attempts yet. Here is the code I wrote.
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 areas to be removed:
+3
user4047695
source
to share
1 answer
Try using the property Extent
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,[]);
+3
source to share