title: Image Normalization in Java
body: <p>I have been working on finger image processing and I am currently want to do Normalization.</p>
  
  <p>I have studied this link on <a href="http://www.griaulebiometrics.com/en-us/book/understanding-biometrics/types/enhancement/normalization" rel="nofollow">Griuale Biometric website</a>.</p>
  
  <p>The idea of normalization consist in changing the intensity of each pixel so that mean and variance of the whole image are changed to some predefined values.</p>
  
  <p>Could any suggest me any example code or algorithm in java that can help me.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I am taking image pixel's <code>MEAN</code> and <code>VARIANCE</code> into account for the image normalization:</p>
  
  <p>Here is my code:</p>
  
  <pre><code>public class NormalizeHistMeanVariance {
  private static BufferedImage original, normalize;
  
  public static void main(String[] args) throws IOException {
      final int N = 256; // Number of graylevels
      final int M = 250; // Max value in histogram for displaying purposes
      int nrows, ncols, size, in_img[][], out_img[][];
      int i, j, max, maxgray;
      double hist[] = new double[N], norm, mean, var, tmp;
  
      String f1 = "E:/single.jpg";
      String f2 = "E:/normImg";
      File original_f = new File(f1);
      original = ImageIO.read(original_f);
  
      Histogram histogram = new Histogram(original);
      in_img = histogram.getPixels(original);
  
      nrows = in_img.length;
      ncols = in_img[0].length;
      size = in_img.length * in_img[0].length;
  
      // Compute average gray and histogram
      for (i = 0; i &lt; N; i++)
          hist[i] = 0;
      mean = 0;
      for (i = 0; i &lt; nrows; i++) {
          for (j = 0; j &lt; ncols; j++) {
              hist[in_img[i][j]]++;
              mean += in_img[i][j];
          }
      }
      mean /= size;
      System.out.println("Mean graylevel = " + mean);
  
      // Compute variance
      var = 0;
      for (i = 0; i &lt; nrows; i++) {
          for (j = 0; j &lt; ncols; j++) {
              tmp = in_img[i][j] - mean;
              var += tmp * tmp;
          }
      }
      var = Math.sqrt(var / (size));
      System.out.println("Variance = " + var);
  
      max = maxgray = 0;
      for (i = 0; i &lt; N; i++) {
          if (max &lt; hist[i]) {
              max = (int) hist[i];
              maxgray = i;
          }
      }
      System.out.println("Max count " + max + " (graylevel = " + maxgray
              + " )");
  
      // Normalize to M for better display effect
      norm = (double) M / maxgray;
      System.out.println("Norm = " + norm);
  
      out_img = new int[nrows][ncols];
      for (int x = 0; x &lt; in_img.length; x++) {
          for (int y = 0; y &lt; in_img[0].length; y++) {
              out_img[x][y] = (int) (in_img[x][y] * norm);
          }
      }
      normalize = ImageUtils.CreateImagefromIntArray(out_img);
  
      writeImage(f2);
  }
  
  private static void writeImage(String output) throws IOException {
      File file = new File(output + ".jpg");
      ImageIO.write(normalize, "jpg", file);
  }
  }
  </code></pre>
  
  <p>What i want is smooth image after normalization like in this <a href="http://www.griaulebiometrics.com/en-us/book/understanding-biometrics/types/enhancement/normalization" rel="nofollow">link</a>. But I am not getting desired result. Could anyone help me?</p>