Why gray to BGR conversion giving distorted results
I used cvtColor for converting int16 2D numpy array into BGR color image. But when view it via imshow() it giving distorted picture. Here is the code snippet i made conversion.
import cv2 as cv
color_image = cv.cvtColor(np.float32(ct_scan), cv.COLOR_GRAY2BGR)
plt.imshow(color_image)
plt.show()
plt.imshow(np.float32(ct_scan),cmap=plt.cm.gray)
plt.show()
The source image, ct_scan is a int16 2D numpy array. The conversion of ct_scan into float32 was done to compatible with the cvtColor function. The results are showing in figure 1-The converted color image and figure 2-source image converted to float32 dtype
But as you can see the converted image is distorted. Can you please help to identify the error behind, or suggest a method to convert the 2D numpy array to a color image.
First image Second image
note, that your image is still in the 16bit range, while matplotlib probably expects something in [0..1] for float images. try to divide by 0xffff before that
Thanks berak