【问题标题】:Mask image with static threshold in matlabmatlab中具有静态阈值的蒙版图像
【发布时间】:2013-03-16 19:01:17
【问题描述】:

我需要在 matlab 中以平均强度的 10% 的静态阈值对图像进行二值化。我使用mean2(Image) 找到平均强度,这会在其中一张图像中返回一个平均值,比如15.10。因此我的平均阈值是1.51.im2bw(image,level) 的阈值在 0 到 1 之间。在这种情况下,如何在 matlab 中对我的图像进行二值化?

【问题讨论】:

    标签: image matlab video image-processing morphological-analysis


    【解决方案1】:

    您可以使用简单的逻辑语句对图像进行二值化。为了完整起见,我还添加了阈值确定。

    threshold = mean(Image(:));
    
    binaryMask = Image > 0.1 * threshold;
    

    【讨论】:

    • 我认为我没有得到二进制图像。有很多彩色像素。二进制应该是黑白的吧?顺便说一句,mean() 不应该是 mean2() 吗?
    • @Panther:您可能首先需要使用rgb2gray 将图像从RGB 转换为灰度(如果size(Image) 在第三维中显示3 的大小)。另外mean2(x)mean(x(:)) 的快捷方式,参见"algorithm" section in the help
    【解决方案2】:

    1) 您可以先使用im2double() 将原始图像转换为双格式。那么所有的像素值都会在 0 和 1 之间。然后你可以使用im2bw(im,level)

    2)如果你不想将图像转换为双倍,那么你可以这样做。假设阈值是平均值的 10%,例如threshold = 1.51。假设您拥有的图像是im。然后im(im<threshold) = 0; im(im>=threshold)=1。经过这两个操作,im 将变成二值图像。

    【讨论】:

    • 我这样做了:mu=mean2(idiff); threshold=0.1*mu; idiff(idiff>=threshold)=1; idiff(idiff<threshold)=0; imagesc(idiff); 我得到一张黑色图像。我做错什么了吗?
    • 改变'idiff(idiff>=threshold)=1;'的顺序和 'idiff(idiff
    【解决方案3】:

    假设您的图像是矩阵img,您可以执行以下操作:

    t = mean2(img) * 0.1 % Find your threshold value
    img(img < t) = 0 % Set everything below the treshold value to 0
    img(img ̃= 0) = 1 % Set the rest to 1
    

    【讨论】:

      【解决方案4】:

      如果您想使用im2bw,则需要对图像的平均强度与最大强度的结果进行归一化(提到的其他解决方案当然是正确且有效的):

      ImageN=Image./max(Image(:))
      t = mean2(ImageN) * 0.1 % Find your threshold value 
      im2bw(Image,t)
      

      【讨论】:

        猜你喜欢
        • 2021-10-02
        • 1970-01-01
        • 1970-01-01
        • 2016-07-15
        • 2020-11-06
        • 1970-01-01
        • 2020-12-01
        • 2015-05-04
        • 2021-02-10
        相关资源
        最近更新 更多