title: applying window level functionality on CT images in DIOCM
body: <p>I am trying to implement window level functionality( To apply bone, brain, lung etc on CT) for DICOM images in my application and implemented formula as per the DICOM specification.
  I am changing pixel values based on below formula and creating a new image, but images are becoming blank. What am doing wrong and is this correct way to do this. Please help :(:( Thanks</p>
  
  <pre><code>BufferedImage image = input image;
  
  double w = 2500; // Window width
  double c = 500; // window Center
  double ymin = 0;
  double ymax = 255;
  double x = 0;
  double y = 0;
  double slope = dicomObject.get(Tag.RescaleSlope).getFloat(true);
  double intercept = dicomObject.get(Tag.RescaleIntercept).getFloat(true);
  
  int width = image.getWidth();
  int height = image.getHeight();
  
  double val = c - 0.5 - (w - 1) / 2;
  
  double val2 = c - 0.5 + (w - 1) / 2;
  
  for (int m = 0; m &lt; height; m++) {
  
      for (int n = 0; n &lt; width; n++) {
  
          int rgb = image.getRGB(n, m);
  
          int valrgb = image.getRGB(n, m);
          int a = (0xff000000 &amp; valrgb) &gt;&gt;&gt; 24;
          int r = (0x00ff0000 &amp; valrgb) &gt;&gt; 16;
          int g = (0x0000ff00 &amp; valrgb) &gt;&gt; 8;
          int b = (0x000000ff &amp; valrgb);
  
          x = a + r + g + b;
  
          if (x &lt;= val)
              y = ymin;
  
          else if (x &gt; val2)
              y = ymax;
  
          else {
              y = ((x - (c - 0.5)) / (w - 1) + 0.5) * (ymax - ymin)+ ymin;
          }
          y = y * slope + intercept;
          rgb = (int) y;
          image.setRGB(n, m, rgb);
  
      }
  }
  String filePath = "out put fileName";
  ImageIO.write(image, "jpeg", new File(filePath));
  </code></pre>