www.gusucode.com > images 案例代码 matlab源码程序 > images/FillRegionsUsingMaskImageExample.m
%% Fill Regions Using Mask Image % %% % Read grayscale image into the workspace. % Copyright 2015 The MathWorks, Inc. I = imread('eight.tif'); %% % Create a mask image that covers all the coins. mask = I < 200; %% % Fill holes in the mask image. mask = imfill(mask,'holes'); %% % Remove noise in the mask image. mask = imerode(mask,strel('disk',10)); mask = imdilate(mask,strel('disk',20)); %% % Fill the regions in the input image using the mask image. J = regionfill(I,mask); %% % Display the original image next to the mask image and the filled image. figure subplot(1,3,1) imshow(I) title('Original image') subplot(1,3,2) imshow(mask) title('Mask of pixels to fill') subplot(1,3,3) imshow(J) title('Resulting image')