Algorithm for determining the size of air bubbles from image
Asked Answered
T

4

9

I'm looking for a good way to isolate an air bubble from the following image. I'm using Visual Studio 2015 and C#.

I've heard of the watershed method and believe it may be a good solution.

I tried implementing the code solution found here: watershed image segmentation

I haven't had much success. The solution has trouble finding functions, for example: FilterGrayToGray.

Does anyone know of a good way to do this?

Example of Image

Terra answered 22/5, 2016 at 13:14 Comment(3)
have you tried OpenCV (or Emgu CV for .Net... C#)? maybe using some binary filters with a blob detector should be enough to at least detect your bubbles...Diatonic
So I tried a different algorithm who need OpenCV but ,all versions of libraries Open CV available NuGet not work.Terra
There was a challenge on codegolf if that helps. With a C# answerSquireen
H
4

You should just train a Neural network to recognize parts of image when there are no bubbles (in example groups of 16x16 pixels). Then when recognizing a square is not successfull you do a burst of horizontal scanlines and you register where the edge starts and ends. You can determine pretty precisely the section of a bubble (however determine its volume needs to keep into account surface curvature, wich is possible but more hard) on the image. If you have the possibility to use more cameras you can triangulate more sections of a bubble and get a precise idea of real volume. As another euristic to know bubble size you can also use the known volume throughput, so you know that if in a time interval you emitted X liters of air, and the bubbles have sections given in a certain proportion you can redistribute total volume across bubbles and further increase precision (of course you have to keep in mind pressure since bubbles on bottom of the pool will be more little).

Show different images tweaked

As you see you can play with simple algorithms like gaussian difference and contrast to achieve different quality results.

  • In the left picture you can easily remove all background noise, however you have lost now part of the bubbles. It is possible you can re-gain the missed bubbles edge by using a different illumination on the pool
  • In the right picture you have the whole bubbles edges, but now you also have more areas that you need to manually discard from picture.

As for edge detections algorithm you should use an algorithm that do not add a fixed offset to edges (like convolution matrix or laplace), for this I think gaussian difference would work best.

Keep all intermediate data so one can easily verify and tweak the algorithm and increase its precision.

EDIT:

The code depends on wich library you use, you can easily implement Gaussian Blur and Horizontal Scanline, for Neural Networks there are already c# solutions out there.

// Do gaussian difference
Image ComputeGaussianDifference (Image img, float r1, float r2){
    Image img = img.GaussianBlur( r1);
    Image img2 = img.GaussianBlur( r2);
    return (img-img2).Normalize(); // make values more noticeable
}

more edits pending.. try do document yourself in the meantime, I already given enough trace to let you do the job, you just need basic understanding of simple image processing algorithms and usage of ready neural networks.

Hod answered 27/5, 2016 at 8:19 Comment(10)
As edge detection use what seems to works better, since there is some noise (waves, light reflection) problably the best thing is just to try gaussian difference and tweak it manually to see only edges of bubbles.Hod
Neural Network is necessary because there are obviouse non-bubble edges (edge of the pool, a bright highlight), those should be manually disabled areas or areas discarded by NN. Of course the better way would be positioning the camera in a way where there is only a monochrome blue backgroudn, that would remove the requirment for a NN.Hod
Can u give sample of code of this solution? I had a problem with the implication solutions the same problem I had to solve in C # and I'm more user Delphi .Terra
I can give sample C# snippet later in lunch break if you want, I'm not a Delphi programmer :)Hod
It was great, and thank you for perfect soultion of my problem, and for your time :)Terra
Could you tell me yet what libraries you used , because I have with this is not a small problem. Guassian blur of spinning AForge has a problem working with my code ? Very help me a full picture of how you did , you used the library , how to process the image on a neural network from c # side , i getting lost terribly whith c#Terra
Aforge seems really nice, however you need a C# neural network for image recognition (since implementing gaussian blur is easy enough to do on your own), right now I'm not able to find one neural network for C# and image recognition (there are several for C++), what about asking for that? softwarerecs.stackexchange.comHod
I tested some functions , fast edge detection, gaussian blur . And the subsequent transformation of the image to true black and white ( binary) , with a corresponding brightening / contrast , and I have a problem with obtaining perfectly visible bubbles. They are always created some defectsTerra
Like already mentioned have you tried by using a different illumination or a different background? if you use a chess-pattern it will be really easy to detect bubbles. While developing the solution may be one of the goals, if you cannot find libraries that are good enough and the goals is really measuring the bubbles, then maybe you can make easier for the computer to detect the bubbles.Hod
ok thanks , I managed to get the desired effect , I have some type of determination of edges, FastEdgeDetection manipulating gamma / luminance / Contrast and differences gaussian . As for the neural network I will be modeled on algorithms face detection in images . Thanks for the helpTerra
V
2

Just in case if you are looking for some fun - you could investigate Application Example: Photo OCR. Basically you train one NN to detect bubble, and try it on a sliding window across the image. When you capture one - you use another NN, which is trained to estimate bubble size or volume (you probably can measure your air stream to train the NN). It is not so difficult as it sounds, and provides very high precision and adaptability.

P.S. Azure ML looks good as a free source of all the bells and whistles without need to go deep.

Valtin answered 27/5, 2016 at 8:6 Comment(0)
S
1

To solutions come to mind:

Solution 1:

Use the Hough transform for circles.

Solution 2:

In the past I also had a lot of trouble with similar image segmentation tasks. Basically I ended up with a flood fill, which is similar to the watershed algorithm you programmed.

A few hat tricks that I would try here:

  • Shrink the image.
  • Use colors. I notice you're just making everything gray; that makes little sense if you have a dark-blue background and black boundaries.
Secession answered 27/5, 2016 at 7:34 Comment(0)
D
1

Do you wish to isolate the air bubble in a single image, or track the same air bubble from an image stream?

To isolate a 'bubble' try using a convolution matrix on the image to detect the edges. You should pick the edge detection convolution based on the nature of the image. Here is an example of a laplace edge detection done in gimp, however it is faily straight forward to implement in code.

Laplace edge detection

This can help in isolating the edges of the bubbles.

If you are tracking the same bubble from a stream, this is more difficult due to as the way bubbles distort when flowing through liquid. If the frame rate is high enough it would be easy to see difference from frame to frame and you can judge which bubble it is likely to be (based on positional difference). i.e you would have to compare current frame to previous frame and use some intelligence to attempt to work out which bubble is the same from frame to frame. Using a fiducial to help give a point of reference would be useful too. The nozzle at the bottom of the image might make a good one, as you can generate a signature for it (nozzle won't change shape!) and check that each time. Signatures for the bubbles aren't going to help much since they could change drastically from one image to the next, so instead you would be processing blobs and their likely location in the image from one frame to the next.

For more information on how convolution matrices work see here.

For more information on edge detection see here.

Hope this helps, good luck.

Dunlavy answered 27/5, 2016 at 8:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.