local enhancement using mean and standard deviation
조회 수: 8 (최근 30일)
이전 댓글 표시
i need a codes for 'local enhancement using mean and standard deviation'.... urgent
댓글 수: 1
Walter Roberson
2012년 4월 2일
http://www.mathworks.com/matlabcentral/answers/29922-why-your-question-is-not-urgent-or-an-emergency
채택된 답변
Image Analyst
2012년 4월 1일
Here's my demo. It calculates local mean and standard deviation. I leave it up to you to figure out how to enhance the image once you have those images (there are a variety of ways). Someday perhaps I'll upload all my demos to the File Exchange in a "grab bag of image processing demos" but until then here it is:
% Demo to take the local mean, variance, and standard deviation
% of a gray scale image.
% userImage, if passed in, is used as the image.
% If userImage is not passed in, user is asked to use a demo image.
% Code written by ImageAnalyst
function local_variance(userImage)
% Clean up.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
workspace; % Make sure the workspace panel is showing.
% Change the current folder to the folder of this m-file.
% (The line of code below is from Brett Shoelson of The Mathworks.)
% Don't use these lines if you're calling this from another m-file.
if(~isdeployed)
cd(fileparts(which(mfilename)));
end
% Check that user has the Image Processing Toolbox installed.
hasIPT = license('test', 'image_toolbox');
if ~hasIPT
% User does not have the toolbox installed.
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')
% User said No, so exit.
return;
end
end
% Initialize.
fontSize = 20;
if nargin == 0
% No image passed in on the command line.
% Read in one of the standard MATLAB demo images
% as our original gray scale image and display it.
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')); % Cast to double.
else
grayImage = double(imread('cameraman.tif')); % Cast to double.
end
else
% Use the image array passed in on the command line.
grayImage = double(userImage); % Cast to double.
end
% Start timing.
startTime = tic;
subplot(2, 3, 1);
imshow(grayImage, []);
title('Original Image', 'FontSize', fontSize);
set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.
% Blur the image with a 5 by 5 averaging (box filter) window.
blurredImage = conv2(grayImage, ones(5,5)/25);
subplot(2, 3, 2);
imshow(blurredImage, []);
title('Blurred (Local Mean) Image', 'FontSize', fontSize);
% Perform a variance filter.
% Output image is the variance of the input image in a 3 by 3 sliding window.
VarianceFilterFunction = @(x) var(x(:));
varianceImage = nlfilter(grayImage, [3 3], VarianceFilterFunction);
% An alternate way of doing the variance filter is on the next line:
% varianceImage = reshape(std(im2col(originalImage,[3 3],'sliding')), size(originalImage)-2);
subplot(2, 3, 3);
imshow(varianceImage, [])
title('Variance Image', 'FontSize', fontSize);
% Compute the square root of the variance image to get the standard deviation.
standardDeviationImage = sqrt(varianceImage);
subplot(2, 3, 4);
imshow(standardDeviationImage, [])
title('Standard Deviation Image', 'FontSize', fontSize);
% Compute the standard deviation filter with MATLAB's built-in stdfilt() filter.
standardDeviationImage2 = stdfilt(grayImage);
subplot(2, 3, 5);
imshow(standardDeviationImage2, [])
title('Built-in stdfilt() filter', 'FontSize', fontSize);
% Perform Sobel filter
% h = fspecial('sobel') returns a 3-by-3 filter h (shown below) that emphasizes horizontal edges
% using the smoothing effect by approximating a vertical gradient.
% If you need to emphasize vertical edges, transpose the filter h'.
% [ 1 2 1
% 0 0 0
% -1 -2 -1 ]
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; % End of local_variance() function.
댓글 수: 2
Rand J
2016년 5월 11일
Image Analyst ,would you please explain how to enhance the image once you have those images? I tried Convolveing the original image with them but it didn't work.
Image Analyst
2016년 5월 11일
If you did it correctly, it did work, though perhaps it didn't give you the effect you want to achieve. How you do an enhancement depends on what you want to achieve. For example if you want to make edges more noticeable, that will take one algorithm. If you want to find you in a huge collect of images and want to paste a photo of Kate Upton next to you with her arm around you, then that would be a different algorithm.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Filtering and Enhancement에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!