문제

I am currently writing a program on Matlab for Image Processing. I am using an image (below) to attempt to count the number of white cars in the image. I have used filtering commands, strel(disk, 2), and have managed to detect the two white cars in the image but due to the way the binary image (below) displays a car it counts one car as two.

Are there any solutions to overcome this problem or are there any particular methods I should be using as an alternative to the code below?

a = imread('Cars2.jpg');        %Read the image Car1.jpg
subplot(3,3,1), imshow (a);     %Display RGB image Car1.jpg

b = rgb2gray(a);                %Turn Car1 from RGB to greyscale
subplot(3,3,2), imshow (b);     %Display greyscale image Car1.jpg

c = graythresh (a);             %Automatically set appropriate threshold for foreground & background (Otsu's Method)
d = im2bw (b,0.8);              %Convert from greyscale to binary image
subplot (3,3,3), imshow(d);     %Display binary image Car1.jpg
subplot(3,3,4), imhist (b,256); %Display histogram for greyscale values (image, samples)

SE = strel ('disk',2);          %Set Disk radius for filtering unnecessary pixels
e = imopen (d,SE);              %Erode then Dilate image with Disk radius
subplot (3,3,5), imshow(e);     %Display openned/filtered image Car1.jpg

B = bwboundaries(e);
imshow(e)
text(10,10,strcat('\color{red}Objects Found:',num2str(length(B))))
hold on

EDIT: As i have under 10 reputation I can't post the image displayed from the code but the theory is pretty generic so I hope you understand what I'm getting across. The images are similar to http://www.mathworks.co.uk/help/images/examples/detecting-cars-in-a-video-of-traffic.html

도움이 되었습니까?

해결책

Instead of using bwboundaries I would use regionprops(e). You can then use some additional logic by looking at the area of the object and the shape of the bounding box to infer if the object is one or two cars.

If you are only interested in detecting white cars, your overall algorithm could be improved by converting the image into HSV colour space and thresholding on the saturation and value channels instead of using im2bw. If you have a video sequence I would segment using vision.ForegroundDetector or another Gaussian mixture model segmentation technique.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top