0

I am trying to detect roi in my image dataset using Otsu thresholding. While in some cases results are on the point, some cases are not that good. I'm using the code below.

import cv2 as cv
import numpy as np

path  = "./images/{}.png".format

for num in range(1000):
    filename  = path(num)
    img       = cv.imread(filename, cv.IMREAD_GRAYSCALE)
    res       = cv.threshold(img, 0, 255, cv.THRESH_BINARY + cv.THRESH_OTSU)[1]
    res       = np.hstack((img, res))
    cv.imwrite(filename.replace(".png", "_.png"), res)

While these results are acceptable

enter image description here enter image description here

These definitely need to be improved

enter image description here enter image description here

How can I improve my code?

3
  • It's not clear what the output should be. Do you want the circle in the center only? Commented Oct 9, 2020 at 0:28
  • Detecting the center point is the first goal, also detecting other circles separately is what I'm trying to do. Second row shows overlapping circles which I don't want to have Commented Oct 9, 2020 at 0:43
  • Have you considered using an adaptive threshold? OpenCV has some implementations for it. Otherwise, I'd try spectral clustering. Commented Oct 9, 2020 at 3:23

1 Answer 1

1

I suggest using the GRIP software to implement two image processing pipelines: One that performs thresholding to find the center point and another to find all the other circles.
These pipelines can then be generated to Python OpenCV code and you can import them into your code (which I have already done for you).

Here is the center point pipeline: It performs a simle HSV threshold followed by a find blob command
Center_Pipeline


Here is the circle pipeline:
It performs a Laplacian transform (which is a one-sided Fourier Transform to detects the contrast changes which represent the edges of the circles), then Canny edge detection to find the edges of the circles, and then finds and filters the contours of the circles. To find the number of circle, you can divide the number of contours by 2 (inner and outer circle associated with each Laplacian ring) Ring_Pipeline


Here is the link to download the GRIP software

Here is a link to all my files (including the auto-generated Python image processing pipeline)

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot, I haven't try it yet but both those pipelines and the software seem like they can help me greatly

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.