Remove Noise
Mat img_noise, img_box_smooth;
medianBlur(img, img_noise, 3);
blur(img, img_box_smooth, Size(3,3));
Remove Light
// Load image to process
Mat light_pattern= imread(light_pattern_file, 0);
if(light_pattern.data==NULL){
// Calculate light pattern
light_pattern= calculateLightPattern(img_noise);
}
medianBlur(light_pattern, light_pattern, 3);
//Apply the light pattern
Mat img_no_light;
img_noise.copyTo(img_no_light);
if(method_light!=2){
img_no_light= removeLight(img_noise, light_pattern, method_light);
}
Binarize
// Binarize image for segment
Mat img_thr;
if(method_light!=2){
threshold(img_no_light, img_thr, 30, 255, THRESH_BINARY);
}else{
threshold(img_no_light, img_thr, 140, 255, THRESH_BINARY_INV);
}