3

Hi I am wondering whether anybody can offer any pointers on a potential approach to sizing the bubbles at the water surface (not those below it) in the following image. I would like to use an open source software if possible (my mind is leaning towards octave given that an image is a matrix). I have absolutely no background in image processing so any ideas are welcome. Obviously as a starting point I know the size of each pixel in the raw image (this image is a compressed version) so calculating a radius in pixels would be perfect.

Bubble image

Edit based upon the thoughts of @mmgp

So to try and make the question more direct I have taken onboard the thoughts of @mmgp using the open source libraries of Opencv. I have never used this before (nor indeed programmed directly in C or C++ however it looks as though it could fulfil my needs and although it looks as though it may have a steep learning curve my experience tells me those solutions that offer the most power often require time spent learning. So here is what I have done so far (with no background in image processing I am not sure if the functions I have used are ideal but I thought it might promote further thought). I have converted the image to grayscale, used a binary threshold and then applied a Hough Transform for circles. The images I generate at each stage are below as well as the code I have used. What is clear is that trackerbars are very useful for tweaking the parameters on the fly. I am however not yet adept enough to implement them in my code (any pointers would be great especially regarding the Hough transform where there are a few parameters to tweak).

So what do you think? What other function(s) might I try? Clearly my attempt is nowhere near as good as @mmgp but that may just be a matter of tweaking parameters.

Here are the photos: Grayscale(for completeness): Grayscale image Binary threshold: Grayscale image Circle image: Grayscale image

Here is the code:

 #include "opencv2/highgui/highgui.hpp"
 #include "opencv2/imgproc/imgproc.hpp"
 #include <iostream>
 #include <stdio.h>

 using namespace cv;

 /** @function main */
 int main(int argc, char** argv)
 {
 Mat src, src_gray, src_bw;

 /// Read the image
 src = imread( argv[1], 1 );

 if( !src.data )
 { return -1; }

 /// Convert it to gray
 cvtColor( src, src_gray, CV_BGR2GRAY );
 imwrite( "Gray_Image.jpg", src_gray );

 /// Threshold the image to make binary
 threshold(src_gray, src_bw, 140, 255, CV_THRESH_BINARY);
 imwrite( "Binary_Image.jpg", src_bw );

 vector<Vec3f> circles;

 /// Apply the Hough Transform to find the circles
 HoughCircles( src_bw, circles, CV_HOUGH_GRADIENT, 5, src_bw.rows/2, 5, 10, 0, 0 );

 /// Draw the circles detected
 for( size_t i = 0; i < circles.size(); i++ )
 {
 Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
 int radius = cvRound(circles[i][2]);
 // circle center
 circle( src, center, 3, Scalar(0,255,0), -1, 8, 0 );
 // circle outline
 circle( src, center, radius, Scalar(0,0,255), 3, 8, 0 );
 }

 /// Show your results
 namedWindow( "Hough Circle Transform Demo", 0 );
 namedWindow( "Gray", 0 );
 namedWindow( "Binary Threshold", 0 );
 imshow( "Hough Circle Transform Demo", src );
 imshow( "Gray", src_gray );
 imshow( "Binary Threshold", src_bw );
 imwrite( "Circles_Image.jpg", src );
 waitKey(0);
 return 0;
 }
Glorfindel
  • 21,988
  • 13
  • 81
  • 109
user1912925
  • 781
  • 1
  • 11
  • 25
  • I don't think it is such a bad fit for SO, I've seen worse questions. In fact, as the question is posed (and exemplified) it can expect approaches with good results. It is not too broad, and it fits stack overflow as much as many other image-processing questions. – mmgp Dec 23 '12 at 01:30
  • Here: http://i.imgur.com/Wi24f.png is the result of something that I would consider as a starting point since it gives mostly only locations where bubbles are. It is a combination of grayscale morphology, binary morphology and basic circle detection. Others will possibly have time to present more detailed (and possibly better) approaches. – mmgp Dec 23 '12 at 02:38
  • Thanks for the tips @mmgp, the result you present is certainly a great start. I deliberately chose one of my more complex images (many small bubbles and half a larger bubble out of shot) to see what was possible. I wonder whether it would be possible to detect the larger bubble even if it is only ~half shown? Out of interest what software did you do the processing in? Octave or something else? – user1912925 Dec 23 '12 at 11:06
  • you might want to consider ImageJ as well. It's the standard tool for image processing at least in life sciences. And it's all in the public domain. – carandraug Dec 24 '12 at 00:43

1 Answers1

0

Another possible path to consider would be Template matching

you just need to create a template image of a typical bubble.

This might be useful for identifying false positives identified by the Hough transform.

You will need to use template images of varying sizes for detecting different size bubbles.

Also, if you have a picture of the water from before the bubbles appeared, you can subtract this to find areas of the image that have bubbles.

sav
  • 2,064
  • 5
  • 25
  • 45