Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

cv2.imshow and cv2.imwrite show different output from the same array

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 image description

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??! image description

cv2.imshow and cv2.imwrite show different output from the same array

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

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)

0)

When I display this with cv2.imshow cv2.imshow I get the correct image image descriptionimage description

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)

255).astype(np.uint8)

Then save it with:

cv2.imwrite(path + "/" + "Test_Out" + '.jpg', output) 

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??! image description

cv2.imshow and cv2.imwrite show different output from the same array

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 image description

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??! image description