Gray Scale Colorspace Conversion Incompatible with OpenCV grayscale images
Hello,
While testing simplejpeg grayscale conversion with OpenCV grayscale image, I ran into the following issue:
>>> import simplejpeg
>>> import cv2
>>> x = cv2.imread("foo.jpg") #3-channel image
>>> x2 = cv2.cvtColor(x2, cv2.COLOR_BGR2GRAY) #Converted to 1-channel grayscale image
>>> img = simplejpeg.encode_jpeg(x, colorspace="GRAY")
Throws following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "simplejpeg/_jpeg.pyx", line 410, in simplejpeg._jpeg.encode_jpeg
ValueError: Buffer has wrong number of dimensions (expected 3, got 2)
But when i checked dimension:
>>> x2.shape
(843, 1500)
This is incompatible but if i add one more dummy dimension, as done #4 (closed):
>>> import numpy as np
>>> x3 = x2[:, :, np.newaxis] #add new dummy dimension
>>> x3.shape
(843, 1500, 1)
It works normally without any error:
>>> import simplejpeg
>>> import cv2
>>> import numpy as np
>>> x = cv2.imread("foo.jpg") #3-channel image
>>> x2 = cv2.cvtColor(x2, cv2.COLOR_BGR2GRAY) #Converted to 1-channel grayscale image
>>> x3 = x2[:, :, np.newaxis] #add new dummy dimension
>>> img = simplejpeg.encode_jpeg(x, colorspace="GRAY")
Therefore, only (843, 1500, 1)
dimension works and not the OpenCV supported grayscale image dimension (843, 1500)
. Please fix this. Thanks!