1

粒子追跡に 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]
4

1 に答える 1

1

次のようなものを試してください:

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 is scripting の使用はできるだけ避けるべきです。ステート マシンが大きな問題を引き起こす可能性があります。

于 2014-05-06T19:52:18.800 に答える