title: Convert opencv image format to PIL image format?
body: <p>I want to convert an image loaded</p>
  <pre><code>TestPicture = cv2.imread(&quot;flowers.jpg&quot;)
  </code></pre>
  <p>I would like to run a <a href="http://pillow.readthedocs.io/en/4.0.x/reference/ImageFilter.html" rel="noreferrer">PIL filter</a> like on the <a href="https://wellfire.co/learn/python-image-enhancements/" rel="noreferrer">example</a> with the variable</p>
  <pre><code>TestPicture
  </code></pre>
  <p>but I'm unable to convert it back and forth between these types.</p>
  <ul>
  <li><p>Is there a way to do these conversions?</p>
  </li>
  <li><p>Can OpenCV do all of the image filters that are in the PIL package?</p>
  </li>
  </ul>
  <p>Example:</p>
  <p><a href="https://i.stack.imgur.com/VDbVb.png" rel="noreferrer"><img src="https://i.stack.imgur.com/VDbVb.png" alt="enter image description here" /></a></p>
  <p>Result:</p>
  <pre><code>gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
  threshold_img = cv2.threshold(gray, 100, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]
  im_pil = cv2_to_pil(threshold_img)
  pytesseract.image_to_string(im_pil)
  Out[5]: 'TUM'
  </code></pre>