Detecting Irregular Circles with Small Dots Inside in an Image using OpenCV (Android)

36 Views Asked by At

input image

Above is my image link"

I am working on an image processing task using OpenCV in Android, and I need assistance in detecting irregular circles within a rectangular bar.

The input image is in black and white, where each circle has small dots inside, and the circle border itself is white.

Image Structure:

  • The input image consists of a rectangular bar.
  • Irregular circles are present in both rows and columns within the bar.
  • Each circle has small dots inside it, and the circle border is white.

Processing Steps:

I have implemented the following steps, but the results are not as expected:

  • Convert the image to grayscale.
  • Apply GaussianBlur for smoothing.
  • Apply binary thresholding to separate black and white regions.
  • Find contours in the binary image.
  • Filter contours based on size and circularity criteria.

Challenges:

  • The current implementation does not reliably detect irregular circles.
  • Small dots inside the circles are not being identified.
ublic Bitmap detectIrregularCirclesWithDots(Bitmap inputBitmap) {
        // Convert Bitmap to Mat
        Mat image = new Mat();
        Utils.bitmapToMat(inputBitmap, image);

        // Convert image to grayscale
        Mat grayImage = new Mat();
        Imgproc.cvtColor(image, grayImage, Imgproc.COLOR_RGB2GRAY);

        // Smooth the image using GaussianBlur
        Imgproc.GaussianBlur(grayImage, grayImage, new Size(9, 9), 2, 2);

        // Apply binary thresholding
        Mat binaryImage = new Mat();
        Imgproc.threshold(grayImage, binaryImage, 128, 255, Imgproc.THRESH_BINARY);

        // Find contours
        List<MatOfPoint> contours = new ArrayList<>();
        Mat hierarchy = new Mat();
        Imgproc.findContours(binaryImage, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);

        // Filter contours based on size and circularity
        List<MatOfPoint> filteredContours = new ArrayList<>();
        for (MatOfPoint contour : contours) {
            double area = Imgproc.contourArea(contour);
            double perimeter = Imgproc.arcLength(new MatOfPoint2f(contour.toArray()), true);
            double circularity = 4 * Math.PI * area / (perimeter * perimeter);

            // Adjust these threshold values based on your specific requirements
            if (area > 100 && circularity > 0.7) {
                filteredContours.add(contour);

                // Draw the circle on the original image
                Imgproc.drawContours(image, Collections.singletonList(contour), -1, new Scalar(0, 255, 0), 2);
            }
        }

        // Convert Mat to Bitmap
        Bitmap outputBitmap = Bitmap.createBitmap(image.cols(), image.rows(), Bitmap.Config.ARGB_8888);
        Utils.matToBitmap(image, outputBitmap);
        return outputBitmap;
    }

Questions:

What additional steps can I take to improve the detection of irregular circles within the rectangular bar?

How can I adjust the parameters for better contour filtering and circularity estimation?

What techniques can be employed to reliably detect and analyze small dots inside the circles?

I appreciate any guidance, code suggestions, or insights that can help enhance the accuracy of the circle detection in this specific scenario.

0

There are 0 best solutions below