Contrast Enhancement - Part 1 Programming example that illustrates how to enhance the contrast of a live video stream with the IC Imaging Control Frame Filter technology.
Language: | .NET C#/Visual Basic
Version: | 3.3
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# sample | Contrast Enhancement 1 - C#
Download VB.net sample | Contrast Enhancement 1 - VB71
Download Contrast Enhancement Frame Filter C++ project | Contrast Enhancement Frame Filter - C++

This sample uses the "Contrast Enhancement" frame filter. This frame filter is contained in the sample setups that can be downloaded using the above links. The filename of the frame filter is ContrastEnhancement.FTF. The "Contrast Enhancement" spreads the histogram of all incoming frames. This kind of image processing enhances the contrast of the incoming frames. The pixel brightness values are mapped within an upper and lower bound to the entire brightness value range from 0 to 255. The upper and lower bound values are parameters of the "Contrast Enhancement" frame filter. The pixels that are darker than the lower bound are set to 0. Those that are brighter than the upper bound are set to 255. The parameter "Enable" of the "Contrast Enhancement" frame filter allows the image processing functionality to be toggled. Using the built-in dialog "Contrast Enhancement Properties" of the frame filter, the upper and lower bound parameters of this filter can be changed.

The frame filter's VC++ 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 the frame filter.

    C#

    private TIS.Imaging.FrameFilter filter;

    VB.NET

    Dim filter As TIS.Imaging.FrameFilter

When the program starts, a single call to icImagingControl1.ShowDeviceSettingsDialog shows IC Imaging Control's built-in dialog for video capture.

After a valid video capture device has been selected, the frame filter "ContrastEnhancement" is loaded with a call to IcImagingControl1.FrameFilterCreate. An exception is thrown, if an error occurs. Thus, the loading of a frame filter should be wrapped in a try..catch block.

Once the frame filter is loaded, it is inserted into the device path of IC Imaging Control and it's parameter "Enabled" is set to true. The live video stream is started with a call to icImagingControl1.LiveStart.

The complete Form1_Load source code looks as follows:

    C#

        private void Form1_Load(object sender, System.EventArgs e)
        {
            icImagingControl1.ShowDeviceSettingsDialog();
            if (!icImagingControl1.DeviceValid)
                return;

            try
            {
                filter = icImagingControl1.FrameFilterCreate("ContrastEnhancement", "");
                // Insert the frame filter in the device path of IC.
                icImagingControl1.DeviceFrameFilters.Add(filter);
                // Enable the filter
                cbEnable.Checked = true;
                // Initialize the Enable check box.
                filter.SetBoolParameter("Enable", cbEnable.Checked);
                icImagingControl1.LiveStart();
            }
            catch(Exception ex)
            {
                MessageBox.Show("Failed to load the frame filter!");
            }
        }

    VB.NET

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        IcImagingControl1.ShowDeviceSettingsDialog()
        If Not IcImagingControl1.DeviceValid Then
            'Unload(Me)
            Exit Sub
        End If

        Try
            filter = IcImagingControl1.FrameFilterCreate("ContrastEnhancement", "")
            ' Insert the frame filter in the device path of IC.
            IcImagingControl1.DeviceFrameFilters.Add(filter)
            ' Enable the filter
            cbEnable.Checked = True
            ' Initialize the Enable check box.
            filter.SetBoolParameter("Enable", cbEnable.Checked)
            IcImagingControl1.LiveStart()
        Catch ex As System.Exception
            MessageBox.Show("Failed to load the frame filter!")
        End Try

    End Sub

The filter can be toggled, using the checkbox cbEnable.

    C#

    private void cbEnable_CheckedChanged(object sender, System.EventArgs e)
    {
        filter.BeginParameterTransfer();
        filter.SetBoolParameter("Enable", cbEnable.Checked);
        filter.EndParameterTransfer();
    }

    VB.NET

    Private Sub cbEnable_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbEnable.CheckedChanged
        filter.BeginParameterTransfer()
        filter.SetBoolParameter("Enable", cbEnable.Checked)
        filter.EndParameterTransfer()
    End Sub

The method filter.ShowDialog displays the built-in dialog for setting the upper and lower bound. After the dialog has been closed, the checkbox cbEnable has to be synchronized with the filter parameter "Enable", as it may have been changed in the frame filter's dialog.

    C#

    private void btParameter_Click(object sender, System.EventArgs e)
    {
        filter.ShowDialog();
        if (filter.GetBoolParameter("Enable"))
            cbEnable.Checked = true;
        else
            cbEnable.Checked = false;

    }

    VB.NET

    Private Sub btParameter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btParameter.Click
        filter.ShowDialog()
        If filter.GetBoolParameter("Enable") Then
            cbEnable.Checked = True
        Else
            cbEnable.Checked = False
        End If
    End Sub