2

I am writing a program with OpenCV that detects circles in the structure pictures. I'm using the Watershed method described here.

There is a problem I faced: 3d structure photo is hardly converted into a binary picture (due to shadows and different depth), so the program can't spot circles. Here you can see my best results of processing 3d structures (2d are detected perfectly).

original

binary

processed

So, is there any way to process pictures of 3d structure and make it possible to convert it into an acceptable bin picture and process with watershed? Maybe I should use a completely different method?

My code:

import cv2
import numpy as np

im = cv2.imread('spheres1.bmp')
hsv = cv2.cvtColor(im, cv2.COLOR_BGR2HSV)
hsv_min = np.array((0, 0, 110), np.uint8)
hsv_max = np.array((0, 0, 255), np.uint8)
gray = hsv[:, :, 2]
gray = cv2.inRange(hsv, hsv_min, hsv_max)

bw = cv2.medianBlur(gray, 13)

#then I use Watershed algorithm
Bilal
  • 3,191
  • 4
  • 21
  • 49
  • 2
    that is an electron microscopy image, just to state the obvious. -- that *is* a tough picture to work with. no sharp edges, generally noisy, bubbles of varying size and shape, occluding each other... -- "cheap" methods won't work here. especially not anything presented in random blogs/youtube tutorials addressed to newbies. -- when in doubt, use AI. *maybe* instance segmentation could be trained to label each of these bubbles. – Christoph Rackwitz Dec 29 '21 at 22:19
  • Actually, the main goal of my program is not the spheres detection, I am just trying to save expert's time on matching structures. How many samples you think it is required to train and test AI with this method? – Dmitry Uspenskiy Dec 30 '21 at 03:47
  • can't say. dozens perhaps, depending on the network and if it's just tuned ("transfer learning") or trained from scratch (would be unreasonable). – Christoph Rackwitz Dec 30 '21 at 03:53
  • Have you tried [Hough circles](https://docs.opencv.org/master/da/d53/tutorial_py_houghcircles.html)? It may be able to do better at detecting circles in the background. – bfris Dec 30 '21 at 18:23
  • Yes, that was the first i've tried. It doesn't spot them due to overlays. – Dmitry Uspenskiy Dec 30 '21 at 18:44

0 Answers0