AForge.NET

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

blob area subtraction

Forum to discuss AForge.NET Framework, its features, API, how-tos, etc.

blob area subtraction

Postby cadillac » Tue Nov 07, 2017 2:11 pm

Hello,

I have a small circle inside a larger circle(Please refer image).
both circles have green edge.
I use color filtering, threshold and fill to get the blobs and blob statistics.
if I set the hole width and height to 200, the larger circle gets filled(Area = 30000). If I set the hole height and width to 50, the smaller circle gets filled(Area = 8000).
What i want is to subtract the area of the smaller blob with the larger one and get the resultant area (22000).
How do I do this? Please help.
Attachments
af_test.png
af_test.png (4.49 KiB) Viewed 8018 times
cadillac
 
Posts: 5
Joined: Tue Nov 07, 2017 1:57 pm

Re: blob area subtraction

Postby andrew.kirillov » Tue Nov 07, 2017 2:45 pm

Hello,

cadillac wrote:and fill to get the blobs and blob statistics.

What do you fill?

cadillac wrote:if I set the hole width and height to 200

Sorry, which hole are you referring to? Are you talking about FillHoles filter?

So you say that you managed to get area=30000 after some operations. And then you managed to get area=8000 after some other operations. So just subtract one from another. Is not it what you need?
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: blob area subtraction

Postby cadillac » Wed Nov 08, 2017 5:24 am

Hi Andrew,

This is my code:

Code: Select all
Bitmap sourceImage = (Bitmap)pictureBox1.Image;

                //***********************Color Filter***************************
                EuclideanColorFiltering filter6 = new EuclideanColorFiltering();
                // set color and radius
                filter6.CenterColor = new RGB(253, 20, 20);
                filter6.Radius = 100;
                // apply the filter
                Bitmap processedImage = filter6.Apply(sourceImage);

                // pictureBox2.Image = processedImage;

                //***********************GrayScale*******************************
                Bitmap sourceImagegs = processedImage;
                Grayscale filter2 = new Grayscale(0.2125, 0.7154, 0.0721);
                Bitmap processedImagegs = filter2.Apply(sourceImagegs);

                //pictureBox2.Image = processedImagegs;

                //***********************Threshold*******************************
                Bitmap sourceImagets = processedImagegs;
                Threshold filter3 = new Threshold(10);
                Bitmap processedImagets = filter3.Apply(sourceImagets);

                //pictureBox2.Image = processedImage;

                //***********************Fill Hole*******************************
                Bitmap sourceImagefh = processedImagets;
                FillHoles filter5 = new FillHoles();
                filter5.MaxHoleHeight = 200;
                filter5.MaxHoleWidth = 200;
                filter5.CoupledSizeFiltering = true;
                // apply the filter
                Bitmap processedImagefh = filter5.Apply(sourceImagefh);

                //pictureBox2.Image = processedImage;

                //***********************BlobSize********************************
                Bitmap sourceImagebs = processedImagefh;
                BlobsFiltering filter4 = new BlobsFiltering();
                filter4.CoupledSizeFiltering = true;
                filter4.MinWidth = 100;
                filter4.MinHeight = 100;
                Bitmap processedImagebs = filter4.Apply(sourceImagebs);

                //pictureBox2.Image = processedImage;
                //***********************Blob Statistics*************************
                Bitmap sourceImagefpi = processedImagebs;

                BlobCounter bc = new BlobCounter(sourceImagefpi);
                // specify sort order
                bc.ObjectsOrder = ObjectsOrder.Size;
                // get objects' information (blobs without image)
                Blob[] blobs = bc.GetObjectsInformation();
                // process blobs
                int count = blobs.Length;



In the above code, i have set the fillhole filter height and width to 200. When I do this the larger circle gets filled and the blob count is 1, although there is a smaller circle within it. If I set the fillhole filter height and width to 50, the smaller circle blob is filled and the blob count is 1.

What im trying to do is. When the larger circle is filled, i want to be able to detect the area of the smaller circle so that I can subtract it. Im unable to find the area of the smaller circle when the larger circle is filled.

Please check the attached image for reference,
Attachments
003.png
003.png (7.59 KiB) Viewed 8009 times
002.png
002.png (5.18 KiB) Viewed 8009 times
001.png
001.png (3.78 KiB) Viewed 8009 times
cadillac
 
Posts: 5
Joined: Tue Nov 07, 2017 1:57 pm

Re: blob area subtraction

Postby cadillac » Wed Nov 08, 2017 6:57 am

Hi Andrew,

I found a solution but its not too pretty.
i got the idea from your reply.
What I did is, I created 2 sets of operation, one with min values and one with max values. So Im getting 2 sets of data in terms of area. Then Im able to subtract it. Its a long procedure but its working.

Is there any cleaner, more efficient way to do this?
cadillac
 
Posts: 5
Joined: Tue Nov 07, 2017 1:57 pm

Re: blob area subtraction

Postby andrew.kirillov » Wed Nov 08, 2017 8:14 am

cadillac wrote:Is there any cleaner, more efficient way to do this?

Another way is not to do any filling of holes at all. So just leave your circles as they are. Use blob processing to find them. If you know those objects are perfect circles, then you know that blob's width equals to blobs height, which equals to circle's diameter. Once you know that, use simple algebra and calculate area of circle.
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: blob area subtraction

Postby cadillac » Wed Nov 08, 2017 8:25 am

Hi Andrew,

I used perfect circle just as an example. In the actual application, the object is fast moving and while capturing the image, the triggered image might distort a bit and the circle might not be perfect, it might be slightly elliptical, the width and height will fluctuate, that is why I'm filling the holes to get the area.
cadillac
 
Posts: 5
Joined: Tue Nov 07, 2017 1:57 pm

Re: blob area subtraction

Postby andrew.kirillov » Wed Nov 08, 2017 9:18 am

Well, this is what I though as well - it was artificial example.

In this case your approach seem to be fine and safe.
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: blob area subtraction

Postby cadillac » Wed Nov 08, 2017 9:58 am

Thanks Andrew.
I calculated the processing time and it didnt change much, earlier it was around 25ms and now its 35ms. So thats still very fast, i'll go ahead with that.
One last question. Is there any option to change the color of the filled hole? It would help to visually differentiate both circles.
Im using a second picturebox to display the processed image.
cadillac
 
Posts: 5
Joined: Tue Nov 07, 2017 1:57 pm

Re: blob area subtraction

Postby andrew.kirillov » Wed Nov 08, 2017 10:50 am

cadillac wrote:Is there any option to change the color of the filled hole?

Just checked - no, there is no such option. But you are right - it would be useful to have that option. Not sure why it was not done.

cadillac wrote:I calculated the processing time and it didnt change much, earlier it was around 25ms and now its 35ms

You can parallel it. So one thread fills small holes and looks for objects after that. While another thread is doing same, but filling bigger holes.
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




Return to AForge.NET Framework