OpenCV has an adaptive threshold paradigm, available at: http://docs.opencv.org/modules/imgproc/doc/miscellaneous_transformations.html#adaptivethreshold
The function prototype looks like this:
void adaptiveThreshold(InputArray src, OutputArray dst,
double maxValue, int adaptiveMethod,
int thresholdType, int blockSize, double C);
The first two parameters are the input image and the storage location for the output threshold image. maxValue- this is the threshold value assigned to the output pixel, if it passes the criteria, adaptiveMethod- this is the method used for the adaptive threshold value, thresholdType- the type of threshold that you want to execute (later), blockSize- the size of the windows to check (later), and C- this constant to subtract from each window. I never had to use this, and I usually set it to 0.
adaptiveThreshold - blockSize x blockSize , C. , maxValue, 0. , .
, , - :
#include <cv.h>
#include <highgui.h>
using namespace cv;
void threshold()
{
Mat image;
image = imread("image.jpg", 1);
Mat gray_image;
cvtColor(image, gray_image, CV_BGR2GRAY);
namedWindow("Gray image", CV_WINDOW_AUTOSIZE);
imshow("Gray image", gray_image);
waitKey(0);
int maxValue = 255;
int blockSize = 25;
int C = 0;
adaptiveThreshold(gray_image, gray_image, maxValue,
CV_ADAPTIVE_THRESH_MEAN_C, CV_THRESH_BINARY,
blockSize, C);
namedWindow("Thresholded image", CV_WINDOW_AUTOSIZE);
imshow("Thresholded image", gray_image);
waitKey(0);
}
int main( int argc, const char** argv )
{
threshold();
}