clc;
close all;
clear;
workspace;
format long g;
format compact;
fontSize = 20;
folder = fileparts(which('cameraman.tif'));
button = menu('Use which demo image?', 'CameraMan', 'Moon', 'Eight', 'Coins', 'Pout');
if button == 1
baseFileName = 'cameraman.tif';
elseif button == 2
baseFileName = 'moon.tif';
elseif button == 3
baseFileName = 'eight.tif';
elseif button == 4
baseFileName = 'coins.png';
else
baseFileName = 'pout.tif';
end
folder = fileparts(which('cameraman.tif'));
fullFileName = fullfile(folder, baseFileName);
original = imread(fullFileName);
subplot(2, 2, 1);
imshow(original, []);
title('Original Grayscale Image', 'FontSize', fontSize, 'Interpreter', 'None');
se = strel('disk',12);
filteredImage = imbothat(original,se);
subplot(2, 2, 2);
imshow(filteredImage, []);
title('Filtered Grayscale Image', 'FontSize', fontSize, 'Interpreter', 'None');
binaryImage = filteredImage > 128
subplot(2, 2, 3);
imshow(binaryImage, []);
title('Binary Image', 'FontSize', fontSize, 'Interpreter', 'None');
redChannel = original;
greenChannel = original;
blueChannel = original;
redChannel(binaryImage) = 255;
greenChannel(binaryImage) = 0;
blueChannel(binaryImage) = 0;
rgbImage = cat(3, redChannel, greenChannel, blueChannel);
subplot(2, 2, 4);
imshow(rgbImage, []);
title('Original Image with Spots Overlaid', 'FontSize', fontSize, 'Interpreter', 'None');
Best Answer