【发布时间】:2014-03-15 18:06:46
【问题描述】:
我目前正在 Matlab 上编写一个用于图像处理的程序。我正在使用图像(下图)来尝试计算图像中白色汽车的数量。我使用了过滤命令 strel(disk, 2),并设法检测到图像中的两辆白色汽车,但由于二进制图像(下图)显示汽车的方式,它会将一辆汽车视为两辆。
是否有任何解决方案来克服这个问题,或者我应该使用任何特定的方法来替代下面的代码?
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
编辑:由于我的声誉低于 10,因此我无法发布代码中显示的图像,但该理论非常通用,因此我希望您了解我所理解的内容。图片类似于http://www.mathworks.co.uk/help/images/examples/detecting-cars-in-a-video-of-traffic.html
【问题讨论】:
-
变量
c未使用,如果不需要,删除该行。 -
谢谢,但不幸的是它没有回答我的问题
-
看看来自 Matlab 的rice counting demo。此外,您可以将图片上传到某处(dropbox..)并在您的问题中包含一个链接。
标签: matlab image-processing detection