i need some help

1 vue (au cours des 30 derniers jours)
Syazwan
Syazwan le 27 Mai 2012
this is the coding that i have modified..
Gray = rgb2gray(handles.RGB);
axes(handles.axes2);
imshow(Gray);
guidata(hObject, handles);
Binary = handles.RGB;
normalizedThresholdValue = 0.5; % In range 0 to 1.
thresholdValue = normalizedThresholdValue * max(max(Binary)); % Gray Levels.
BW = im2bw(Binary, normalizedThresholdValue); % One way to threshold to binary
handles.BW = BW;
axes(handles.axes2);
imshow(BW);
guidata(hObject, handles);
fill = handles.BW;
handles.fill = imfill(fill, 'holes');
axes(handles.axes2);
imshow(handles.BW);
guidata(hObject, handles);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
label = handles.fill;
handles.labeledImage = bwlabel(label, 8);
color = handles.labeledImage
coloredLabels = label2rgb (color, 'jet', 'r', 'noshuffle'); % pseudo random color labels
axes(handles.axes3);
imshow(handles.labeledImage),imshow(coloredLabels);
guidata(hObject, handles);
blobMeasurements = regionprops(handles.labeledImage, 'all');
numberOfBlobs = size(blobMeasurements, 1);
fontSize = 14; % Used to control size of "blob number" labels put atop the image.
labelShiftX = -7; % Used to align the labels in the centers of the object.
%blobECD = zeros(1, numberOfBlobs);
% Put the labels on the rgb labeled image also.
for k = 1 : numberOfBlobs % Loop through all blobs.
blobCentroid = blobMeasurements(k).Centroid; % Get centroid.
text(blobCentroid(1) + labelShiftX, blobCentroid(2), num2str(k), 'FontSize', fontSize, 'FontWeight', 'Bold');
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
however the result turns out like the image shown..
Can anybody help me on how to repair the coding so that the number on labeled image show the correct value.(eg: 1st car is shown as number 1).

Réponse acceptée

Image Analyst
Image Analyst le 27 Mai 2012
You have too many blobs. You need to get rid of the parking spot lines first. Try imopen() to get rid of the lines. Then do a hole fill with imfill(). Then use that with imreconstruct() to get back the original cars without the parking lines. Now you have just the cars but each car may be made up of several disconnected pieces that you have to join together into a single blob. Do a hole fill again, or call imclose() and do a hole file, and then call bwlabel(). I haven't tried it but I think that may be an improved approach, though it might take some tweaking to make it more robust to other images.
Another approach might be to use hough() or houghlines() to find lines, then divide up the image into an integer number of parking spaces - a grid essentially. Then take the sum of the pixels in the grid (parking space). If there are more 1 pixels than 0 pixels then the parking space is occupied.
  4 commentaires
Syazwan
Syazwan le 27 Mai 2012
done with the steps..they really worked!!!
thank you so much..
Image Analyst
Image Analyst le 27 Mai 2012
Water, true. I didn't say that correctly. He should determine if there are more than a certain number of white pixels (more than some small noise amount), like, say, 30 pixels or something.

Connectez-vous pour commenter.

Plus de réponses (1)

Walter Roberson
Walter Roberson le 27 Mai 2012
The code already labels the first car as number 1. It just isn't very good at figuring out what a car is.
  1 commentaire
Syazwan
Syazwan le 27 Mai 2012
yes..i knew it.
so how can i label the car correctly with the correct numbers?

Connectez-vous pour commenter.

Catégories

En savoir plus sur Get Started with Image Processing Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by