Noise removal & Lighting removal & Binarization

Remove Noise

  1.   Mat img_noise, img_box_smooth;
  2.   medianBlur(img, img_noise, 3);
  3.   blur(img, img_box_smooth, Size(3,3));

Remove Light

  1.   // Load image to process
  2.   Mat light_pattern= imread(light_pattern_file, 0);
  3.   if(light_pattern.data==NULL){
  4.     // Calculate light pattern
  5.     light_pattern= calculateLightPattern(img_noise);
  6.   }
  7.   medianBlur(light_pattern, light_pattern, 3);
  8.  
  9.   //Apply the light pattern
  10.   Mat img_no_light;
  11.   img_noise.copyTo(img_no_light);	
  12.   if(method_light!=2){
  13.   	img_no_light= removeLight(img_noise, light_pattern, method_light);	
  14.   }

Binarize

  1.   // Binarize image for segment
  2.   Mat img_thr;
  3.   if(method_light!=2){
  4.   	threshold(img_no_light, img_thr, 30, 255, THRESH_BINARY);
  5.   }else{
  6.   	threshold(img_no_light, img_thr, 140, 255, THRESH_BINARY_INV);
  7.   }

Leave a Reply

Your email address will not be published. Required fields are marked *