How to use imfill() function to fill the interior of the boundary surface using Matlab?

27 ビュー (過去 30 日間)
Hi dear community members,
i am using flood fill operation to fill the interior. i have closed the boundary surface. There are no holes on the boundary surface but still, the interior cannot be filled.
I am using the following code. Please guide me where i am making mistake. The matrix A as a text file is already attached.
Regards.
interior_filled = imfill(A,'holes')
  1 件のコメント
M.S. Khan
M.S. Khan 2021 年 3 月 12 日
Is the imfill() function is not capable to fill the interior region? How come, boundary surface is closed and imfill() function is not applicable?

サインインしてコメントする。

採用された回答

Image Analyst
Image Analyst 2021 年 3 月 12 日
@M.S. Khan, try this:
% Demo by Image Analyst, March, 2021.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clearvars;
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 16;
fprintf('Beginning to run %s.m ...\n', mfilename);
grayImage = importdata('Boundary_closed_1s_3s.txt');
subplot(2, 1, 1);
imshow(grayImage, []);
impixelinfo;
axis('on', 'image');
% Create a binary image.
binaryImage = grayImage ~= 0;
% Fill the object by scanning across all columns and
% drawing a line from the top-most pixel to the bottom-most pixel.
[rows, columns] = size(binaryImage);
for col = 1 : columns
% Find the top most pixel.
topRow = find(binaryImage(:, col), 1, 'first');
if ~isempty(topRow)
% If there is a pixel in this column, then find the lowest/bottom one.
bottomRow = find(binaryImage(:, col), 1, 'last');
% Fill from top to bottom.
binaryImage(topRow : bottomRow, col) = true;
end
end
interior_filled = binaryImage;
% interior_filled = imfill(binaryImage, 4, 'holes');
subplot(2, 1, 2);
imshow(binaryImage, []);
axis('on', 'image');
fprintf('Done running %s.m\n', mfilename);
  12 件のコメント
M.S. Khan
M.S. Khan 2021 年 3 月 19 日
Hi Dear Image Analyst, could you please share your feedback. I am waiting for your expert point of view. Regards!
M.S. Khan
M.S. Khan 2021 年 3 月 20 日
i think, the 'P' should be changed with respect to the shape of the object. i am trying how to handle it.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange3-D Volumetric Image Processing についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by