Toster
Toster

Reputation: 381

Algorithm for determining the size of air bubbles from image

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

Upvotes: 9

Views: 1293

Answers (4)

CoffeDeveloper
CoffeDeveloper

Reputation: 8325

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.

Upvotes: 4

lfgtm
lfgtm

Reputation: 1047

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.

Upvotes: 1

Dmitry Nogin
Dmitry Nogin

Reputation: 3750

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.

Upvotes: 2

atlaste
atlaste

Reputation: 31146

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.

Upvotes: 1

Related Questions