【问题标题】:Issue using imfill command in MATLAB在 MATLAB 中使用 imfill 命令出现问题
【发布时间】:2016-08-12 20:46:26
【问题描述】:

您好,我有一个二进制变量(称为“列”大小 733x1),我正在尝试将 0 更改为介于 1 和 1 之间的值(即 00001110011... 到 00001111111...)。我曾尝试使用 imfill,但无法这样做。我已将它从逻辑类型转换为 uint8 以提供帮助,但它没有工作。

column=column*255 % convert to form to work with 'imfill' command
column_fill=uint8(column)
column_fill=imfill(column); 

但是,在我的变量中的 1 之间,我仍然有几个 0 我想去掉。 Link to data。输出(从 000..000111000011101... 到 000..000111111111111...)谢谢。

【问题讨论】:

    标签: matlab variables command


    【解决方案1】:

    试试下面的例子:

    load data
    column=column100*255 % convert to form to work with 'imfill' command
    
    %Create column filled with 255 values.
    white_column = ones(size(column))*255;
    
    %Padd column from both sides (create 3 columns image).
    im = [white_column, column, white_column];
    
    %Apply imfill on image im
    im_fill = imfill(uint8(im)); 
    
    %Extract center column of im_fill.
    column_fill = im_fill(:, 2);
    

    你也可以不使用imfill试试下面的代码:

    column_fill = column100;
    column_fill(find(column100 == 1, 1):find(column100 == 1, 1, 'last')) = 1;
    

    【讨论】:

    • 非常感谢!完美运行。
    • 感谢您的回答。当它找到最后一个“1”以将所有先前的“0”值更改为“1”时,有没有办法改变它。例如(000...000100100000 到 000...000111111111)。谢谢。
    【解决方案2】:

    您可以将imfill'holes' 选项一起使用

    BW2= imfill(BW,'holes')
    

    但你应该保留你的图像二进制而不是乘以 255。

    【讨论】:

    • 我试过了,没用。请找到附加的数据集。 dropbox.com/s/9ib58auz90eg5f5/data.mat?dl=0
    • 您的变量column 应该是二进制的。您是否从column=column*255 中删除了*255
    • 是的,我做到了,它不包含在数据集中,这是我想到的一种方法。
    猜你喜欢
    • 2022-01-15
    • 1970-01-01
    • 2019-03-16
    • 2014-12-23
    • 1970-01-01
    • 2018-04-11
    • 1970-01-01
    • 2011-01-03
    • 2021-10-07
    相关资源
    最近更新 更多