Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Image 如何计算重叠对象和具有一种以上颜色的对象?_Image_Matlab_Image Processing - Fatal编程技术网

Image 如何计算重叠对象和具有一种以上颜色的对象?

Image 如何计算重叠对象和具有一种以上颜色的对象?,image,matlab,image-processing,Image,Matlab,Image Processing,我想创建一个可以计算图像中对象数量的程序。除以下图像外,所有操作都进行得很顺利: 具有一种以上颜色的对象 重叠对象 下面是我的程序,它只能计算图像中只有一种颜色且没有重叠的对象的数量。我使用函数bwlabel a=imread('Tumpukan Buku2.jpg'); a_citra_keabuan = rgb2gray(a); threshold = graythresh(a_citra_keabuan); a_bww = im2bw(a_citra_keabuan,threshold);

我想创建一个可以计算图像中对象数量的程序。除以下图像外,所有操作都进行得很顺利:

  • 具有一种以上颜色的对象
  • 重叠对象
  • 下面是我的程序,它只能计算图像中只有一种颜色且没有重叠的对象的数量。我使用函数
    bwlabel

    a=imread('Tumpukan Buku2.jpg');
    a_citra_keabuan = rgb2gray(a);
    threshold = graythresh(a_citra_keabuan);
    a_bww = im2bw(a_citra_keabuan,threshold);
    a_bw=~a_bww;
    [labeled,numObjects]=bwlabel(a_bw);
    [m,n]=size(a_bw);
    s = regionprops(labeled, 'Centroid');
    B = bwboundaries(a_bw);
    
    imshow(a_bw)
    hold on
    for k = 1:numel(s)
        c = s(k).Centroid;
        text(c(1), c(2), sprintf('%d', k), ...
            'HorizontalAlignment', 'center', ...
            'VerticalAlignment', 'middle');
    end
    for k = 1:length(B)
        boundary = B{k};
        plot(boundary(:,2), boundary(:,1), 'g', 'LineWidth', 0.2)
    end
    hold off
    
    以下是具有1种颜色对象的图像的结果:

    对于对象颜色大于1且重叠的图像,以下是错误的结果:


    如何解决这个问题?

    首先,您需要清楚地定义输入数据-您想要检测什么类型的对象(书籍、人物、任何类型的对象?),环境条件的范围是什么(平滑背景与纹理、照明、透视)

    然后试着看看什么适合你的输入数据范围。没有“正确”的答案——这完全取决于你的数据

    您还可以尝试合并先前的信息,这些信息是您在评估场景时知道的,而计算机仅通过评估像素是不会知道的


    例如,可能所有对象都具有某种最小大小。因此,您的算法可以过滤为仅返回具有
    pixelArea>minArea
    的对象。也许你只希望每种颜色有一个物体。因此,如果两个检测对象的颜色直方图与给定的公差匹配,则将它们视为同一对象。 所以,我不能对任何类型的对象进行分割?我必须聚焦于具有相同结构的物体。不能用matlab的相同代码分割像圆这样的对象与对象重叠的书?