Image Processing: Contrast Enhancement 2

This programming example extents the Contrast Enhancement 1 example by showing how to control the parameters for the contrast enhancement programmatically.
Language:Visual Basic 6
Version:3.0.3
Released on:August 20, 2006
Author:IC Imaging Control Support Department
Requirements:IC Imaging Control >2.1
Camera, converter or grabber with WDM Stream Class drivers.

It shows how to manipulate the parameters for the contrast enhancement directly in your program instead of using the built-in dialog of the filter that provides the contrast enhancement functionality.

The sample application's window looks as follows:

The Testdialog of IC Imaging Control,

The filter applies a histogram stretching function to the image. That means that the pixel values between a min and max value are mapped to the entire value range of the image. The pixel values that are below the min value are set to 0. The pixel values that are above the max value are set to 255. The min and max value can be manipulated with 2 scrollbars (sldLowerBound and sldUpperBound). The beginning of the program is extended by 2 function calls that initialize the controls on the main form.

InitControls
UpdateControls

The function InitControls initializes the min and max values of the scrollbars.

Private Sub InitControls()
    sldLowerBound.Min = 0
    sldLowerBound.Max = 255
    sldUpperBound.Min = 0
    sldUpperBound.Max = 255
End Sub

The function UpdateControls assigns the filter parameters "Enable", "Lower Bound" and "Upper Bound" to the checkbox cbEnable and the scrollbars sldLowerBound and sldUpperBound.

Private Sub UpdateControls()
    If filter.Parameter("Enable") Then
        cbEnable.Value = Checked
    Else
        cbEnable.Value = Unchecked
    End If
    sldLowerBound.Value = filter.Parameter("Lower Bound")
    txLowerBound.Text = sldLowerBound.Value
    sldUpperBound.Value = filter.Parameter("Upper Bound")
    txUpperBound.Text = sldUpperBound.Value
End Sub

The event handler for the scrollbar sldLowerBound ensures that its value is equal or less to the value of the scrollbar sldUpperBound . After this check, the scrollbar value is assigned to the filter parameter "Lower Bound" and the text field to the right of the scrollbar is updated. The event handler for the scrollbar sldUpperBound works accordingly.

Private Sub sldLowerBound_Scroll()
    If sldLowerBound.Value >= sldUpperBound.Value Then
        sldLowerBound.Value = sldUpperBound.Value - 1
    End If
    filter.Parameter("Lower Bound") = sldLowerBound.Value
    txLowerBound.Text = sldLowerBound.Value
End Sub

Related Source Code Samples

Disclaimer
The source code that appears in the IC Imaging Control Source Code Library is indented for educational purposes only. The Imaging Source Europe GmbH, the manufacturer of IC Imaging Control, does not assume any kind of warranty expressed or implied, resulting from the use of the content of this page.

This site is part of The Imaging Source Network. Other sites include Company Portal, Image Processing, Astronomy Cameras, Astronomy Cameras Blog, Blog caméras d'astronomie, Astronomy Cameras Competition, TX Text Control, LiveDocx, phpLiveDocx and Forums.