Tuesday, June 5, 2012

Canny and Sobel Edge Detection in C#

Sobel and Canny are major edge detection algorithms in Image Processing. Here I have implemented those algorithms using c#.

Download the source code from here.

Canny Edge Detection (click to zoom)

Sobel Edge Detection (click to zoom)




You can improve the program by using optimization methods such as threading and loop optimization.

21 comments :

  1. Would you be willing to repost a download link to the source? The existing link isn't working.

    ReplyDelete
  2. plz send me this code.ur link is not valid

    ReplyDelete
  3. please send me url download of this code

    ReplyDelete
    Replies
    1. please i dont have account could you please send me the code of canny edge detection

      Delete
  4. hi. i need to canny code for c# . please send me this code.thanks

    ReplyDelete
    Replies
    1. check the download link, you may need to log to shared hosting site.

      Delete
  5. heyy man..Sobel Edge Detection source code plz...

    ReplyDelete
    Replies
    1. you can find it in the attached project.

      -imp4.cs and method is private void sobel ( )

      Delete
  6. for ( int wi = -1; wi < 2; wi++ )
    {
    for ( int hw = -1; hw < 2; hw++ )
    {

    why the start value is -1
    why not start by 0

    ReplyDelete
    Replies
    1. Because of previous loops. Numbers depends on how you use them.

      This is a pure implementation of algorithm. Please use this in a optimized manner.

      Delete
  7. 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 )
    bb.SetPixel (i, j, Color.Black);
    //bb.SetPixel (i, j, Color.FromArgb(allPixR[i,j],allPixG[i,j],allPixB[i,j]));
    else
    bb.SetPixel (i, j, Color.White);
    }
    }

    for ( int wi = -1; wi < 2; wi++ ) nah tlng bnget knpa mulainya dari -1 kenap ndak mulai dari 0..


    artinya apa ini
    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;
    saya belum paham ,kenapa gx[ wi + 1,hw + 1] * rc;??

    ReplyDelete
    Replies
    1. I can not understand your language. :)

      Delete


    2. briefly describe the flow of the program??

      what the mean for this loop??

      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;

      Delete
    3. Find the edge strength by taking the gradient of the image using Sobel operator

      Please refer this article
      http://en.wikipedia.org/wiki/Canny_edge_detector

      Delete
    4. how about rc = allPixR[ i + hw,j + wi], what the mean??
      i + hw,j + wi parameters for what? value is taken from where??

      sorry many questions!!
      :)

      Delete
  8. sorry,, I wanna ask you about this code, may i ask you by email?

    ReplyDelete