0

Since i'm relatively new to image analyses, i'm having some questions about the separation of overlapping objects using scikit image (not cv2). With the code below I try to illustrate all the 11 coins with different colors:

from skimage.measure import label, regionprops
from skimage.morphology import remove_small_objects
from skimage.color import label2rgb
from skimage import filters
import math

im = im_coin = io.imread("test1.png") 
im = im.astype(float)
im = im-im.min()
im = im/im.max()
block_size = 201
imbw1 = im > filters.threshold_local(im, block_size, method = 'mean')

imbw1 = remove_small_objects(imbw1, 1000, connectivity=1)

label_img = label(imbw1)
image_label_overlay = label2rgb(label_img, image=im, bg_label = 0)

regions = regionprops(label_img)

plt.figure(figsize=(8,8))
plt.imshow(image_label_overlay, cmap=plt.cm.gray)

for (i, props) in zip(range(len(regions)), regions):  
    y1, x1 = props.centroid
    plt.text(x1, y1,(i + 1),color='w')
    
plt.axis('off') 

As you can see in the result below, the coins have different colors. However, coins with the number 5 and 7 should be separated into multiple single coins.The output then should be 11 individual coins with 11 different colors. The question is: can someone help me with the code to separate those overlapping coins.

result

This is the orginal image if you want to use it for the code: enter image description here

  • take a look at [Hough circles](https://scikit-image.org/docs/stable/auto_examples/edges/plot_circular_elliptical_hough_transform.html). with this you should be able to detect the different coins even if they overlap –  Mar 22 '22 at 14:59
  • Yes! Detecting is possible, but with the code in your example I can only detect the circles. I'm not sure how to put it in my code above. Suggestions? – Paul Engelbert Mar 22 '22 at 16:52
  • once you know the center and radius of each circle you can calculate the two intersection points between two circles. a line between this two points will split them, so if you assign the pixels of this line to 0 it will split the circles. you can also [skeletokize](https://scikit-image.org/docs/dev/api/skimage.morphology.html#medial-axis) the circles, so separating them is easier. take a look at https://link.springer.com/article/10.1007/s10044-020-00951-z –  Mar 22 '22 at 16:58
  • Thanks, I asked a follow up question right here: https://stackoverflow.com/questions/71583950/from-hough-circle-detection-to-coin-separation . Maybe you can help me answer it. Quite a newby at this moment – Paul Engelbert Mar 25 '22 at 07:53

0 Answers0