"Chang Qin" <cqin111@gmail.com> wrote in message
> answer by myself:
> J = rangefilt(I)
> !!!!
> Thank you~~~~

Sorry, but that's NOT the answer. To find the max value in a sliding window, use imdilate(), not rangefilt().
By the way, here's my demo on taking Standard Deviation, Vairance, Sobel, and convolution filters:
(You may need to join any lines that the newsreader splits into two).
% 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 mfile.
% (The line of code below is from Brett Shoelson of The Mathworks.)
% Don't use these lines if you're calling this from another mfile.
if(~isdeployed)
cd(fileparts(which(mfilename)));
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 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 builtin stdfilt() filter.
standardDeviationImage2 = stdfilt(grayImage);
subplot(2, 3, 5);
imshow(standardDeviationImage2, [])
title('Builtin stdfilt() filter', 'FontSize', fontSize);
% Perform Sobel filter
% h = fspecial('sobel') returns a 3by3 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.
