clc;
close all;
clear;
workspace;
format long g;
format compact;
fontSize = 25;
baseFileName = 'eeewvwvwv.PNG';
folder = [];
fullFileName = fullfile(folder, baseFileName);
grayImage = imread(fullFileName);
[rows, columns, numberOfColorChannels] = size(grayImage);
if numberOfColorChannels > 1
grayImage = rgb2gray(grayImage);
end
subplot(2, 2, 1);
imshow(grayImage, []);
axis on;
caption = sprintf('Original Gray Scale Image');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
hp = impixelinfo();
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
set(gcf, 'Toolbar', 'none', 'Menu', 'none');
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
drawnow;
mask = grayImage > 30;
props = regionprops(logical(mask), 'Area');
allAreas = sort([props.Area])
mask = bwareaopen(mask, 25);
mask = imclearborder(mask);
subplot(2, 2, 2);
imshow(mask);
axis on;
axis image;
title('Binary Image Mask', 'fontSize', fontSize);
drawnow;
maskedGrayImage = grayImage;
maskedGrayImage(~mask) = 0;
subplot(2, 2, 3);
imshow(maskedGrayImage);
axis on;
axis image;
title('Masked Gray Scale Image', 'fontSize', fontSize);
drawnow;
Best Answer