BLOG.CSHARPHELPER.COM: Use a scroll bar to change the cutoff value for binary contrast enhancement in C#
Use a scroll bar to change the cutoff value for binary contrast enhancement in C#
The example Perform binary contrast enhancement on an image in C# performs binary contrast enhancement by setting each pixel to black or white depending on whether the sum of its red, green, and blue component values is greater than 3 * 128 = 384. For images that are particularly dark or light, however, the result may be too dark or too light.
This example lets you use a scroll bar to determine what cutoff value to use in performing the adjustment. In the picture, the cutoff value was fairly high so many of the mid-shade pixels in the original image were changed to black.
Whenever the program loads a new image or the user adjusts the scroll bar, the code calls the following PerformEnhancement method.
The code creates a new Bitmap that is a copy of the original image. It then calls the BinaryContrast method (see the earlier post for a description about that method) to perform the binary contrast enhancement, passing it the value selected by the scroll bar. It then displays the result.
Comments