error: (-215) _src.type() == CV_8UC1 in function equalizeHist when trying to equalize a float64 image
<p>I'm trying to equalize a 1 one channel image like so:</p>

<pre><code>img = cv2.equalizeHist(img)
</code></pre>

<p>But since it's a float64 img, I get the following error:</p>

<blockquote>
  <p>error: (-215) _src.type() == CV_8UC1 in function equalizeHist</p>
</blockquote>

<p>How do I go about this?</p>

<p>The function equalizeHist is histogram equalization of images and only implemented for CV_8UC1 type, which is a single channel 8 bit unsigned integral type.</p>

<p>To convert your image to this type you can use the function <code>convertTo</code> with the target type (must be the same number of channels).</p>

<p>Make sure that the source image has the right value range, typically floating point images are interpret as 0 = black and 1 = white and the gray range is in between, while integral images are interpreted as 0 = black and maximum value = white (which would be 255 for unsigned 8 bit type). So you'll often have to multiply your source image by 255 to fit the range. Function <code>convertTo</code> has a parameter to scale your values during conversion, which could give you a speed improvement compared to manual scaling.</p>

python opencv numpy