Q: How to normalize the image to [0,1] when using MATLAB to train a CNN? I'm a newer on machine learning and now trying to train a CNN on MNIST.
I have 60k png training set of MNIST, but the Layer class, the imageinputlayer(), it can only zero-center the image, and can't normalize it.
what should I do to scale the image input to 0¬1?
What I mean is: I want deploy a image normalization Layer on the Class Layer when using function trainNetwork() to train a CNN.
in the document of MATLAB: https://cn.mathworks.com/help/nnet/examples/create-simple-deep-learning-network-for-classification.html
There is a demo code
    digitDatasetPath = fullfile(matlabroot,'toolbox','nnet','nndemos', ...
        'nndatasets','DigitDataset');
    digitData = imageDatastore(digitDatasetPath, ...
            'IncludeSubfolders',true,'LabelSource','foldernames');
[trainDigitData,testDigitData] = splitEachLabel(digitData, ...
                trainingNumFiles,'randomize');
layers = [imageInputLayer([28 28 1])
          convolution2dLayer(5,20)
          reluLayer
          maxPooling2dLayer(2,'Stride',2)
          fullyConnectedLayer(10)
          softmaxLayer
          classificationLayer()];
options = trainingOptions('sgdm','MaxEpochs',15, ...
    'InitialLearnRate',0.0001);
convnet = trainNetwork(trainDigitData,layers,options);

as we all know, the png image data is int type from 0 to 255.
but in the same time, the input of a cnn deep learning need to be normalized to [0-1]
the normalization options on the class imageInputLayer(), is zero center (data/mean of data)only, don't have a scale normalization options(data/255).
so how could I add a normalization Layer to the Layer structure?
or there is no need to do a normalization for the training set?

A: Maybe you mean this? This is how I preprocessing the imdb data and it works for my images. The data is stored as (dim1, dim2, sample_size) form
   imdb.images.data = (imdb.images.data-min(imdb.images.data(:)))/(max(imdb.images.data(:)-min(imdb.images.data(:))));
   imageMean = mean(imdb.images.data,3); 
   for j= 1:size(imdb.images.data,3)
        imdb.images.data(:,:,j) = imdb.images.data(:,:,j) - imageMean ;
   end

