title: image Normalization, image Range and image Scaling for different stack of images
body: <p>I am so confused with image Normalization, and image Range, and image Scaling.
  I am using an algorithm (I have upload the algorithm in my <a href="https://stackoverflow.com/questions/10863734/image-processing-algorithm-in-matlab/">Previous Question</a>), and after applying the algorithm I am using this formula from <a href="http://en.wikipedia.org/wiki/Normalization_%28image_processing%29" rel="nofollow noreferrer">wikipedia</a> to normalize the images:</p>
  
  <p><img src="https://i.stack.imgur.com/k032N.png" alt="enter image description here"></p>
  
  <p>using <code>getrangefromclass(filtImag1{i})</code> from MATLAB, the range of matrices before applying the algorithm is [0 255] and after applying the algorithm the range is [0 1].</p>
  
  <p>the problem is I need to find a reference to find out if the normalization formula is correct or not? also I have 5 stacks of images each containing 600 images. I have applied the algorithm for each stack, and because the result of algorithm is 10 images for each stack, I will end up with 50 images that I need to analysis and compare them together. I find the max and the min of the 50 images , and then pass each image into the formula to normalize the image. </p>
  
  <p>although the range of the images is [0 1] but the max of the image is :
  max =  3.6714e+004</p>
  
  <p>why? shouldn't it be 1?
  is this the right way of normalization?
  how can I apply scaling ? do I need to do it?</p>
  
  <p>here is the normalization code :</p>
  
  <pre><code>%%%%%%%%%%%%%%Find Min and Max between the results%%%%%%%%%%%%%%%%%%%%%%% 
  pre_max = max(filtImag1{1}(:));
  for i=1:10
     new_max = max(filtImag1{i}(:));
      if (pre_max&lt;new_max)
          pre_max=max(filtImag1{i}(:));
      end
  end
  new_max = pre_max;
  
  pre_min = min(filtImag1{1}(:));
  for i=1:10
     new_min = min(filtImag1{i}(:));
      if (pre_min&gt;new_min)
          pre_min = min(filtImag1{i}(:));
      end
  end
  new_min = pre_min;
  
  %%%%%%%%%%%%%%normalization %%%%%%%%%%%%%%%%%%%%%%%
   for i=1:10
   temp_imag = filtImag1{i}(:,:);
   x=isnan(temp_imag);
   temp_imag(x)=0;
   t_max = max(max(temp_imag));
   t_min = min(min(temp_imag));
   temp_imag = (double(temp_imag-t_min)).*((double(new_max)-double(new_min))/double(t_max-t_min))+(double(new_min));
   imag_test2{i}(:,:) = temp_imag;
   end
  </code></pre>
  
  <p><strong>EDIT</strong>
  I have change the code based on suggested answers but the result is black image </p>
  
  <p>%find the max and min between them
  pre_max = max(sTStack{1}(:));
  for i=1:40
     newMax = max(sTStack{i}(:));
      if (pre_max
  
  <p>pre_min = min(sTStack{1}(:));
  for i=1:40
     newMin = min(sTStack{i}(:));
      if (pre_min>newMin)
          pre_min = min(sTStack{i}(:));
      end
  end
  t_min = pre_min;</p>
  
  <p>%%%%%%%%%%%%%%%%%%%%%%% Normalize the Image:%%%%%%%%%%%%%%%%%%%%%%%%%%%%</p>
  
  <p>for i=1:40
  NTstack{i} = (sTStack{i} - t_min)/(t_max-t_min);
  end</p>
  
  <p>for i=10:10:40
      figure,imshow(NTstack{i});
      colorbar
      colormap jet
  end</p>