Atinesh
Atinesh

Reputation: 1910

Trouble using OpenCV Histogram Equalisation

I am trying to use Contrast Limited Adaptive Histogram Equalisation (CLAHE) in OpenCV, But getting below error

Error enter image description here

Code

import cv2 as cv
from matplotlib import pyplot as plt

imgG = cv.imread('sample.png')

clahe = cv.createCLAHE(clipLimit=2.0, tileGridSize=(8,8))
imgC  = clahe.apply(imgG)

fig = plt.figure(figsize = (20,20))
ax  = fig.add_subplot(111)
ax.imshow(imgC, cmap='gray')
plt.show()

Any guess why its happening

Upvotes: 1

Views: 91

Answers (1)

ZdaR
ZdaR

Reputation: 22954

The error tells that: (-215) _src.type() == CV_8UC1 || _src.type() == 16UC1, which basically means that the input mat to clahe.apply() can be a single channel 8-bit matrix or a single channel 16-bit matrix. The 1 in 8UC1 signifies the number of channels expected in the input matrix, since you are reading image as cv.imread('sample.png'), so by default it reads 3 channel BGR image. You can either use cv.imread('sample.png', 0) or use img = cv.cvtColor(img, cv.COLOR_BGR2GRAY) after reading the image.

Upvotes: 1

Related Questions