title: OpenCV preprocess image for better thresholding results
body: <p>In OpenCV, how can I preprocess images for better thresholding results? My input image is </p>
  
  <p><a href="https://i.stack.imgur.com/5qJnB.png" rel="nofollow">base image</a></p>
  
  <p>I am using a variety of thresholding methods like:</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Applying <code>CLAHE (Contrast Limited Adaptive Histogram Equalization)</code> significantly decreases the amount of noise but the text extracted is still kind of blurry. Is there a way I can make the text more "crisp"?</p>
  
  <pre><code>clahe = cv2.createCLAHE(clipLimit=1.0, tileGridSize=(3,3))
  inputImage = clahe.apply(inputImage)
  </code></pre>
  
  <p><strong>END OF EDIT</strong></p>
  
  <pre><code>invertRet, invertColors = cv2.threshold(inputImage,127,255,cv2.THRESH_BINARY_INV)
  
  gaussianThreshold = cv2.adaptiveThreshold(inputImage, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY_INV, 11, 2)
  
  adaptiveMean = cv2.adaptiveThreshold(inputImage, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY_INV, 11, 2)
  
  otsuRet, otsu = cv2.threshold(inputImage,0,255,cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)
  </code></pre>
  
  <p>but they all display lots of noise like:</p>
  
  <p><a href="https://i.stack.imgur.com/uIDQW.png" rel="nofollow">gaussian thresholding</a></p>