Beispiel #1
0
def random_snips(image, r, n_snips):
    #Arguments -->
    #image   : 3D array for snipping. (Note: It must be MNI registered.)
    #r       : radius of the snipped image(in pixels)
    #n_snips : no of snips to be generated
    from random import randint
    import numpy as np
    import os
    cur_path = os.getcwd()
    indexes = []
    snips = []
    #import sys, os
    #sys.path.append(os.path.)
    from pfca.core.preprocessing import mni_template_registration
    harvard_mni = mni_template_registration(cur_path, harvard_atlas, 'harvard')
    harvard_mask = (harvard_mni.numpy() > 0) * 1
    indices = np.asarray(np.where(harvard_mask == 1)).T
    n_indices = len(indices)
    for i in range(n_snips):
        t = randint(0, n_indices)
        tmp_pt = indices[t]
        indexes.append(tmp_pt)
        tmp_snip = image[tmp_pt[0] - r:tmp_pt[0] + r,
                         tmp_pt[1] - r:tmp_pt[1] + r,
                         tmp_pt[2] - r:tmp_pt[2] + r]
        snips.append(tmp_snip)
    return snips, indexes
Beispiel #2
0
 def disp_roi(self, patient):
     import pandas as pd
     import numpy as np
     from pfca.exp.results import draw_roi
     from pfca.core.preprocessing import nifti_ANTS, mni_template_registration
     from pfca import init_path
     import os
     raw_dir, nifti_dir = init_path()
     cur_path = os.getcwd()
     k = self.dataset
     im_nifti = nifti_ANTS(nifti_dir,
                           patient,
                           category='eswan',
                           unskulled=True)
     im_patient = mni_template_registration(cur_path, im_nifti, patient)
     patient_data = k.loc[k['patient_name'] == patient]
     peaks = patient_data['RST_peak'].tolist()
     draw_roi(im_patient, peaks, 5)
Beispiel #3
0
def store_results(dataset, r, folder_name):
    d = dataset  #Writing so long names is not cool enough
    ###First make a folder for storing all the images
    from pfca import init_path
    import os
    from skimage.draw import rectangle_perimeter
    import matplotlib.patches as mpathches
    from pfca.core.preprocessing import nifti_ANTS, mni_template_registration
    cur_path = os.getcwd()
    raw_dir, nifti_dir = init_path()
    snips_dir = str(cur_path) + "/visuals/RST_snips/" + folder_name + "/"
    try:
        os.makedirs(snips_dir)
    except FileExistsError:
        print("Directory Exists!")
    ############
    #Moving to the important stuff...Get Data...
    #peaks = d['RST_peak'].tolist()
    ###########
    from matplotlib import pyplot as plt
    for i in range(len(d)):
        plt.figure(figsize=(12, 14))
        p = (d.iloc[i]['RST_peak']).tolist()
        patient = d.iloc[i]['patient_name']
        im_nifti = nifti_ANTS(nifti_dir,
                              patient,
                              category='eswan',
                              unskulled=True)
        image = mni_template_registration(cur_path, im_nifti, patient)
        temp = image[:, :, p[2]]
        plt.imshow(temp, cmap=plt.get_cmap('gray'))
        plt.title("Patient : " + patient + "; " + "Coordinate : " + str(p))
        ax = plt.gca()
        rect = mpathches.Rectangle((p[1] - r, p[0] - r),
                                   2 * r,
                                   2 * r,
                                   fill=False,
                                   edgecolor='red',
                                   linewidth=1)
        ax.add_patch(rect)
        #ax.set_axis_off()
        plt.savefig(snips_dir + patient + "_" + str(i) + ".png")
        plt.close()