I want to create an algorithm that can take a dataset and check how each image is represented and change the scale to 0-255 or 0-1 automatically. I know how this is done manually if I know how my full dataset is represented. Lets say my dataset is 16 bit I can convert it to 8 bit by:
img = (img/256).astype('uint8')
Or convert it between 0-1 by:
img = (img/65536)
However, lets say I have a dataset that is 8 bit represented (I dont know this yet) and I loop through each image individually it may happen that some of my images max is 240,250 and 251. Then if I want to rescale to 0-1 it will not be correct:
img = img/240 # first image
img = img/250 # second image
img = img/251 # third image
I could also check for the maximum value of the full dataset and then get the correct max value. But is there a way to rescale "correctly" even if the max value for the individual image is 240?