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!