Mark Underexposed and Overexposed Pixels - Part 2

This snippet extents the first part, by showing how to programmatically control the parameters that visualize underexposed and overexposed pixels.

Language:.NET C#/Visual Basic
Version:3.3
Released:20060820

Author:IC Imaging Control Support Department

Requirements:
Software:IC Imaging Control 3.3, Visual Studio™ 2010
Hardware:Camera, converter or grabber with WDM Stream Class drivers.
Download C# sampleMark Pixels2 - C#
Download VB7 sampleMark Pixels2 - VB7
Download Clipping Frame Filter C++ projectClipping Frame Filter - C++

The window of the resulting application looks as follows:

The Testdialog of IC Imaging Control,

This sample application illustrates how to manipulate the parameters for the visualization of underexposed and overexposed pixels directly from program code - as opposed to using the built-in dialog that provides the visualization functionality.

The frame filter's VC++ .NET project can also be downloaded from the top of this page. Please note that the frame filter's source code is not required in order to run and understand the following programming example.

First of all a variable filter of type TIS.Imaging.FrameFilter must be declared in the class Form1. This variable will contain the frame filter and is used to communicate with it.

C#
      
private TIS.Imaging.FrameFilter filter;

        
VB.NET
      
Private filter As TIS.Imaging.FrameFilter

        

The filter provides the following parameters: the threshold ("Threshold"), a parameter indicating whether pixels are marked that are brighter or darker than the threshold ("ClipAboveThreshold"); and the color and pattern that is used to mark the pixels ("FillMode" and "FillColor").

The threshold can be manipulated with the scrollbar sldThreshold. Whether pixels are marked that are brighter or darker than the threshold is controlled by the 2 radio buttons rbClipAbove and rbClipBelow. The beginning of the program is extended by 2 function calls that initialize the controls on the main form.

C#
      
InitControls();
UpdateControls();

        
VB.NET
      
InitControls()
UpdateControls()

        

The function InitControls initializes the minimum and maximum value of the scrollbar sldThreshold.

C#
      
private void InitControls()
{
    sldThreshold.Minimum = 0;
    sldThreshold.Maximum = 255;
}

        
VB.NET
      
Private Sub InitControls()
    sldThreshold.Minimum = 0
    sldThreshold.Maximum = 255
End Sub

        

The function UpdateControls assigns the filter parameters "Enable", "Threshold" and "ClipAboveThreshold" to the checkbox cbEnable, the scrollbar sldThreshold and the radio buttons rbClipAbove and rbClipBelow.

C#
      
private void UpdateControls()
{

    filter.BeginParameterTransfer();

    // Update the "Enable" checkbox.
    cbEnable.Checked = filter.GetBoolParameter("Enable");

    // Update the radio buttons.
    bool state = filter.GetBoolParameter("ClipAboveThreshold");
    rbClipAbove.Checked = state;
    rbClipBelow.Checked = !state;

    // Update the slider.
    sldThreshold.Value = filter.GetIntParameter("Threshold");
    txThreshold.Text = sldThreshold.Value.ToString();

    filter.EndParameterTransfer();

}

        
VB.NET
      
Private Sub UpdateControls()

    filter.BeginParameterTransfer()

    ' Update the "Enable" checkbox.
    cbEnable.Checked = filter.GetBoolParameter("Enable")

    ' Update the radio buttons.
    Dim state As Boolean = filter.GetBoolParameter("ClipAboveThreshold")
    rbClipAbove.Checked = state
    rbClipBelow.Checked = Not state

    ' Update the slider.
    sldThreshold.Value = filter.GetIntParameter("Threshold")
    txThreshold.Text = sldThreshold.Value

    filter.EndParameterTransfer()
End Sub

        

The event handler for the scrollbar sldThreshold assigns its current value to the filter parameter "Threshold" and updates the text field txThreshol with this value.

C#
      
private void sldThreshold_Scroll(object sender, System.EventArgs e)
{
    filter.BeginParameterTransfer();
    filter.SetIntParameter("Threshold", sldThreshold.Value);
    filter.EndParameterTransfer();
    txThreshold.Text = sldThreshold.Value.ToString();
}

        
VB.NET
      
Private Sub sldThreshold_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles sldThreshold.Scroll
    filter.BeginParameterTransfer()
    filter.SetIntParameter("Threshold", sldThreshold.Value)
    filter.EndParameterTransfer()
    txThreshold.Text = sldThreshold.Value
End Sub

        

The event handler for the radio button rbClipAbove assigns True to the filter parameter "ClipAboveThreshold" and unchecks the radio button rbClipBelow. The event handler for the radio button rbClipBelow works similarly.

C#
      
private void rbClipAbove_CheckedChanged(object sender, System.EventArgs e)
{
    filter.BeginParameterTransfer();
    filter.SetBoolParameter("ClipAboveThreshold", true);
    filter.EndParameterTransfer();
    rbClipBelow.Checked = false;
}

private void rbClipBelow_CheckedChanged(object sender, System.EventArgs e)
{
    filter.BeginParameterTransfer();
    filter.SetBoolParameter("ClipAboveThreshold", false);
    filter.EndParameterTransfer();
    rbClipAbove.Checked = false;
}

        
VB.NET
      
Private Sub rbClipBelow_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbClipBelow.CheckedChanged
    filter.BeginParameterTransfer()
    filter.SetBoolParameter("ClipAboveThreshold", False)
    filter.EndParameterTransfer()
    rbClipAbove.Checked = False
End Sub

Private Sub rbClipAbove_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbClipAbove.CheckedChanged
    filter.BeginParameterTransfer()
    filter.SetBoolParameter("ClipAboveThreshold", True)
    filter.EndParameterTransfer()
    rbClipBelow.Checked = False
End Sub