clc;
close all;
workspace;
format long g;
format compact;
fontSize = 20;
rgbImage = imread('hole.png');
subplot(2,2,1)
imshow(rgbImage)
title('Original Image', 'FontSize', fontSize);
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
set(gcf, 'Toolbar', 'none', 'Menu', 'none');
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
binaryImage = im2bw(rgbImage);
subplot(2,2,2);
imshow(binaryImage);
title('Original Binary Image', 'FontSize', fontSize);
binaryImage = imclearborder(binaryImage);
subplot(2,2,3);
imshow(binaryImage);
title('Frame now removed', 'FontSize', fontSize);
filledImage = imfill(binaryImage, 'holes');
subplot(2,2,4);
imshow(filledImage);
title('Image without frame or holes', 'FontSize', fontSize);
Best Answer