Image processing to size bubbles in octave

耗尽温柔 提交于 2020-01-02 08:45:12

问题


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.

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): Binary threshold: Circle 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;
 }

回答1:


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.



来源:https://stackoverflow.com/questions/14007913/image-processing-to-size-bubbles-in-octave

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!