www.gusucode.com > images 案例代码 matlab源码程序 > images/EraseLargestLetterFromImageExample.m
%% Erase Largest Component from Image % %% % Read image into the workspace and display it. BW = imread('text.png'); imshow(BW) %% % Find the number of connected components in the image. CC = bwconncomp(BW) %% % Determine which is the largest component in the image and erase it (set % all the pixels to 0). numPixels = cellfun(@numel,CC.PixelIdxList); [biggest,idx] = max(numPixels); BW(CC.PixelIdxList{idx}) = 0; %% % Display the image, noting that the largest component happens to be the % two consecutive f's in the word different. figure imshow(BW)