Image segmentation , pattern recognition Vision v 1.5.1

  • Image segmentation , pattern recognition Vision v 1.5.1

    Vision is an experimental .net desktop application that can detect and categorize objects from images. The original purpose is to detect objects on medical images (CT x-rays). Using image filters and Sobel's edge detection algorithm Vision can detect with high 100% accuracy simple simple shapes like triangles in images and can partially extract and categorize objects on more complicated medical images.

    Implementation of Sobel's edge detection algorithm C# .Net

        using System;
        using System.Collections.Generic;
        using System.Text;
        using System.Drawing;
        using System.Windows.Forms;
        using System.Drawing.Imaging;
    
        namespace Vision.Entities
        {
            class EdgeDetection
            {
                public Image EdgeDetect(Image im)
                {
                    //sobel masks
                    int[,] gx = new int[,] { { -1, 0, 1 }, { -2, 0, 2 }, { -1, 0, 1 } };   //  Gx kernel
                    int[,] gy = new int[,] { { 1, 2, 1 }, { 0, 0, 0 }, { -1, -2, -1 } };  //  Gy kernel
                    Bitmap b = (Bitmap)im;
                    Bitmap b1 = new Bitmap(im);
                    // scan image
                    for (int i = 1; i < b.Height - 1; i++)
                    {
                        for (int j = 1; j < b.Width - 1; j++)
                        {
                            float new_x = 0;
                            float new_y = 0;
                            float c;
                            //loop for cov matrix
                            for (int hw = -1; hw < 2; hw++)
                            {
                                for (int wi = -1; wi < 2; wi++)
                                {
                                    c = (b.GetPixel(j + wi, i + hw).B + b.GetPixel(j + wi, i + hw).R + b.GetPixel(j + wi, i + hw).G) / 2;
                                    new_x += gx[hw + 1, wi + 1] * c;
                                    new_y += gy[hw + 1, wi + 1] * c;
                                }
                            }
    
                            if (new_x * new_x + new_y * new_y > 50 * 50)
                            {
                                b1.SetPixel(j, i, Color.Black);
                            }
                        }
                    }
                    return (Image)b1;
                }
    
                public void SobelEdgeDetection(PictureBox pictureBox1, PictureBox pictureBox2)
                {
                    Bitmap image1 = new Bitmap(pictureBox1.Image);
                    Bitmap image2 = new Bitmap(pictureBox1.Image);
                    int width = image1.Width;
                    int height = image1.Height;
                    //sobel masks
                    int[,] gx = new int[,] { { -1, 0, 1 }, { -2, 0, 2 }, { -1, 0, 1 } };
                    int[,] gy = new int[,] { { 1, 2, 1 }, { 0, 0, 0 }, { -1, -2, -1 } };
    
                    int[,] allPixR = new int[width, height];
                    int[,] allPixG = new int[width, height];
                    int[,] allPixB = new int[width, height];
    
                    int limit = 128 * 128;
    
                    for (int i = 0; i < width; i++)
                    {
                        for (int j = 0; j < height; j++)
                        {
                            allPixR[i, j] = image1.GetPixel(i, j).R;
                            allPixG[i, j] = image1.GetPixel(i, j).G;
                            allPixB[i, j] = image1.GetPixel(i, j).B;
                        }
                    }
    
                    int new_rx = 0, new_ry = 0;
                    int new_gx = 0, new_gy = 0;
                    int new_bx = 0, new_by = 0;
                    int rc, gc, bc;
                    for (int i = 1; i < image1.Width - 1; i++)
                    {
                        for (int j = 1; j < image1.Height - 1; j++)
                        {
                            new_rx = 0;
                            new_ry = 0;
                            new_gx = 0;
                            new_gy = 0;
                            new_bx = 0;
                            new_by = 0;
                            rc = 0;
                            gc = 0;
                            bc = 0;
    
                            for (int wi = -1; wi < 2; wi++)
                            {
                                for (int hw = -1; hw < 2; hw++)
                                {
                                    rc = allPixR[i + hw, j + wi];
                                    new_rx += gx[wi + 1, hw + 1] * rc;
                                    new_ry += gy[wi + 1, hw + 1] * rc;
    
                                    gc = allPixG[i + hw, j + wi];
                                    new_gx += gx[wi + 1, hw + 1] * gc;
                                    new_gy += gy[wi + 1, hw + 1] * gc;
    
                                    bc = allPixB[i + hw, j + wi];
                                    new_bx += gx[wi + 1, hw + 1] * bc;
                                    new_by += gy[wi + 1, hw + 1] * bc;
                                }
                            }
                            if (new_rx * new_rx + new_ry * new_ry > limit ||
                                    new_gx * new_gx + new_gy * new_gy > limit || new_bx * new_bx + new_by * new_by > limit)
                            {
                                image2.SetPixel(i, j, Color.Red);
                            }
                            else
                            {
                                image2.SetPixel(i, j, image1.GetPixel(i, j));
                            }
                        }
                    }
                    pictureBox2.Image = image2;
                }
            }
        }
                                    

    Paper Link

    Sample Images

  • Category

Up Next

Js Metro Tabs

Alexabdros Okkalides

Magic The Gathering Slider

Alexandros Okkalides

Js-Toolbar

Alexandros Okkalides

Ajax Image Uploader

Alexandros Okkalides