% I = RGB 2 gray(RGB); % color converted to grayscale
I = imread(' source 3 . BMP ');
level = gray thresh(I); % get the right threshold, get the right threshold.
bw= im2bw(I,level); % binarization
SE= strel('square ',3); % Set Extended Structure Element
bw 1 = im dilat(bw,SE); Expansion percentage
SE 1= strel ('any', eye (5)); % set corrosion structural elements
BW2= imerode(bw,se 1); % corrosion
BW3= bwmorph(bw,' open'); Percentage of operation
BW4= bwmorph(bw,' close '); % close operation
Figure (1),
Subplots (2, 3, 1), im show (i); Title ("original");
Subplots (2, 3, 2), IM Show (BW); Title ("Binary Diagram");
Subplots (2, 3, 3), im show (bw1); Title ("Inflation");
Subplots (2, 3, 4), IM SHOW (BW2); Title ("Corrosion");
Subplots (2, 3, 5), IM Show (BW3); Title ("Open operation");
Subplots (2, 3, 6), IM SHOW (BW4); Title ("Close Operation");
%
Figure (2)
BW5 = imfill(bw,' hole');
Subplot (12 1), im show (bw), title ("source image binarization")
Subplot (122), Instant Message Display (bw5), Title ("Filled Image")
% contour extraction
Figure (3)
contour = bwperim(bw);
Imshow (contour line);
Title ("Outline")