I want to binarize an image using local thrersholding( localized Otsu, Niblack, Sauvola ). I have implemented global Otsu. See the following code-
#include<iostream>
#include<string>
#include<vector>
#include<opencv2/opencv.hpp>
#include<opencv2/imgproc.hpp>
#include<opencv2/highgui.hpp>
using namespace std;
using namespace cv;
int main()
{
vector<cv::String> fn;
glob("G:\\files\\*.jpg", fn, false);
string out = "F:\\image_out\\";
Mat image, gray, blur, blackWhite;
size_t count = fn.size(); //number of png files in images folder
for (size_t i=0; i<count; i++){
image = imread(fn[i], IMREAD_COLOR);
cvtColor(image, gray, COLOR_BGR2GRAY);
GaussianBlur(gray, blur, Size(7, 7), 0, 0);
threshold(blur, blackWhite, 0, 255, THRESH_BINARY | THRESH_OTSU);
imwrite((out+to_string(i)+".png"), blackWhite);
imshow( "black white image ", blackWhite); //optional
}
waitKey(0);
destroyAllWindows();
}
Now I want to replace global thresholding with local thresholding.
Note: If the same process can be done without opencv, that will also do. But ofcourse with C++.