blob in emgu cv library

Ask question on using Emgu CV with C#

blob in emgu cv library

Postby bilokhan » Sat Jan 28, 2012 12:28 pm

how to separate the pixels by applying blob and creating rectangle around the pixels glowing in image processing ..plzzzzzzzzzzzzzzzzzzzzz help me....
bilokhan
 
Posts: 2
Joined: Sat Jan 28, 2012 12:11 pm

Re: blob in emgu cv library

Postby bojoeb » Sun Jan 29, 2012 3:10 am


I suppose what you mean by pixels glowing is that they are brighter than everything else in the image. To extract the blobs of those pixels, maybe just set an illumination threshold (if you need more information about that just say so). But I'm not too sure what you mean by "glowing", maybe you could provide a screenshot of what you want? To create a rectangle around the blob, just use findContours to find the contours of the blobs and then when you have the contour of the blob that you want to create a rectangle around, simply get the bounding rectangle of the contour.

FindContours Method: http://www.emgu.com/wiki/files/1.5.0.0/Help/html/028cb9c4-eb4b-aa5d-242e-273ac7e227e2.htm
BoundingRectangle Property: http://www.emgu.com/wiki/files/1.3.0.0/html/10b477ef-b9be-ec95-c6a2-469b2180c012.htm

Sorry if this isn't what you wanted, but I sort of need more information before I can fully help you. :D Thanks, and I hope this helps.
                              '-'
    bojoeb
     
    Posts: 13
    Joined: Mon Jan 09, 2012 11:40 pm

    Re: blob in emgu cv library

    Postby bilokhan » Sun Jan 29, 2012 3:26 pm

    how to find the connected component in C# from dilated image using Emgucv library............i cannt find blob functions and if there is any other function use in emgu except blob so tell me......what name space or dll file use to get blob function......or any other way to find the connected commponent......i m providing the code too.. plz help ............



    {
    public partial class Form1 : Form
    {
    Image<Gray, float> imgSobel;
    Image<Gray,Byte> grayscale;
    Image<Gray, Byte> img_sobel;
    Image<Gray, Byte> img_threshold;
    Image<Gray, Byte> img_Dilation;
    Size img;
    Image<Gray, byte> imgp;
    public Form1()
    {
    InitializeComponent();

    IntPtr image = CvInvoke.cvLoadImage(@"C:/images/013_001.png", LOAD_IMAGE_TYPE.CV_LOAD_IMAGE_COLOR);
    img = CvInvoke.cvGetSize(image);

    grayscale = new Image<Gray, Byte>(img);
    CvInvoke.cvCvtColor(image, grayscale, COLOR_CONVERSION.CV_BGR2GRAY);
    CvInvoke.cvShowImage("Input Image", image);

    img_sobel = new Image<Gray, byte>(img);

    imgp = new Image<Gray, byte>(img);

    Image<Gray, Byte> img_gradiant = new Image<Gray, byte>(img_sobel.Size);

    img_threshold = new Image<Gray, byte>(img_gradiant.Size);
    img_Dilation = new Image<Gray, byte>(img_threshold.Size);
    try
    {
    CvInvoke.cvShowImage("Grayscale Image", grayscale);



    Image<Gray, Byte> test = new Image<Gray, Byte>(img);
    imgSobel = new Image<Gray, float>(img);
    imgSobel = grayscale.Sobel(1, 0, 3);
    Image<Gray, byte> myimg = new Image<Gray, byte>(imgSobel.Size);

    int num = 8;
    Gray g;

    Gray d;
    double intensity;
    int dd;

    for (int h = 0; h < imgSobel.Size.Height; h++)
    {
    for (int f = 0; f < imgSobel.Size.Width; f++)
    {

    dd = Convert.ToInt32(imgSobel[h, f].MCvScalar.v0.ToString());
    intensity = dd;
    if (intensity > 255)
    {
    d = new Gray(255);
    imgSobel[h, f] = d;
    }
    else
    if (intensity < 0)
    {
    d = new Gray(0);
    imgSobel[h, f] = d;
    }

    }
    }

    CvInvoke.cvShowImage("Sobel Image 1", imgSobel);
    int mid = num / 2;
    int index = 0;
    int sum = 0;
    int inner = 0;
    for (int i = 0; i < imgSobel.Size.Height; i++)
    {
    for (int j = 0; j < imgSobel.Size.Width; j++)
    {
    sum = 0;
    //array2 = array;
    index = j;
    if (j - mid <= 0)
    {
    inner = mid + (j - mid);
    index = index - inner;
    inner = mid - inner;
    }
    else
    {
    inner = 0;
    index = index - ((num - 1) - mid);
    }
    for (; inner < num; inner++)
    {

    if (index < imgSobel.Size.Width)
    {
    sum = sum + (Convert.ToInt32(imgSobel[i, index].MCvScalar.v0.ToString()));
    index++;
    }

    }

    if (sum < 256)
    {
    g = new Gray(sum);
    // lb.Items.Add(sum.ToString());
    img_gradiant[i, j] = g;
    }
    else
    {
    g = new Gray(255);
    img_gradiant[i, j] = g;
    }
    }

    }
    }
    catch (Exception ex)
    {
    MessageBox.Show(ex.Message + " " + ex.StackTrace);
    string err = ex.Message;
    }

    CvInvoke.cvShowImage("Acc gradiant", img_gradiant);

    CvInvoke.cvThreshold(img_gradiant, img_threshold, 127, 255, THRESH.CV_THRESH_BINARY);
    CvInvoke.cvShowImage("img_threshold", img_threshold);

    Image<Gray, byte> testimg = new Image<Gray, byte>(img_Dilation.Size);


    StructuringElementEx kernel = new StructuringElementEx(5, 1, 1, 0, CV_ELEMENT_SHAPE.CV_SHAPE_RECT);


    CvInvoke.cvDilate(img_threshold, img_Dilation, kernel, 1);
    CvInvoke.cvShowImage("img_Dilation", img_Dilation);
    testimg = img_Dilation;


    /*

    Contour<Point> cp;
    MemStorage store = new MemStorage();
    cp = testimg.FindContours(Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_SIMPLE, Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_LIST, store);
    CvInvoke.cvZero(testimg.Ptr);
    CvInvoke.cvDrawContours(testimg.Ptr, cp.Ptr, new MCvScalar(255, 0, 0), new MCvScalar(0, 0, 255), 2, 1, Emgu.CV.CvEnum.LINE_TYPE.CV_AA, Point.Empty);
    */
    CvInvoke.cvShowImage("testimg", testimg);


    }


    private void button1_Click(object sender, EventArgs e)
    {
    this.Close();
    }

    }
    }




    Thank you...
    Attachments
    22.jpg
    Sample.....i want output some thing like this
    22.jpg (57.55 KiB) Viewed 1107 times
    img_dilatte.jpg
    dilation image
    img_dilatte.jpg (63.03 KiB) Viewed 1107 times
    bilokhan
     
    Posts: 2
    Joined: Sat Jan 28, 2012 12:11 pm

    Re: blob in emgu cv library

    Postby bojoeb » Mon Jan 30, 2012 6:41 am


    That would be using FindContours, which you have commented out there. I forgot to tell you that FindContours sort of returns a list of all of the contours. To get the bounding rectangle, you would probably collect a list of rectangles in the while loop by getting the BoundingRectangle Property from each of the contours in the list. Basically, you would need code similar to this to access each of the contours in the contour "list":


    Code: Select all
    MemStorage store = new MemStorage();
    cp = testimg.FindContours(Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_SIMPLE, Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_LIST, store);
    List<Rectangle> rectangles = new List<Rectangle>();
    while (cp != null)
    {
        rectangles.Add(cp.BoundingRectangle);
        cp = cp.HNext; // Goes to the next contour in the list until cp is null, meaning that there are no more contours in the list.
    }

    Hope this helps!
                                '-'
      bojoeb
       
      Posts: 13
      Joined: Mon Jan 09, 2012 11:40 pm


      Return to C# Help

      Who is online

      Users browsing this forum: Google [Bot], Yahoo [Bot] and 5 guests