need help in contrast stretching
<p>i have found this formula and its description on a site</p>

<pre><code>l(x,y)=(l(x,y)-min)(no of intensity levels/(max-min)) + initial intensity level
</code></pre>

<p>where, I( x,y ) represents the images, on the left side it represents the output image, while on the right side it represents the xth pixel in the yth column in the input image. In this equation the "min" and "max" are the minimum intensity value and the minimum intensity value in the current image. Here "no. of intensity levels" shows the total number of intensity values that can be assigned to a pixel. For example, normally in the gray-level images, the lowest possible intensity is 0, and the highest intensity value is 255. Thus "no. of intensity levels" is equal to 255.</p>

<p>i have converted it into code, have i correctly converted it?</p>

<pre><code>for(int y = 0; y &lt; bmp.bmHeight; y++)   
  {      
      for(int x = 0; x &lt; bmp.bmWidth; x++)     
      {         
          COLORREF rgb = dc.GetPixel(x, y);     
          BYTE r = GetRValue(rgb);       
          BYTE g = GetGValue(rgb);     
          BYTE b = GetBValue(rgb);     
          BYTE p,p1;
          if(r&lt;g)
          {
              p=r;
              p1=g;
          }
          else
          {
              p=g;
              p1=r;
          }
          if(b&lt;p)
              p=b;
          if(b&gt;p1)
              p1=b;
          BYTE bw = (RGB(r, g, b)-p);
          bw=bw*(255/(p1-p));
          bw+=p1;
          dc.SetPixel(x, y, RGB(bw, bw, bw));      
      }   
</code></pre>
