Beispiel #1
0
def figure1k3(info, path):
    if not os.path.exists(path):
        os.makedirs(path)

    sessions = info.groupby(level=['subject'])
    for subject, sinfo in sessions:
        fig = plt.figure()
        subjectpath = os.path.join(activitymovies.datafolder, subject)

        stepframes = []
        stinfo = sinfo[sinfo.protocol == 'stable']
        for key, group in stinfo.groupby(level=['session']):
            stact = activitytables.read_subjects(subjectpath, days=[key])
            stcr = activitytables.read_subjects(
                subjectpath, days=[key], selector=activitytables.crossings)
            stepframes += activitytables.stepframes(stact,
                                                    stcr,
                                                    group,
                                                    4,
                                                    3,
                                                    subtractBackground=True)
        stepframes = [
            cv2.threshold(f, 5, 255, cv2.cv.CV_THRESH_BINARY)[1]
            for f in stepframes
        ]
        stavg = imgproc.average(stepframes, 1)

        stepframes = []
        uinfo = sinfo[sinfo.protocol != 'stable']
        for key, group in uinfo.groupby(level=['session']):
            uact = activitytables.read_subjects(subjectpath, days=[key])
            ucr = activitytables.read_subjects(
                subjectpath, days=[key], selector=activitytables.crossings)
            stepframes += activitytables.stepframes(uact,
                                                    ucr,
                                                    group,
                                                    4,
                                                    3,
                                                    subtractBackground=True)
        stepframes = [
            cv2.threshold(f, 5, 255, cv2.cv.CV_THRESH_BINARY)[1]
            for f in stepframes
        ]
        uavg = imgproc.average(stepframes, 1)

        avg = cv2.merge((uavg, stavg, np.zeros(stavg.shape,
                                               dtype=stavg.dtype)))
        avg = avg.astype(np.uint8)
        avg = cv2.convertScaleAbs(avg, alpha=1.4, beta=0.0)
        plt.imshow(avg)
        plt.title(str.format('{0}', subject))
        fname = str.format("{0}_posture_stable_unstable.png", subject)
        fpath = os.path.join(path, fname)
        plt.axis("off")
        plt.savefig(fpath)
        plt.close(fig)
def figure1k2(info,path):
    if not os.path.exists(path):
        os.makedirs(path)
        
    sessions = info.groupby(level=['subject','session'])
    for (subject,session),sinfo in sessions:
        fig = plt.figure()
        subjectpath = os.path.join(activitymovies.datafolder,subject)
        sact = activitytables.read_subjects(subjectpath,days=[session])
        scr = activitytables.read_subjects(subjectpath,days=[session],
                                           selector = activitytables.crossings)
        stepframes = activitytables.stepframes(sact,scr,sinfo,4,3)
        side = int(np.ceil(np.sqrt(len(stepframes))))
        tile = imgproc.tile(stepframes,side,side)
        plt.imshow(tile[0], cmap = plt.cm.Greys_r)
        plt.title(str.format('{0} (session {1})',subject,session))
        fname = str.format("{0}_session_{1}_step_posture.png",
                           subject, session)
        fpath = os.path.join(path,subject)
        if not os.path.exists(fpath):
            os.makedirs(fpath)
        fpath = os.path.join(fpath,fname)
        plt.axis("off")
        plt.savefig(fpath)
        plt.close(fig)
Beispiel #3
0
def figure1k2(info, path):
    if not os.path.exists(path):
        os.makedirs(path)

    sessions = info.groupby(level=['subject', 'session'])
    for (subject, session), sinfo in sessions:
        fig = plt.figure()
        subjectpath = os.path.join(activitymovies.datafolder, subject)
        sact = activitytables.read_subjects(subjectpath, days=[session])
        scr = activitytables.read_subjects(subjectpath,
                                           days=[session],
                                           selector=activitytables.crossings)
        stepframes = activitytables.stepframes(sact, scr, sinfo, 4, 3)
        side = int(np.ceil(np.sqrt(len(stepframes))))
        tile = imgproc.tile(stepframes, side, side)
        plt.imshow(tile[0], cmap=plt.cm.Greys_r)
        plt.title(str.format('{0} (session {1})', subject, session))
        fname = str.format("{0}_session_{1}_step_posture.png", subject,
                           session)
        fpath = os.path.join(path, subject)
        if not os.path.exists(fpath):
            os.makedirs(fpath)
        fpath = os.path.join(fpath, fname)
        plt.axis("off")
        plt.savefig(fpath)
        plt.close(fig)
def figure1k3(info,path):
    if not os.path.exists(path):
        os.makedirs(path)
        
    sessions = info.groupby(level=['subject'])
    for subject,sinfo in sessions:
        fig = plt.figure()
        subjectpath = os.path.join(activitymovies.datafolder,subject)
        
        stepframes = []
        stinfo = sinfo[sinfo.protocol == 'stable']
        for key,group in stinfo.groupby(level=['session']):
            stact = activitytables.read_subjects(subjectpath,days=[key])
            stcr = activitytables.read_subjects(subjectpath,days=[key],
                                                selector = activitytables.crossings)
            stepframes += activitytables.stepframes(stact,stcr,group,4,3,
                                                    subtractBackground=True)
        stepframes = [cv2.threshold(f, 5, 255, cv2.cv.CV_THRESH_BINARY)[1]
                      for f in stepframes]
        stavg = imgproc.average(stepframes,1)
        
        stepframes = []
        uinfo = sinfo[sinfo.protocol != 'stable']
        for key,group in uinfo.groupby(level=['session']):
            uact = activitytables.read_subjects(subjectpath,days=[key])
            ucr = activitytables.read_subjects(subjectpath,days=[key],
                                                selector = activitytables.crossings)
            stepframes += activitytables.stepframes(uact,ucr,group,4,3,
                                                    subtractBackground=True)
        stepframes = [cv2.threshold(f, 5, 255, cv2.cv.CV_THRESH_BINARY)[1]
                      for f in stepframes]
        uavg = imgproc.average(stepframes,1)
        
        avg = cv2.merge((uavg,stavg,np.zeros(stavg.shape,dtype=stavg.dtype)))
        avg = avg.astype(np.uint8)
        avg = cv2.convertScaleAbs(avg,alpha=1.4,beta=0.0)
        plt.imshow(avg)
        plt.title(str.format('{0}',subject))
        fname = str.format("{0}_posture_stable_unstable.png", subject)
        fpath = os.path.join(path,fname)
        plt.axis("off")
        plt.savefig(fpath)
        plt.close(fig)
Beispiel #5
0
def _averageposture_(cract,info,cr,cropsize=(300,300)):

    stepframes = []
    for key,scr in cr.groupby(level=['subject','session']):
        sinfo = info.loc[[key],:]
        stepframes += activitytables.stepframes(cract,scr,sinfo,4,3,
                                                cropsize=cropsize,
                                                subtractBackground=True)
    stepframes = [cv2.threshold(f, 5, 255, cv2.cv.CV_THRESH_BINARY)[1]
                  for f in stepframes]
    return imgproc.average(stepframes,1)