In the image.py sources in the AxesImage class (which imshow returns), the _get_unsampled_image method is called at some point in the drawing process. The corresponding code starts at line 226 for me (matplotlib-1.5.3):
if A.dtype == np.uint8 and A.ndim == 3: im = _image.frombyte(A[yslice, xslice, :], 0) im.is_grayscale = False else: if self._rgbacache is None: x = self.to_rgba(A, bytes=False)
Thus, the type and size of input A are checked:
if A.dtype == np.uint8 and A.ndim == 3:
and in this case, pre-processing is not performed. Otherwise, without checking the input range, you end up having multiplication by 255 and listing on uint8 :
x = (x * 255).astype(np.uint8)
And we know what to expect if x is from 0 to 255 instead of 0 to 1:
In [1]: np.uint8(np.array([1,2,128,254,255])*255) Out[1]: array([255, 254, 128, 2, 1], dtype=uint8)
So the light becomes dark. That this inverts the image is probably not the intended behavior, as I think you are assuming.
You can compare the _rgbacache values ββin the object returned from imshow for each of your input cases to observe the result, for example. im._rbacache where im = plt.imshow(np.float64(img)) .