AForge.NET

  :: AForge.NET Framework :: Articles :: Forums ::

Mask to detect object at same place

The forum is to discuss topics related to different areas of image processing and computer vision.

Mask to detect object at same place

Postby roshanpillai » Wed Feb 20, 2019 2:23 pm

Hi,

I have a folder of images of same pattern blobs in same place in all images. But in some images blobs might be missing from their location. How can i create a mask with placeholders for blobs so that I can detect a blob as missing if its not there?
roshanpillai
 
Posts: 6
Joined: Wed Feb 20, 2019 2:19 pm

Re: Mask to detect object at same place

Postby andrew.kirillov » Thu Feb 21, 2019 8:01 am

Hello,

It depends on what sort of patterns/blobs you are looking for and what is the background. If you could share few sample images, it may get easier to tell something.

If the objects you are looking for have some specific color which is easy to separate from background, then some color filtering may help. After that apply blob processing and see if you can find anything at the X/Y coordinates you expect the object to be.
With best regards,
Andrew


Interested in supporting AForge.NET Framework?
User avatar
andrew.kirillov
Site Admin, AForge.NET Developer
 
Posts: 3453
Joined: Fri Jan 23, 2009 9:12 am
Location: UK

Re: Mask to detect object at same place

Postby roshanpillai » Thu Feb 21, 2019 8:31 am

Hi Andrew,

For some reason im unable to upload any image, getting the following error : Could not upload attachment to ./files/5795_5d06418c7274e34fd7249056452097fb.

I'll try to explain what im doing :

* I have an image with 2 yellow squares in a black background.
* I apply grayscale, histogram, fillholes filter to detect the blob and create a mask(8bpp).
* I draw rectangles around the blobs detected.
* I take another image just like the first one but with the 2nd square missing.
* Tried using mask filters to try and compare images but didnt work.

* I'm trying to compare the second image to the mask to detect missing blob and draw a different color rectangle around the missing place.
roshanpillai
 
Posts: 6
Joined: Wed Feb 20, 2019 2:19 pm

Re: Mask to detect object at same place

Postby roshanpillai » Thu Feb 21, 2019 9:09 am

Hi Andrew,

I found another way to do this using the difference filter.
I created a mask in a different process, extracted blob of the 2nd image with missing blob, and used the mask as an overlay image in the difference filter for the 2nd image.

This seems like an inefficient way of doing it, is there any simpler way?
Also, How do I compare blob id's. For example, in the mask i have two blob id's, in the 2nd image i have only. How can I keep the blobid of the missing blob as the same as the mask(use mask as a placeholder)? So that I can send suitable signal to arduino for further operation.

Code: Select all
  Bitmap sourceimage = imgInput2;

            Grayscale grayfilter = new Grayscale(0.2125, 0.7154, 0.0721);
            // apply the filter
            Bitmap grayImage = grayfilter.Apply(sourceimage);

             // threshold Image
            Threshold thresholdfilter = new Threshold(10);
            // apply the filter
            Bitmap thresholdImage = thresholdfilter.Apply(grayImage);

           //Fill Holes if any
            FillHoles filter5 = new FillHoles();
            filter5.MaxHoleHeight = 50;
            filter5.MaxHoleWidth = 50;
            filter5.CoupledSizeFiltering = false;
            // apply the filter
            Bitmap processedImagefh = filter5.Apply(thresholdImage);
            Bitmap unmasked = processedImagefh;

            //Differrence filter
            Difference filter = new Difference(Maskimage);
            // apply the filter
            Bitmap resultImage = filter.Apply(processedImagefh);

            //filter blobs to remove small blobs
            BlobsFiltering blobfilter = new BlobsFiltering();
            blobfilter.MinWidth = 50;
            blobfilter.MinHeight = 50;
            // apply the filter
            Bitmap blobfilterImage = blobfilter.Apply(resultImage);
                     
            BlobCounter blobCounter = new BlobCounter();
            blobCounter.ProcessImage(blobfilterImage);
            Blob[] blobs2 = blobCounter.GetObjectsInformation();

            Graphics g = pictureBox2.CreateGraphics();

            foreach (Blob blob in blobs2)
            {
                Pen rectpen = new Pen(Color.Red, 5);
                g.DrawRectangle(rectpen, blob.Rectangle.X, blob.Rectangle.Y, blob.Rectangle.Width, blob.Rectangle.Height);
            }
roshanpillai
 
Posts: 6
Joined: Wed Feb 20, 2019 2:19 pm

Re: Mask to detect object at same place

Postby andrew.kirillov » Thu Feb 21, 2019 11:34 am

roshanpillai wrote:For some reason im unable to upload any image, getting the following error : Could not upload attachment to ./files/5795_5d06418c7274e34fd7249056452097fb.

Fixed. Should be possible to upload files again.
With best regards,
Andrew


Interested in supporting AForge.NET Framework?
User avatar
andrew.kirillov
Site Admin, AForge.NET Developer
 
Posts: 3453
Joined: Fri Jan 23, 2009 9:12 am
Location: UK

Re: Mask to detect object at same place

Postby andrew.kirillov » Thu Feb 21, 2019 11:38 am

Not sure I understand why you need mask image at all. After color filtering and grayscaling/thresholding you can simply run blob counter to see how many blobs you have. Check their size/position/etc. and decide if something is missing or not.

roshanpillai wrote:Also, How do I compare blob id's. For example, in the mask i have two blob id's, in the 2nd image i have only

Blob IDs are internal details - you can not rely on them or compare them. Instead use other properties of blobs - X/Y coordinate, width, height, area, etc.
With best regards,
Andrew


Interested in supporting AForge.NET Framework?
User avatar
andrew.kirillov
Site Admin, AForge.NET Developer
 
Posts: 3453
Joined: Fri Jan 23, 2009 9:12 am
Location: UK

Re: Mask to detect object at same place

Postby roshanpillai » Thu Feb 21, 2019 11:47 am

Hi Andrew,

I need a mask because the blobs will always be in the same place and position all the time. I send the information to a robotic hand to move to pick the object. So, if an object is missing from its place the robotic hand doesnt have to go there. As you said, I can count the blob and know that a blob is missing, but I wont know which one is missing.

Do you have any resource where I can see how to identify blob location using X,Y data, store them in an array and name them manually?
roshanpillai
 
Posts: 6
Joined: Wed Feb 20, 2019 2:19 pm

Re: Mask to detect object at same place

Postby andrew.kirillov » Thu Feb 21, 2019 12:06 pm

roshanpillai wrote:Do you have any resource where I can see how to identify blob location using X,Y data, store them in an array and name them manually?

Try some of these: [1], [2], [3].
With best regards,
Andrew


Interested in supporting AForge.NET Framework?
User avatar
andrew.kirillov
Site Admin, AForge.NET Developer
 
Posts: 3453
Joined: Fri Jan 23, 2009 9:12 am
Location: UK

Re: Mask to detect object at same place

Postby roshanpillai » Fri Feb 22, 2019 7:21 am

Hi Andrew,

I checked all the documents but I could'nt find any way to acheive what im trying to do.
I tried the blobcounter.objectorder to sort it with XY, but my blobs are arranged in an elliptical path as below :

blank.jpg (112.75 KiB) Viewed 13180 times


When I apply blobcounter.objectorder to sort it with XY, and draw the string using the blobs X/Y points, I get the result as follows :

result
222.png (61.3 KiB) Viewed 13180 times


When I write the blobid's in a listbox, i get them in order.
How can I get the blob to be numbered/labelled from left to right following the elliptical path?
roshanpillai
 
Posts: 6
Joined: Wed Feb 20, 2019 2:19 pm

Re: Mask to detect object at same place

Postby roshanpillai » Mon Feb 25, 2019 8:27 am

Hi Andrew,

I achieved this by using the COG of each blob, by comparing the cog coordinate from a center point and draw them from left to right order using LINQ. Using blob XY/width/height was not useful.
roshanpillai
 
Posts: 6
Joined: Wed Feb 20, 2019 2:19 pm



Next

Return to Image Processing and Computer Vision