help with object recognition matlab

1 visualización (últimos 30 días)
Omar
Omar el 22 de Jul. de 2011
*hello everyone I have this code working for object recognition with one image: http://i32.photobucket.com/albums/d26/blinketo/recon7.jpg *
RGB = imread('recon7.jpg');
figure, imshow(RGB);
%%Step 2: Threshold the Image
% Convert the image to black and white in order to prepare for
% boundary tracing using |bwboundaries|.
I = rgb2gray(RGB);
%I = wiener2(I1,[5 5]); %function!
threshold = graythresh(I);
bw = im2bw(I,threshold);
figure, imshow(bw)
%%Step 3: Remove the Noise
% Using morphology functions, remove pixels which do not belong to the
% objects of interest.
BWnobord = imclearborder(bw);
%BWnobord=bw;
% remove all object containing fewer than 1000 pixels
BWnobord = bwareaopen(BWnobord,5000);
% fill a gap in the pen's cap
se = strel('disk',20);
BWnobord = imclose(BWnobord,se);
% fill any holes, so that regionprops can be used to estimate
% the area enclosed by each of the boundaries
BWnobord = imfill(BWnobord,'holes');
figure, imshow(BWnobord)
%%Step 4: Find the Boundaries
% Concentrate only on the exterior boundaries. Option 'noholes' will
% accelerate the processing by preventing |bwboundaries| from searching
% for inner contours.
[B,L] = bwboundaries(BWnobord,'noholes');
% Display the label matrix and draw each boundary
figure, imshow(label2rgb(L, @jet, [.5 .5 .5]))
hold on
for k = 1:length(B)
boundary = B{k};
plot(boundary(:,2), boundary(:,1), 'w', 'LineWidth', 2)
end
stats = regionprops(L,'Area','Centroid');
%threshold = 0.94;
% loop over the boundaries
% obtain (X,Y) boundary coordinates corresponding to label 'k'
boundary = B{1};
% compute a simple estimate of the object's perimeter
delta_sq = diff(boundary).^2;
perimeter = sum(sqrt(sum(delta_sq,2)));
% obtain the area calculation corresponding to label 'k'
area = stats(1).Area;
% compute the roundness metric
%metric = 4*pi*area/perimeter^2;
metric= perimeter;
% display the results
metric_string = sprintf('%2.2f',metric);
% mark objects above the threshold with a black circle
if metric > threshold
centroid = stats(1).Centroid;
plot(centroid(1),centroid(2),'ko');
end
text(boundary(1,2)-35,boundary(1,1)+13,metric_string,'Color','y',...
'FontSize',14,'FontWeight','bold');
title(['Areas or Perimeters of the objects']);
*
but the code is not detecting objects in the following image:
any suggestions to improve the code so I can detect the object in the second image? thank you in advance.*

Respuestas (2)

Diamela Duverge
Diamela Duverge el 2 de Ag. de 2011
it doesnt work :(

Image Analyst
Image Analyst el 2 de Ag. de 2011
You'll have to try another method that will handle more situations. It could be color classification, or it could be something else.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by