why imfill resul is a white figure?

5 vues (au cours des 30 derniers jours)
elena rondina
elena rondina le 27 Jan 2016
Commenté : elena rondina le 27 Jan 2016
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

Réponse acceptée

Image Analyst
Image Analyst le 27 Jan 2016
Modifié(e) : Image Analyst le 27 Jan 2016
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 commentaire
elena rondina
elena rondina le 27 Jan 2016
thank you now code is ok...you are great!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur White dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by