Floating point values representing images

When I’m normalizing images I use the ToTensor() function which squeezes all the values between 0 and 1.
In the image you can see I want to see some images in the batch so I unnoramlized it but didn’t undo my ToTensor() function, yet it’s showing images just fine.
My point is that the pixels are not integers anymore and are actually decimal values between 0 and 1, how are they still be able to display images?

Matplotlib expects uint8 images or float values between 0 or 1.

okay but we know that pixels are represented in terms of integer values of [0,256), what happens inside matplotlib? Does it convert them back from decimal values to to a range of 0 to 256?

I’m afraid I don’t know the source code of matplotlib as it’s a super complex library.
I neither think it’s relevant at all. Matplotlib’s main purpose is creating graphics, and your eye cannot really distinguish the difference between values of 255 and 253 (for example).

Anyway, if it’s really important to you, I think you can ask in a more specialized forum such us Stack Overflow or Superuser.

fair enough, thank you.

I think @JuanFMontesinos is correct and matplotlib would rescale the image to the standard uint8 format before clipping invalid values. You could check the source code (e.g. with a debugger) and should see some calls into e.g. this transformation and this clipping.

1 Like