function local_variance(userImage)
clc;
close all;
workspace;
if(~isdeployed)
cd(fileparts(which(mfilename)));
end
hasIPT = license('test', 'image_toolbox');
if ~hasIPT
message = sprintf('Sorry, but you do not seem to have the Image Processing Toolbox.\nDo you want to try to continue anyway?');
reply = questdlg(message, 'Toolbox missing', 'Yes', 'No', 'Yes');
if strcmpi(reply, 'No')
return;
end
end
fontSize = 20;
if nargin == 0
promptMessage = sprintf('Which image do you want to use.\nThe coins or the cameraman?');
button = questdlg(promptMessage, 'Select Image', 'Coins', 'Cameraman', 'Coins');
if strcmp(button, 'Coins')
grayImage = double(imread('coins.png'));
else
grayImage = double(imread('cameraman.tif'));
end
else
grayImage = double(userImage);
end
startTime = tic;
subplot(2, 3, 1);
imshow(grayImage, []);
title('Original Image', 'FontSize', fontSize);
set(gcf, 'Position', get(0,'Screensize'));
blurredImage = conv2(grayImage, ones(5,5)/25);
subplot(2, 3, 2);
imshow(blurredImage, []);
title('Blurred (Local Mean) Image', 'FontSize', fontSize);
VarianceFilterFunction = @(x) var(x(:));
varianceImage = nlfilter(grayImage, [3 3], VarianceFilterFunction);
subplot(2, 3, 3);
imshow(varianceImage, [])
title('Variance Image', 'FontSize', fontSize);
standardDeviationImage = sqrt(varianceImage);
subplot(2, 3, 4);
imshow(standardDeviationImage, [])
title('Standard Deviation Image', 'FontSize', fontSize);
standardDeviationImage2 = stdfilt(grayImage);
subplot(2, 3, 5);
imshow(standardDeviationImage2, [])
title('Built-in stdfilt() filter', 'FontSize', fontSize);
verticalSobelKernel = fspecial('sobel');
sobelImage = imfilter(grayImage, verticalSobelKernel);
subplot(2, 3, 6);
imshow(sobelImage, [])
title('Sobel edge filter', 'FontSize', fontSize);
elapsedTime = toc(startTime);
message = sprintf('Done!\n\nElapsed time = %.2f seconds.', elapsedTime);
msgbox(message);
return;
Best Answer