title: ImageMagick - Set levels for grayscaled image
body: <p>I write program in C# but hope that C++ and C# in background exactly same.
  What i want - take grayscaled image  and separate colors over 127 and under 17 to separate images. If i simply get "white" colors and programmatically stretch them from range (127-255) to (0-255) like</p>
  
  <pre><code>// pseudocode
  int min = 127, max = 255;
  for(int x; x&lt; width; x++)
      pixels[x] = pixels[x]/(max-min) * max;
  </code></pre>
  
  <p>Then here will be not smooth interval.. I mean, that 127 converts to 0 but 128 converts to 2 and colors 1,3,5,... are not exist.</p>
  
  <p>That is original image with alpha:<a href="http://snorgg.ru/patchwork/tst_orig.png" rel="nofollow">image original</a></p>
  
  <p>That is image with "extracted white":<a href="http://snorgg.ru/patchwork/tst_white.png" rel="nofollow">image original</a></p>
  
  <p>That is image with "extracted black": snorgg.ru/patchwork/tst_black.png.</p>
  
  <p>I don't clearly understand how it can be realized so exampe code will like:</p>
  
  <pre><code>{
     im.MagickImage image = new im.MagickImage("c:/55/11.png");
     im.MagickImage imageWhite = ExtractWhite(image);
     im.MagickImage imageBlack = ExtractBlack(image);
  }
  
  ....  
  
  public static im.MagickImage ExtractWhite(im.MagickImage  img){
  
     im.MagickImage result = new im.MagickImage(img);
  
     ?????
     ?????
  
     return result;
  }
  </code></pre>
  
  <p>thankы in advance ))</p>