我正在尝试使用trackpy (以下简称tp)进行粒子跟踪。我有一系列细胞样本的图像。自然,图像中有一些噪声。跟踪的第一步是从序列的第一张图像中选择哪些集群是细胞,哪些集群不是细胞。这很大程度上是由tp.locate完成的。这并不完美。我希望能够浏览一下tp.locate选择的“候选”,并指出每个候选是一个单元还是不是一个单元。
为此,我创建了函数ID。我们的目标是浏览tp.locate生成的“候选人”列表。我想通过显示(通过matplotlib的imshow函数)每个“候选人”,同时提示用户输入“候选人”是否是一个单元格来实现这一点。
问题是,请求用户输入似乎会抑制imshow函数的输出。每次通过for循环都会询问一个不同的候选对象,但imshow窗口实际上从未显示过该候选对象。我不知道如何解决这个问题,我觉得我离我的最终目标已经很近了,所以我真的很感谢大家的意见。
我不需要GUI,但是有没有什么方法可以让我用tkinter来处理这个问题呢?我不熟悉tkinter,但我读过一些东西,使我认为我可以用它来解决这个问题。
import numpy as np
import matplotlib.pyplot as plt
def framer(f,image,windowsize=(60,100)):
arr = image[:,:] #This makes a copy of image, so that when the buffers are
#added for the following process, the input image (image)
#is not modified.
h = windowsize[0]
w = windowsize[1]
hbuffer = np.zeros((h/2,arr.shape[1]))
arr = np.concatenate((hbuffer,arr,hbuffer),axis=0) #Buffer takes care of situations
#where the crop window extends
#beyond input image dimensions
wbuffer = np.zeros((arr.shape[0],w/2))
arr = np.concatenate((wbuffer,arr,wbuffer),axis=1)
narr = np.zeros((f.shape[0],h,w)) #Initialize array of crop windows
for i in range(f.shape[0]):
crop_arr = arr[f.get_value(i,'y'):f.get_value(i,'y') + h,f.get_value(i,'x'):f.get_value(i,'x') + w] #THIS MIGHT BE BACKWARDS
narr[i] = crop_arr
return narr
def ID(f,image,windowsize=(60,100)):
arr = framer(f,image,windowsize=(60,100))
f_cop = f[:]
reslist = np.zeros((arr.shape[0]))
for i in range(arr.shape[0]):
plt.imshow(arr[i],cmap='gray')
plt.annotate('particle '+repr(i),xy=(f.get_value(i,'x'),\
f.get_value(i,'y')),xytext=(f.get_value(i,'x')+20,f.get_value(i,'y')+20),\
arrowprops=dict(facecolor='red', shrink=0.05),fontsize=12,color='r')
res = input('Is this a cell? 1 for yes, 0 for no, 5 to exit')
if res == 1 or res == 0:
reslist[i] = res
if res == 5:
break
else:
print('Must give a valid input! (0,1 or 5)')
f_cop['res'] = reslist
return f_cop[f_cop.res == 1]发布于 2014-05-07 03:52:19
尝试如下所示:
fig, ax = plt.subplots(1, 1)
for i in range(arr.shape[0]):
ax.cla()
im = ax.imshow(arr[i], cmap='gray', interpolation='nearest')
plt.annotate('particle ' + repr(i), xy=(f.get_value(i, 'x'), f.get_value(i,'y')),
xytext=(f.get_value(i,'x')+20, f.get_value(i,'y')+20),
arrowprops=dict(facecolor='red', shrink=0.05),
fontsize=12,color='r')
fig.canvas.draw()
res = None
while res not in (0, 1, 5):
res = input('Is this a cell? 1 for yes, 0 for no, 5 to exit')
if res == 1 or res == 0:
reslist[i] = res
elif res == 5:
break
else:
print "should never get here"你应该尽量避免使用pyplot是脚本,状态机会给你带来很大的麻烦。
https://stackoverflow.com/questions/23501357
复制相似问题