Wikipedia has a good explanation for standard deviation that you can use for a standard deviation filter.
Basically, it comes down to blurring the image using the box filter, blurring the square of the image using the box filter, and extracting the square root of their difference.
UPDATE: This is probably better shown using the equation from Wikipedia ... 
You can think of the OpenCV blur function as representing the expected value (ie E [X], as well as the average value of the sample) of the neighborhood of interest. Random samples X in this case are represented by image pixels in a local neighborhood. Therefore, using the above equivalence, we have something like sqrt(blur(img^2) - blur(img)^2) in OpenCV. The implementation of this method allows you to calculate local tools and standard deviations.
In addition, just in case, you are interested in learning a mathematical proof. This equivalence is known as the computational formula for rejection .
Here's how you can do it in OpenCV:
#include <iostream> #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <opencv2/imgproc/imgproc.hpp> using namespace std; using namespace cv; Mat mat2gray(const Mat& src) { Mat dst; normalize(src, dst, 0.0, 1.0, NORM_MINMAX); return dst; } int main() { Mat image = imread("coke-can.jpg", 0); Mat image32f; image.convertTo(image32f, CV_32F); Mat mu; blur(image32f, mu, Size(3, 3)); Mat mu2; blur(image32f.mul(image32f), mu2, Size(3, 3)); Mat sigma; cv::sqrt(mu2 - mu.mul(mu), sigma); imshow("coke", mat2gray(image32f)); imshow("mu", mat2gray(mu)); imshow("sigma",mat2gray(sigma)); waitKey(); return 0; }
This results in the following images:
Original

Average

Standard deviation

Hope this helps!
mevatron
source share