clc;
close all;
imtool close all;
clear;
workspace;
fontSize = 20;
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
baseFileName = 'cameraman.tif';
fullFileName = fullfile(folder, baseFileName);
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, 'file')
fullFileName = baseFileName;
if ~exist(fullFileName, 'file')
errorMessage = sprintf('Error: %s does not exist.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
grayImage = imread(fullFileName);
[rows columns numberOfColorBands] = size(grayImage);
subplot(2, 3, 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')
sdImage = stdfilt(grayImage);
subplot(2, 3, 2);
imshow(sdImage, []);
title('Std. Dev. Image', 'FontSize', fontSize);
varianceImage = sdImage .^2;
subplot(2, 3, 3);
imshow(varianceImage, []);
title('Variance Image', 'FontSize', fontSize);
meanVarianceImage = conv2(varianceImage, ones(3)/9);
subplot(2, 3, 4);
imshow(meanVarianceImage, []);
title('Mean Variance Image', 'FontSize', fontSize);
for gl = 0:255
matchingIndexes = (grayImage == gl);
W(gl+1) = mean(meanVarianceImage(matchingIndexes));
end
subplot(2, 3, 5);
plot(W);
grid on;
title('Plot of W', 'FontSize', fontSize);
xlabel('Gray Level', 'FontSize', fontSize);
Best Answer