Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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.

image description First image image description Second image