【问题标题】:Identifying White Cars in an Image using Matlab使用 Matlab 识别图像中的白色汽车
【发布时间】: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


【解决方案1】:

我不会使用bwboundaries,而是使用regionprops(e)。然后,您可以通过查看对象的面积和边界框的形状来使用一些额外的逻辑来推断对象是一辆车还是两辆汽车。

如果您只对检测白色汽车感兴趣,则可以通过将图像转换为 HSV 颜色空间并在饱和度和值通道上设置阈值来改进您的整体算法,而不是使用 im2bw。如果您有视频序列,我会使用vision.ForegroundDetector 或其他高斯混合模型分割技术进行分割。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-12
    • 1970-01-01
    • 2018-10-13
    • 1970-01-01
    • 2018-06-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多