why imfill resul is a white figure?
2 次查看(过去 30 天)
显示 更早的评论
hi i have to close the holes in a image but my resulting is a white figure. Why? where is the problem? my code is:
img=imread('hole.png')
subplot(1,3,1)
imshow(img)
title('image')
%binarization
bw_immage=im2bw(img);
subplot(1,3,2);
imshow(bw_immage);
title('binary image');
%close the holes
i=imfill(bw_immage,'holes');
subplot(1,3,3);
imshow(i);
title('image unless holes');
end
hole.png is:
hole.png is the same immage that use matlab documentation:http://it.mathworks.com/help/images/ref/imfill.html
0 个评论
采纳的回答
Image Analyst
2016-1-27
编辑:Image Analyst
2016-1-27
Your image had a white frame/border around it. Use imclearborder() to get rid of that. See corrected code:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
rgbImage = imread('hole.png');
subplot(2,2,1)
imshow(rgbImage)
title('Original Image', 'FontSize', fontSize);
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Get rid of tool bar and pulldown menus that are along top of figure.
set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
%binarization
binaryImage = im2bw(rgbImage);
% Display this image.
subplot(2,2,2);
imshow(binaryImage);
title('Original Binary Image', 'FontSize', fontSize);
% Important: Get rid of surrounding white border (frame):
binaryImage = imclearborder(binaryImage);
% Display this image.
subplot(2,2,3);
imshow(binaryImage);
title('Frame now removed', 'FontSize', fontSize);
% Close the holes
filledImage = imfill(binaryImage, 'holes');
subplot(2,2,4);
imshow(filledImage);
title('Image without frame or holes', 'FontSize', fontSize);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Feature Detection and Extraction 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!