# Rescaling each image Individually with keras

I am a beginner working on a simple CNN to classify X-ray detector images. Due to source intensity, all images have different max values. I want to use ImageDataGenerator to rescale those images to be in range [0,1], but cant't find a way to do that for each individual image. As far as I understand it, people usually just divide by 255 because that is the RGB max, but in my case the max could be anything between 1 and serveral million. Does anyone have an idea how to do this within ImageDataGenerator? Thank you for your time!

Edit: I ran over my images and normalized all of them prior to feeding them to the generator. Inspecting them then showed that the generator had scaled them back to rgb values (I assume due to color_mode). I then used rescale with the standard 1./255 and got the expectd max value of 1. However, after adding back samplewise_std_normalization, I again am getting values larger than 1. I understand why this is happening, but I'm not sure which "rule" is more important to follow: normalize to [0,1] or use samplewise_std_normalization

• First, have you make sure that every image possess similar characteristic as you mentioned? Second, do lookout what the max value might means and if possible find out the theoretical max value(e.g. 255 for normal image). If you still cant find out just calculate all channelwise max before proceeding. – Yohanes Alfredo Dec 29 '19 at 3:00
• You could always write your own custom data generator in which you can preprocess and augment the different individual images as you like. – Oxbowerce Dec 29 '19 at 12:29
• Thank you both. I have ammended my question – Djaik Navidson Dec 29 '19 at 14:38

Normalize to $$[0, 1]$$ is what I'd do to ensure that the model gets expected (sanitized) inputs.