how to calculate mean and variance of the image using W*W sliding window

contrast enhancement is to improve the contrast of lesions for detection using a w*w sliding window with assumption that w is large enough to contain a statistically representative distribution of the local variation of lesions. where the sigmoid function used with the maximum and minimum intensity values of smooth green channel image,respectively. mean and variance of intensity values with in the window.
CAN U HELP ME WITH CODING

 Accepted Answer

Try this:
meanImage = conv2(grayImage, ones(w)/w^2);
stdDevImage = stdfilt(grayImage, ones(w)/w^2);
varianceIMage = stdDevImage .^2;

10 Comments

dear image analyst, I need the output mean and variance of the sliding window in the matrix form(may be image for my work) so that i need to subtract from the image matrix and divide it by the variance (ie, to substitute in the formula sigmoid function) to perform local contrast enhancement
Sounds like a Wallis filter ( http://www.dtic.mil/dtic/tr/fulltext/u2/a248301.pdf). Okay, just remember to cast your images to double before subtracting and dividing or your results will be rounded to integers and clipped to the range 0-255.
given that the sigmoid function formula is 1 / {[1+exp((M-I)/V)]} were M is the mean of the intensity values in the w*w sliding window(subimage), V is the variance of the intensity values in the w*w sliding window(subimage) *I is the *colored image *
I got the standard deviation of the image as output, but while converting it to variance of the image it shows the error that matrix should be square, how can i convert the image matrix to square with out the loss of information
It doesn't need to be square. Did you use the dot in .^2? Or did you just do ^2?
just ^2 ,is it wrong
Yes. That's wrong. That's a matrix multiply, not an element-by-element multiply. So it's like A*B, except it's A*A, and as you know the number of columns of A must match the number of rows in B, but since A is B, the number of columns of A must match the number of rows of A so it must be square. But you don't want that. You want an element by element multiple. I didn't add the dot in there just for the fun of it - you need it.
the error showing is * ??? Error using ==> mldivide * Matrix dimensions must agree. * what should i do how can i code the formula sigmoid function formula is 1 / {[1+exp((M-I)/V)]} were M is the meanimage, V is the varianceimage , I is the color image * and my code is sigmoid = 1/(1+exp((double(meanImage)-double(green))./double(sdImage))); * is it correct?
Use the 'same' option in conv2 to get the same size image.
meanImage = conv2(grayImage, ones(w)/w^2, 'same');

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!