简体   繁体   English

如何从我的png图像中分离出每个白色斑点?

[英]How to separate each white blob from my png images?

I am given a png image which is strictly two colours: Black and White . 我得到的png图片严格是两种颜色: Black and White More specifically it has a black background and some white marks (we call blobs). 更具体地说,它具有黑色背景和一些白色标记(我们称为斑点)。 Each image has about 30 to 50 such blobs. 每个图像都有大约30到50个这样的斑点。 Our task is to generate those 30 to 50 sperate images from our given image, with each having one blob . 我们的任务是从给定的图像中生成30到50张精子图像,每个图像都有一个blob。

For example, we have a given image: 例如,我们有一个给定的图像:

原始图片

We need to convert them into: 我们需要将它们转换为:

1号

2号

3号

And so on with all the blobs. 以此类推。 Please guide me on how to do it, I am comfortable with all standard image processing libraries in python. 请指导我如何做,我对python中的所有标准图像处理库都感到满意。

I think you are looking for scipy.ndimage.measurements.label : 我认为您正在寻找scipy.ndimage.measurements.label

from scipy.ndimage.measurements import label

lb = label(my_bw_image)
msks = []
for li in xrange(1, lb.max()+1):
    msks.append(lb==li)

You should have all your masks in msks list. 您应该将所有口罩都放在msks列表中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM