【问题标题】:how to take the values of Background from an image after segmentation in Matlab?在 Matlab 中分割后如何从图像中获取背景值?
【发布时间】:2012-12-13 00:19:42
【问题描述】:

当我对任何图像进行分割时,它会返回一个图像,即具有背景和前景表示的二进制图像。 现在,如果我只想将图像的背景用于任何目的......怎么做......我的意思是在分割后我得到了一个二值图像现在如何识别(或获取)背景的值。? ??????

【问题讨论】:

    标签: matlab image-processing


    【解决方案1】:
    % Assume you have these variables:
    %  'mask'  - binary segmentation results, all 1's or 0's.
    %  'img'   - original image.
    %  'bgImg' - Output, containing background only.
    
    bgImg = zeros(size(img));  % Initialize to all zeros.
    bg(mask) = img(mask);      % Use logical indexing.
    

    【讨论】:

      【解决方案2】:

      我假设您有一张灰度图像。当您将分割目标设为 1 并将背景设为 0 时,只需执行元素矩阵乘法即可获得目标图像。这类似于掩蔽。如果你只想要背景,你可以做 (1 - Binary image) 并与原始图像进行类似的乘法。请记住,这是逐元素乘法,而不是矩阵乘法。

      【讨论】:

      • 是的,我有一张灰度图像,我只想要用 1 表示的背景图像(如果我的图像在分割后)。现在我想从原始图像中获取背景像素,并希望获取背景像素的平均值。
      • 如果我有名为 'img' 的分段图像......我可以通过使用像 ind=find(img==1); 这样的 find 语句来获取背景值; bt 它给出了奇怪的东西.....
      • @chee 请将这些 cmets 添加到您的问题中 - 它们使问题更加清晰。
      【解决方案3】:

      如果你想测量前景/背景区域的统计数据,一个有趣的选择是regionprops

      % img - variable containing original grey-scale image
      % mask - binary mask (same size as img) with 0 - background 1 - foreground
      
      % using regionprops to measure average intensity and weighted centroid,
      % there are MANY more interesting properties ou can measure, use 
      % >> doc regionprops 
      % to discover them 
      st = regionprops( mask + 1, img, 'MeanIntensity', 'WeightedCentroid');
      
      % get BG avg intensity:
      fprintf(1, 'Avg intensity of background = %.2g\n', st(1).MeanIntensity );
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-09-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-11-15
        • 2016-01-12
        相关资源
        最近更新 更多