Beispiel #1
0
 def extractArray(self, path, targetShape):
     X_direct = []
     y = []
     l = len(glob(path + '/*'))
     numbact = 0
     printProgressBar(0,
                      l,
                      prefix='Progress:',
                      suffix='Complete',
                      length=50)
     for i, im_path in enumerate(glob(path + '/*')):
         printProgressBar(i + 1,
                          l,
                          prefix='Progress:',
                          suffix='Complete',
                          length=50)
         init = np.float32(cv2.imread(im_path, 0))
         resized = cv2.resize(init,
                              targetShape,
                              interpolation=cv2.INTER_LINEAR)
         X_direct.append(resized)
         if self.labeled:
             if 'NORMAL' in im_path:
                 y.append(0)
             elif 'bacteria' in im_path:
                 y.append(1)
                 numbact += 1
             else:
                 y.append(2)
     percentBact = numbact / len(X_direct)
     print("Percent Bact", percentBact)
     X_direct = np.stack(X_direct, axis=0) / 255
     return X_direct, np.asarray(y)
Beispiel #2
0
def compute_motion(cls, time_subsampling=5, with_ProgressBar=False):
    """

    """
    frames = np.arange(cls.nframes)[::time_subsampling]
    motion = np.zeros(len(frames) - 1)

    if with_ProgressBar:
        printProgressBar(0, cls.nframes)

    for i, frame in enumerate(frames[:-1]):
        imgs = load_ROI_data(cls, frame, frame + 2, flatten=True)
        motion[i] = np.mean(np.diff(imgs, axis=0)**2)

        if with_ProgressBar and (i % 20 == 0):
            printProgressBar(frame, cls.nframes)

    return frames[1:], motion
Beispiel #3
0
def perform_loop(parent,
                 subsampling=1000,
                 shape='ellipse',
                 gaussian_smoothing=0,
                 saturation=100,
                 with_ProgressBar=False):

    temp = {}  # temporary data in case of subsampling
    for key in [
            'frame', 'cx', 'cy', 'sx', 'sy', 'diameter', 'residual', 'angle'
    ]:
        temp[key] = []

    if with_ProgressBar:
        printProgressBar(0, parent.nframes)

    for parent.cframe in list(
            range(parent.nframes - 1)[::subsampling]) + [parent.nframes - 1]:
        # preprocess image
        img = preprocess(parent,
                         gaussian_smoothing=gaussian_smoothing,
                         saturation=saturation,
                         with_reinit=False)

        coords, _, res = perform_fit(parent,
                                     saturation=saturation,
                                     shape=shape)
        if shape == 'circle':
            coords = list(coords) + [coords[-1]]  # form circle to ellipse
        temp['frame'].append(parent.cframe)
        temp['residual'].append(res)
        for key, val in zip(['cx', 'cy', 'sx', 'sy', 'angle'], coords):
            temp[key].append(val)
        temp['diameter'].append(np.pi * coords[2] * coords[3])
        if with_ProgressBar:
            printProgressBar(parent.cframe, parent.nframes)
    if with_ProgressBar:
        printProgressBar(parent.nframes, parent.nframes)

    print('Pupil size calculation over !')

    for key in temp:
        temp[key] = np.array(temp[key])
    temp['blinking'] = np.zeros(len(temp['cx']), dtype=np.uint)

    return temp