Reputation: 302
I can't get a grayscale image in RGB, here's my code:
img=cv2.imread("clahe_2.jpg")
backtorgb = cv2.cvtColor(img,cv2.COLOR_GRAY2RGB)
showImg(backtorgb,"claheCLR")
This error returns:
backtorgb = cv2.cvtColor(img,cv2.COLOR_GRAY2RGB)
cv2.error: /build/opencv-L2vuMj/opencv-3.2.0+dfsg/modules/imgproc/src/color.cpp:9765: error: (-215) scn == 1 && (dcn == 3 || dcn == 4) in function cvtColor
Filepath is correct. Any suggest?
Upvotes: 1
Views: 3701
Reputation: 302
The problem was on the application of the CLAHE filter and its grayscale output, actually the output kept the 3 channels but at the sight it looked like a grayscale, documentation here.
I simply found here a method that kept the RGB form to solve the problem, thanks to everyone for the answers.
Upvotes: 0
Reputation: 436
By default, imread
opens the image as a 3-channel BGR image so you don't need to convert it, maybe just to RGB if that's what you're looking for.
Check out the documentation here
Upvotes: 0
Reputation: 1804
I think tat problem is that your image is not real grayscale. It is RGB, but visible as grayscale. So need to bring one channel from image and then run the code:
backtorgb = cv2.cvtColor(img[..., 0], cv2.COLOR_GRAY2RGB)
Upvotes: 1