Error using cv2.equalizeHist

I am trying to align a histogram of a gray level image with the following code:

import cv2 im = cv2.imread("myimage.png") eq = cv2.equalizeHist(im) 

The following exception is thrown:

 error: (-215) CV_ARE_SIZES_EQ(src, dst) && CV_ARE_TYPES_EQ(src, dst) && CV_MAT_TYPE(src->type) == CV_8UC1 in function cvEqualizeHist 

Opencv version 2.4.2

Any guesses?

+8
python image image-processing opencv histogram
source share
1 answer

cv2.equalizeHist only works with grayscale images (1 channel). or:

 im = cv2.imread("myimage.png", 0) # load as grayscale 

or

 im = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY) # or convert 
+17
source share

All Articles