i need some help
1 次查看(过去 30 天)
显示 更早的评论
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).
0 个评论
采纳的回答
Image Analyst
2012-5-27
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 个评论
Image Analyst
2012-5-27
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.
更多回答(1 个)
Walter Roberson
2012-5-27
The code already labels the first car as number 1. It just isn't very good at figuring out what a car is.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!