1 year ago

#321731

test-img

Paul Engelbert

How to separate overlapping objects in image using scikit-image?

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

python

image

scikit-image

overlapping

region

0 Answers

Your Answer

Accepted video resources