clc;
close all;
imtool close all;
clear;
workspace;
format longg;
format compact;
fontSize = 20;
folder = fileparts(which('cameraman.tif'));
baseFileName = 'cameraman.tif';
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, 'file')
fullFileNameOnSearchPath = baseFileName;
if ~exist(fullFileNameOnSearchPath, 'file')
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
grayImage = imread(fullFileName);
[rows, columns, numberOfColorBands] = size(grayImage);
if numberOfColorBands > 1
grayImage = grayImage(:, :, 2);
end
subplot(1, 2, 1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize);
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
noisyImage = grayImage;
noiseIndexes = randperm(numel(grayImage), 5000);
noisyImage(noiseIndexes) = 255;
subplot(1, 2, 2);
imshow(noisyImage, []);
title('Noisy Image', 'FontSize', fontSize);
axis on;
Best Answer