Skip to content Skip to sidebar Skip to footer

Why Does Matplotlib Imshow() And Show() Functions Show Images In A Different Color Scheme Depending On Whether They're Read In As Uint8 Or In64?

Depending on how I read in the image (option 1 or option 2), the images are shown differently when printed. Why is that? Option 1 image = np.array(plt.imread('fixed_image.jpg'), dt

Solution 1:

I think the imshow documentation is pretty clear on that:

X : array_like, shape (n, m) or (n, m, 3) or (n, m, 4) Display the image in X to current axes. X may be an array or a PIL image. If X is an array, it can have the following shapes and types:

  • MxN – values to be mapped (float or int)
  • MxNx3 – RGB (float or uint8)
  • MxNx4 – RGBA (float or uint8)

The value for each component of MxNx3 and MxNx4 float arrays should be in the range 0.0 to 1.0.

This means you may provide a float array of values between 0. and 1., or an unsigned integer array of values between 0 and 255.

What happens if you use 'int64' is not documented. Therefore just anything could happen, ranging from an error over an undesired image to the expected output.

In order to explain your actual outcome, one would need to know the operating system, the python version, the bit depth of the OS and of python, the numpy and matplotlib versions you use. Possibly also the actual image you read in.

Post a Comment for "Why Does Matplotlib Imshow() And Show() Functions Show Images In A Different Color Scheme Depending On Whether They're Read In As Uint8 Or In64?"