why imfill resul is a white figure?

조회 수: 2 (최근 30일)
elena rondina
elena rondina 2016년 1월 27일
댓글: elena rondina 2016년 1월 27일
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

채택된 답변

Image Analyst
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);
  댓글 수: 1
elena rondina
elena rondina 2016년 1월 27일
thank you now code is ok...you are great!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Feature Detection and Extraction에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by