cv2.imshow and cv2.imwrite show different output from the same array[SOLVED]
I am creating an image from a numpy array which was created by a style transfer .net
output = net.forward()
The output is the renormalized from the.net processing.
output = output.reshape((3, output.shape[2], output.shape[3]))
output[0] += 103.939
output[1] += 116.779
output[2] += 123.680
output = output.transpose(1, 2, 0)
When I display this with cv2.imshow
I get the correct image
Now i try and convert this to an image file for saving and display: First I rescale the image back up to the 0 -255 integer range with:
output = (output * 255).astype(np.uint8)
Then save it with:
cv2.imwrite(path + "/" + "Test_Out" + '.jpg', output)
The latter image has color artifacts that I can't explain. (I don't have enough posts to display the images :( )
Any ideas how to properly display the numpy array??!
I'm not sure, but does the array have 4 channels? If so, try setting the last one (which may be treated as a transparency array) to a constant 255.
Check this link reshape
Of course the array is not the same if you do an operation to it after imshow...
https://docs.opencv.org/3.4/d0/d86/tu... (see top chapter there)