在 MATLAB 中使用 imfill 命令的问题

Issue using imfill command in MATLAB

嗨,我有一个二进制变量(称为 'column' 大小 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...)谢谢。

您可以使用 imfill'holes' 选项

BW2= imfill(BW,'holes')

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

尝试以下示例:

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;