If anyone else stumbled across this but is already using grayscale ($M \times N$) ndarrays... There can be another problem.
When you use cv2.imread()
it reads in the image as a numpy ndarray using dtype=np.uint8
. However, when I use any other method it can be stored as a dtype=np.uint16
which will trigger the following warning
OpenCV Error: Assertion failed (_src.type() == (((0) & ((1 << 3) - 1)) + (((1)-1) << 3))) in cv::equalizeHist, file C:\projects\opencv-python\opencv\modules\imgproc\src\histogram.cpp, line 3913
Traceback (most recent call last):
File "<input>", line 1, in <module>
cv2.error: C:\projects\opencv-python\opencv\modules\imgproc\src\histogram.cpp:3913: error: (-215) _src.type() == (((0) & ((1 << 3) - 1)) + (((1)-1) << 3)) in function cv::equalizeHist
Solution:
img_int8 = img.astype(np.uint8)
EDIT: might be doing something wrong though... because the output now gives strange results in some cases of transformation.