edit -door detection
조회 수: 8 (최근 30일)
이전 댓글 표시
I have a code for detecting the door,but id detect only some images ,it detects only doors brown in colour,if it is other colours,it os not detecting,please help
clc
clear all
[filename, pathname] = ...
uigetfile({'*.jpg';'*.bmp';'*.png';'*.*'},'File Selector');
i=imread([pathname,filename]);
I=i;
if length(size(i)) == 3
im = double(i(:,:,2));
else
im = double(i);
end
cs = fast_corner_detect_9(im, 60)
size(im)
image(im/6)
axis image
colormap(gray)
hold on
axis off
plot(cs(:,1), cs(:,2), 'r.'),title('Corner Detection')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%GUASSIAN SMOOTHING %%%%%%%%%%%%%%%%%%%%%%%%%%%%
G = fspecial('gaussian',[5 5],2);
Ig = imfilter(im,G,'same');
figure('name','Guassian Smoothing','numbertitle','off'),imshow(uint8(Ig))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%RESIZING AN IMAGE%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
I1=imresize(Ig,.5)
figure('name','Reduced Resolution Image','numbertitle','off'),imshow(uint8(I1))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%EDGE DETECTION%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
edge_detect=edge(im,'sobel');
figure('name','Edge detected Image','numbertitle','off'),imshow(edge_detect);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%DETCTION%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
cform = makecform('srgb2lab');
J = applycform(I,cform);
%figure;imshow(J);
K=J(:,:,2);
%figure;imshow(K);
L=graythresh(J(:,:,2));
BW1=im2bw(J(:,:,2),L);
%figure;imshow(BW1);
M=graythresh(J(:,:,3));
%figure;imshow(J(:,:,3));
BW2=im2bw(J(:,:,3),M);
%figure;imshow(BW2);
O=BW1.*BW2;
% Bounding box
P=bwlabel(O,8);
BB=regionprops(P,'Boundingbox');
BB1=struct2cell(BB);
BB2=cell2mat(BB1);
[s1 s2]=size(BB2);
mx=0;
for k=3:4:s2-1
p=BB2(1,k)*BB2(1,k+1);
if p>mx & (BB2(1,k)/BB2(1,k+1))<1.8
mx=p;
j=k;
end
end
figure,imshow(I);
hold on;
rectangle('Position',[BB2(1,j-2),BB2(1,j-1),BB2(1,j),BB2(1,j+1)],'EdgeColor','g' )
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%END OF CODING%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
댓글 수: 7
Pria Bertopeng
2016년 12월 8일
Can someone explain how this code works? especially on detection section. Thx
Walter Roberson
2016년 12월 8일
It converts to L*a*b color space, and does a thresholding on the L (brightness) channel to produce a binary image in which 0 corresponds to darker spots and 1 corresponds to brighter spots.
You could also do much the same with rgb2gray, or with rgb2hsv and taking the v channel as the brightness.
답변 (3개)
Winnie
2012년 6월 24일
hi...Did you write this code by yourself? Because my friend has the exact same code as you!
댓글 수: 0
Image Analyst
2012년 6월 24일
I have no idea how challenging this is. Perhaps you have images with doors that have a known and contrasting color from the rest of the items in the image. If so, then you could use the color detection methods in my File Exchange and then check on what their area is (large = closed door, small = open door). http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862 This would be one of the easier cases.
If you're hoping for some code that will tell you "open" or "closed" for every possible door that a search of "door" images on Google might bring up, then that's way beyond your capabilities now. Some people in the "CBIR" community are working on that but it's very very challenging. For example, show me, based on only the image pixels and no metadata, images that have pictures of babies in them. Or dogs, or doors, or cars, or whatever. Look up CBIR in a web search.
댓글 수: 3
Image Analyst
2012년 6월 24일
Not to mention things like gates. Is a half height solid wooden gate a door? How about a full height, wrought iron, non-solid gate? Is it supposed to find the door on a car, and the door to the batteries on my electronic device, as well as doors to buildings? What if the door is glass, like in many modern buildings? I wouldn't tackle this problem unless it was very very constrained to certain types of doors.
Walter Roberson
2012년 6월 24일
Yes for the solid wooden gates: consider the traditional "Old West" saloon doors.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!