San*_*der 13 python image-processing
我的问题与识别图片中的颜色有关.做微生物学我需要计算用显微镜照相机拍摄的照片上存在的细胞核数量.我用GIMP用红色点标记原子核.现在我需要在python中创建一个脚本,给出一个图像,它会告诉我有多少个红点.除了点之外,图片中没有红色.
我想到了一个相当复杂的解决方案,可能不是最好的解决方案:拍照并开始迭代检查每个颜色的像素.如果是红色,请检查所有8个最近的像素,再次递归检查每个红色的邻居,直到找不到更多相邻的红色像素.然后将核数增加1并标记遍历的像素,这样它们就不会再次迭代.然后从停止的地方继续迭代.看起来有点沉重所以我想我会问,也许有人已经更优雅地处理了类似的问题.
此致,桑德
jfs*_*jfs 13
该代码改编自Python Image Tutorial.使用教程中的核输入图像:

#!/usr/bin/env python
import scipy
from scipy import ndimage
# read image into numpy array
# $ wget http://pythonvision.org/media/files/images/dna.jpeg
dna = scipy.misc.imread('dna.jpeg') # gray-scale image
# smooth the image (to remove small objects); set the threshold
dnaf = ndimage.gaussian_filter(dna, 16)
T = 25 # set threshold by hand to avoid installing `mahotas` or
       # `scipy.stsci.image` dependencies that have threshold() functions
# find connected components
labeled, nr_objects = ndimage.label(dnaf > T) # `dna[:,:,0]>T` for red-dot case
print "Number of objects is %d " % nr_objects
# show labeled image
####scipy.misc.imsave('labeled_dna.png', labeled)
####scipy.misc.imshow(labeled) # black&white image
import matplotlib.pyplot as plt
plt.imsave('labeled_dna.png', labeled)
plt.imshow(labeled)
plt.show()
Number of objects is 17 

我会这样做:
评论:它不会是最快的,也不会总是准确的。但这会很有趣 - 因为简历总是很有趣 - 并且只需 10 行代码即可完成。只是一个松散的想法。
至于更多可用于生产的建议:
但最优雅的解决方案就是对 GIMP 中标记的核进行计数,正如 Ocaso Protal 上面所建议的那样。准确且最快。其他一切都容易出错,而且速度要慢得多,因此我的只是松散的想法,比任何事情都更有趣。