Click here to Skip to main content
Click here to Skip to main content
Articles » Multimedia » GDI+ » General » Downloads
 
Add your own
alternative version

Image Processing Lab in C#

, 13 Mar 2007 GPL3
A tool and library for image processing
iplab_demo.zip
iplab_demo
AForge.dll
AForge.Imaging.chm
AForge.Imaging.dll
AForge.Math.dll
DockingToolbar.dll
iplab.exe
SourceGrid2.dll
SourceLibrary.dll
WeifenLuo.WinFormsUI.dll
iplab_src.zip
iplab_src
icons
about.gif
clone.gif
convolution.gif
copy.gif
cut.gif
disk.gif
fit_to_size.gif
folder_out.gif
fourier.gif
grayscale.gif
histogram_window.gif
levels.gif
morphology.gif
paste.gif
pie-chart.gif
resize.gif
rotate.gif
threshold.gif
view_1_1.gif
zoom_in.gif
zoom_out.gif
iplab
App.ico
banner.gif
column-chart.ico
Controls
Filters Forms
line-chart.ico
References
AForge.dll
AForge.Imaging.dll
AForge.Math.dll
DockingToolbar.dll
SourceGrid2.dll
SourceLibrary.dll
WeifenLuo.WinFormsUI.dll
Resources
arrow.bmp
harrow.cur
hmove.cur
Tools
namespace IPLab
{
    using System;
    using System.Drawing;

    using SourceGrid2;
    using SourceGrid2.Cells.Real;

    // Events arguments
    public class GridEventArgs : EventArgs
    {
        private int col, row;

        // Constructor
        public GridEventArgs( int col, int row )
        {
            this.col = col;
            this.row = row;
        }

        // Col property
        public int Col
        {
            get { return col; }
        }
        // Row property
        public int Row
        {
            get { return row; }
        }
    }


    /// <summary>
    /// GridArrayInt
    /// </summary>
    public class GridArrayInt : SourceGrid2.Grid
    {
        private Array array;
        private CellBehavior behavior;

        // events
        public delegate void GridEventHandler( object sender, GridEventArgs e );
        public event GridEventHandler CellClicked;
        public event GridEventHandler ValueChanged;

        // Constructor
        public GridArrayInt( )
        {
        }

        // Load data
        public void LoadData( Array array )
        {
            //
            this.array = array;

            behavior = new CellBehavior( array );


            // set column and row headers
            FixedRows = 1;
            FixedColumns = 1;

            // Redim the grid
            Redim( array.GetLength( 0 ) + FixedRows, array.GetLength( 1 ) + FixedColumns );

            // Header
            this[0, 0] = new Header( );

            // Column headers
            for ( int i = 1; i < this.ColumnsCount; i++ )
            {
                ColumnHeader header = new ColumnHeader( i.ToString( ) );
                header.EnableSort = false;
                this[0, i] = header;
            }
            // Row headers
            for ( int i = 1; i < this.RowsCount; i++ )
            {
                this[i, 0] = new RowHeader( i.ToString( ) );
            }

            // Data cells
            Type type = array.GetValue( 0, 0 ).GetType( );
            for ( int i = 1, ia = 0; i < this.RowsCount; i++, ia++ )
            {
                for ( int j = 1, ja = 0; j < this.ColumnsCount; j++, ja++ )
                {
                    Cell cell = new Cell( array.GetValue( ia, ja ), type );
                    cell.Behaviors.Add( behavior );
                    this[i, j] = cell;
                }
            }

            Colorize( );
        }

        // Colorize cells
        public void Colorize( )
        {
            int n = array.GetLength( 0 );
            int k = array.GetLength( 1 );
            int min = int.MaxValue;
            int max = int.MinValue;
            int v = 0;

            // find min and max values
            for ( int i = 0; i < n; i++ )
            {
                for ( int j = 0; j < k; j++ )
                {
                    v = (int) Convert.ChangeType( array.GetValue( i, j ), typeof( int ) );

                    if ( v > max )
                        max = v;
                    if ( v < min )
                        min = v;
                }
            }

            // Update cells color
            for ( int i = 1, ia = 0; i < this.RowsCount; i++, ia++ )
            {
                for ( int j = 1, ja = 0; j < this.ColumnsCount; j++, ja++ )
                {
                    Cell cell = (Cell) this[i, j];
                    v = (int) Convert.ChangeType( cell.Value, typeof( int ) );

                    if ( v > 0 )
                    {
                        int c = 63 + 192 * ( max - v ) / max;

                        cell.BackColor = Color.FromArgb( 255, c, c );
                    }
                    else if ( v < 0 )
                    {
                        int c = 63 + 192 * ( min - v ) / min;

                        cell.BackColor = Color.FromArgb( 255, 255, c );
                    }
                    else
                        cell.BackColor = Color.White;
                }
            }
        }

        // On cell clicked
        protected virtual void OnCellClicked( int col, int row )
        {
            if ( CellClicked != null )
                CellClicked( this, new GridEventArgs( col, row ) );
        }

        // On value changed
        protected virtual void OnValueChanged( int col, int row )
        {
            if ( ValueChanged != null )
                ValueChanged( this, new GridEventArgs( col, row ) );
        }

        // Cell behavior
        private class CellBehavior : SourceGrid2.BehaviorModels.Common
        {
            private Array array;

            // Constructor
            public CellBehavior( Array array )
            {
                this.array = array;
            }

            // On mouse click
            public override void OnClick( PositionEventArgs e )
            {
                ( (GridArrayInt) e.Grid ).OnCellClicked( e.Position.Column - 1, e.Position.Row - 1 );
            }
            // On value changed
            public override void OnValueChanged( PositionEventArgs e )
            {
                array.SetValue( e.Cell.GetValue( e.Position ), e.Position.Row - 1, e.Position.Column - 1 );
                ( (GridArrayInt) e.Grid ).Colorize( );
                ( (GridArrayInt) e.Grid ).OnValueChanged( e.Position.Column - 1, e.Position.Row - 1 );
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)

Share

About the Author

Andrew Kirillov
Software Developer (Senior) Cisco Systems
United Kingdom United Kingdom
Started software development at about 15 years old and it seems like now it lasts most part of my life. Fortunately did not spend too much time with Z80 and BK0010 and switched to 8086 and further. Similar with programming languages – luckily managed to get away from BASIC and Pascal to things like Assembler, C, C++ and then C#. Apart from daily programming for food, do it also for hobby, where mostly enjoy areas like Computer Vision, Robotics and AI. This led to some open source stuff like AForge.NET.
 
Going out of computers I am just a man loving his family, enjoying traveling, a bit of books, a bit of movies and a mixture of everything else. Always wanted to learn playing guitar, but it seems like 6 strings are much harder than few dozens of keyboard’s keys. Will keep progressing ...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.141220.1 | Last Updated 13 Mar 2007
Article Copyright 2005 by Andrew Kirillov
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid