Hough circle does not detect eye iris

I want to detect eye irises and their centers using the Hough Circle algorithm.

I am using this code:

  private void houghCircle() { Bitmap obtainedBitmap = imagesList.getFirst(); /* convert bitmap to mat */ Mat mat = new Mat(obtainedBitmap.getWidth(),obtainedBitmap.getHeight(), CvType.CV_8UC1); Mat grayMat = new Mat(obtainedBitmap.getWidth(), obtainedBitmap.getHeight(), CvType.CV_8UC1); Utils.bitmapToMat(obtainedBitmap, mat); /* convert to grayscale */ int colorChannels = (mat.channels() == 3) ? Imgproc.COLOR_BGR2GRAY : ((mat.channels() == 4) ? Imgproc.COLOR_BGRA2GRAY : 1); Imgproc.cvtColor(mat, grayMat, colorChannels); /* reduce the noise so we avoid false circle detection */ Imgproc.GaussianBlur(grayMat, grayMat, new Size(9, 9), 2, 2); // accumulator value double dp = 1.2d; // minimum distance between the center coordinates of detected circles in pixels double minDist = 100; // min and max radii (set these values as you desire) int minRadius = 0, maxRadius = 1000; // param1 = gradient value used to handle edge detection // param2 = Accumulator threshold value for the // cv2.CV_HOUGH_GRADIENT method. // The smaller the threshold is, the more circles will be // detected (including false circles). // The larger the threshold is, the more circles will // potentially be returned. double param1 = 70, param2 = 72; /* create a Mat object to store the circles detected */ Mat circles = new Mat(obtainedBitmap.getWidth(), obtainedBitmap.getHeight(), CvType.CV_8UC1); /* find the circle in the image */ Imgproc.HoughCircles(grayMat, circles, Imgproc.CV_HOUGH_GRADIENT, dp, minDist, param1, param2, minRadius, maxRadius); /* get the number of circles detected */ int numberOfCircles = (circles.rows() == 0) ? 0 : circles.cols(); /* draw the circles found on the image */ for (int i=0; i<numberOfCircles; i++) { /* get the circle details, circleCoordinates[0, 1, 2] = (x,y,r) * (x,y) are the coordinates of the circle center */ double[] circleCoordinates = circles.get(0, i); int x = (int) circleCoordinates[0], y = (int) circleCoordinates[1]; Point center = new Point(x, y); int radius = (int) circleCoordinates[2]; /* circle outline */ Core.circle(mat, center, radius, new Scalar(0, 255, 0), 4); /* circle center outline */ Core.rectangle(mat, new Point(x - 5, y - 5), new Point(x + 5, y + 5), new Scalar(0, 128, 255), -1); } /* convert back to bitmap */ Utils.matToBitmap(mat, obtainedBitmap); MediaStore.Images.Media.insertImage(getContentResolver(),obtainedBitmap, "testgray", "gray" ); } 

But he does not detect the iris in all images correctly. Especially if the iris is dark in color, such as brown. How can I fix this code to correctly identify irises and their centers?

EDIT: Here are a few sample images (which I got from the Internet) that show the performance of the algorithm (please ignore the landmarks that are represented by red squares):

In these images, the algorithm does not detect all irises:

enter image description here

enter image description here

This image shows how the algorithm could not detect irises:

enter image description here

EDIT 2: Here is the code that uses Canny edge detection, but this causes the application to crash:

  private void houghCircle() { Mat grayMat = new Mat(); Mat cannyEdges = new Mat(); Mat circles = new Mat(); Bitmap obtainedBitmap = imagesList.getFirst(); /* convert bitmap to mat */ Mat originalBitmap = new Mat(obtainedBitmap.getWidth(),obtainedBitmap.getHeight(), CvType.CV_8UC1); //Converting the image to grayscale Imgproc.cvtColor(originalBitmap,grayMat,Imgproc.COLOR_BGR2GRAY); Imgproc.Canny(grayMat, cannyEdges,10, 100); Imgproc.HoughCircles(cannyEdges, circles, Imgproc.CV_HOUGH_GRADIENT,1, cannyEdges.rows() / 15); //now circles is filled with detected circles. //, grayMat.rows() / 8); Mat houghCircles = new Mat(); houghCircles.create(cannyEdges.rows(),cannyEdges.cols() ,CvType.CV_8UC1); //Drawing lines on the image for(int i = 0 ; i < circles.cols() ; i++) { double[] parameters = circles.get(0,i); double x, y; int r; x = parameters[0]; y = parameters[1]; r = (int)parameters[2]; Point center = new Point(x, y); //Drawing circles on an image Core.circle(houghCircles,center,r, new Scalar(255,0,0),1); } //Converting Mat back to Bitmap Utils.matToBitmap(houghCircles, obtainedBitmap); MediaStore.Images.Media.insertImage(getContentResolver(),obtainedBitmap, "testgray", "gray" ); } 

This is the error I get in the log

 FATAL EXCEPTION: Thread-28685 CvException [org.opencv.core.CvException: cv::Exception: /hdd2/buildbot/slaves/slave_ardbeg1/50-SDK/opencv/modules/imgproc/src/color.cpp:3739: error: (-215) scn == 3 || scn == 4 in function void cv::cvtColor(cv::InputArray, cv::OutputArray, int, int) ] at org.opencv.imgproc.Imgproc.cvtColor_1(Native Method) at org.opencv.imgproc.Imgproc.cvtColor(Imgproc.java:4598) 

What is caused by this line: Imgproc.cvtColor(originalBitmap,grayMat,Imgproc.COLOR_BGR2GRAY);

Can anyone tell me how this error can be resolved? Perhaps adding canny edge detection will improve the results.

+5
source share
3 answers

As you want to detect aperture using the hough transform (there are others), you better examine the Canny edge detector and its parameters. cv::HoughCircles accepts the Cyny hysteresis threshold in param1 . Exploring Canny alone, you get the impression of a good threshold range.

Perhaps, instead of Gaussian blur, you apply better noise reduction (not local means with say h=32 and window sizes 5 and 15), and try to match the image contrast, for example, using contrast adaptive histogram correction ( cv::CLAHE ).

Harmonization means that all eyes (backlight and shadow) are displayed in the same intensity range.

+2
source

I wanted to know if these images were processed by you images or if you want to take a snapshot of your cell phone on the screen to upload them here. Because irises are greater than the maximum radius set in the code. Therefore, I do not understand how you can find iris at all. Irises in the first image have a radius of more than 20. Thus, you will not be able to detect them. You must set the radii to the radius of the range that you expect from your irises.

+1
source

Too cool circles work better on well-defined circles. They are not good with things like the iris.

After some threshold value, morphological operations, or canny edge detection, object detection methods such as MSER work much better for iris detection.

Here is a similar question with a solution if you are looking for some kind of code.

+1
source

Source: https://habr.com/ru/post/1242598/


All Articles