def display_all(self):
     plt.imshow(self.image_slice, cmap = plt.cm.gray)
     plt.show()
     
     plt.imshow(self.label_slice, cmap=plt.cm.gray)
     plt.show()
     
     print("Masked version: ")
     mask = np.where(self.label_slice == 0, self.label_slice, 
                     self.image_slice)
     plt.imshow(mask, cmap=plt.cm.gray)
     plt.show()
     
     show_eigenpatches(self.eigens_mask)
     
     plot_gabor(self.eigens_mask)
    def display_all(self):
        plt.imshow(self.image_slice, cmap=plt.cm.gray)
        plt.show()

        plt.imshow(self.label_slice, cmap=plt.cm.gray)
        plt.show()

        print("Masked version: ")
        mask = np.where(self.label_slice == 0, self.label_slice,
                        self.image_slice)
        plt.imshow(mask, cmap=plt.cm.gray)
        plt.show()

        show_eigenpatches(self.eigens_mask)

        plot_gabor(self.eigens_mask)
Example #3
0
    def save_report(self, path):
        save_fn = path + os.path.basename(self.filename)
        eigen_fn = show_eigenpatches(self.eigens_mask, save_fn)
        gabor_fn = plot_gabor(self.eigens_mask, save_fn)

        # base pdf
        plt.figure(figsize=(20, 28))

        plt.suptitle('Report: Slice ' + str(self.slice_no) + ' for ' +
                     self.filename + '\n',
                     fontsize=48)

        # prepare the mask
        mask = np.where(self.label_slice == 0, self.label_slice,
                        self.image_slice)

        # Saves a summary of the slice information as pdf
        with PdfPages(save_fn + '.pdf') as pdf:
            plt.subplot(2, 3, 1)
            plt.imshow(self.image_slice, cmap=plt.cm.gray)
            plt.xticks(())
            plt.yticks(())
            plt.title('Original Image', fontsize=24)

            plt.subplot(2, 3, 2)
            plt.imshow(mask, cmap=plt.cm.gray)
            plt.xticks(())
            plt.yticks(())
            plt.title('Mask', fontsize=24)

            plt.subplot(2, 3, 3)
            plt.imshow(plt.imread(eigen_fn))
            plt.xticks(())
            plt.yticks(())
            plt.title('Eigenpatches', fontsize=24)

            plt.subplot(2, 1, 2)
            plt.imshow(plt.imread(gabor_fn))
            plt.xticks(())
            plt.yticks(())
            plt.title('Gabor responses', fontsize=24)

            pdf.savefig()
            plt.close()
 def save_report(self, path):
     save_fn = path + os.path.basename(self.filename)
     eigen_fn = show_eigenpatches(self.eigens_mask, save_fn)   
     gabor_fn = plot_gabor(self.eigens_mask, save_fn)
     
     # base pdf
     plt.figure(figsize=(20, 28))
     
     plt.suptitle('Report: Slice ' + str(self.slice_no) + 
     ' for ' + self.filename + '\n', fontsize=48)
     
     # prepare the mask
     mask = np.where(self.label_slice == 0, self.label_slice, 
                     self.image_slice)
     
     # Saves a summary of the slice information as pdf 
     with PdfPages(save_fn + '.pdf') as pdf:
         plt.subplot(2, 3, 1)
         plt.imshow(self.image_slice, cmap = plt.cm.gray)
         plt.xticks(())
         plt.yticks(()) 
         plt.title('Original Image', fontsize=24)
         
         plt.subplot(2, 3, 2)
         plt.imshow(mask, cmap = plt.cm.gray)
         plt.xticks(())
         plt.yticks(())
         plt.title('Mask', fontsize=24)
         
         plt.subplot(2, 3, 3)
         plt.imshow(plt.imread(eigen_fn))
         plt.xticks(())
         plt.yticks(())
         plt.title('Eigenpatches', fontsize=24)
         
         plt.subplot(2, 1, 2)
         plt.imshow(plt.imread(gabor_fn))
         plt.xticks(())
         plt.yticks(())
         plt.title('Gabor responses', fontsize=24)
         
         pdf.savefig()
         plt.close()
def process(filename, filename_label, slice_no):
    
    # Grab the image
    image_slice, orientation_slice = get_nifti_slice(filename, slice_no)
    if SHOW_IMG:
        plt.imshow(image_slice, cmap = plt.cm.gray)
        plt.show()
    
    # Grab the labels
    label_slice, orientation_label = get_nrrd_data(filename_label, slice_no)
    if SHOW_IMG:
        plt.imshow(label_slice, cmap=plt.cm.gray)
        plt.show()

    # Show the mask
    if SHOW_IMG:
        print("Masked version: ")
        mask = np.where(label_slice == 0, label_slice, image_slice)
        plt.imshow(mask, cmap=plt.cm.gray)
        plt.show()   
    
    # Extract patches in ROI
    patches_mask, patches_nonmask = extract_roi_patches(image_slice, 
                                                        label_slice, 
                                                        PATCH_SIZE)
    
    # Get the decomposed patches
    eigens_mask = get_eigenpatches(patches_mask, PATCH_SIZE, MAX_EIGEN)
    eigens_nonmask = get_eigenpatches(patches_nonmask, PATCH_SIZE, MAX_EIGEN)
    
    # Show the eigens, if you want
    if SHOW_IMG:
        show_eigenpatches(eigens_mask)
        
    # Generate Gabor Kernels
    kernels = generate_kernels()
    
    # Show the Gabors
    if SHOW_IMG:
        plot_gabor(eigens_mask)

    # Store all the features and Gabor responses    
    all_features_mask = []
    all_powers_mask = []
    complete_features_mask = []
    
    all_features_nonmask = []
    all_powers_nonmask = []
    complete_features_nonmask = []
    
    for eigen in eigens_mask:
        all_features_mask.append(compute_feats(eigen, kernels))
        all_powers_mask.append(compute_powers(eigen, kernels))
    
    for eigen in eigens_nonmask:
        all_features_nonmask.append(compute_feats(eigen, kernels))
        all_powers_nonmask.append(compute_powers(eigen, kernels))
        
#    for patch in patches_mask:
#        complete_features_mask.append(compute_feats(patch, kernels))
#    
#    for patch in patches_nonmask:
#        complete_features_nonmask.append(compute_feats(patch, kernels))
        
        
    return SliceInfo(filename, slice_no, image_slice, orientation_slice, 
                     label_slice, orientation_label, kernels,
                     patches_mask, eigens_mask,
                     all_features_mask, all_powers_mask,
                     patches_nonmask, eigens_nonmask,
                     all_features_nonmask, all_powers_nonmask)
Example #6
0
def process(filename, filename_label, slice_no):

    # Grab the image
    image_slice, orientation_slice = get_nifti_slice(filename, slice_no)
    image_slice = normalise(image_slice)
    if SHOW_IMG:
        plt.imshow(image_slice, cmap=plt.cm.gray)
        plt.show()

    # Grab the labels
    label_slice, orientation_label = get_nrrd_data(filename_label, slice_no)
    #if SHOW_IMG:
    #    plt.imshow(label_slice, cmap=plt.cm.gray)
    #    plt.show()

    # Show the mask
    if SHOW_IMG:
        print("Masked version: ")
        mask = np.where(label_slice == 0, label_slice, image_slice)
        plt.imshow(mask, cmap=plt.cm.gray)
        plt.show()

    # Extract patches in ROI
    patches_mask, patches_nonmask = extract_roi_patches(
        image_slice, label_slice, PATCH_SIZE)

    # Get the decomposed patches
    eigens_mask = get_randoms(patches_mask, MAX_EIGEN)
    eigens_nonmask = get_randoms(patches_nonmask, MAX_EIGEN)

    # Show the eigens, if you want
    if SHOW_IMG:
        show_eigenpatches(eigens_mask)

    # Generate Gabor Kernels
    kernels = generate_kernels()

    # Show the Gabors
    if SHOW_IMG:
        plot_gabor(eigens_mask)

    # Store all the features and Gabor responses
    all_features_mask = []
    all_powers_mask = []

    all_features_nonmask = []
    all_powers_nonmask = []

    for eigen in eigens_mask:
        all_features_mask.append(compute_feats(eigen, kernels))
        all_powers_mask.append(compute_powers(eigen, kernels))

    for eigen in eigens_nonmask:
        all_features_nonmask.append(compute_feats(eigen, kernels))
        all_powers_nonmask.append(compute_powers(eigen, kernels))

    return SliceInfo(filename, slice_no, image_slice, orientation_slice,
                     label_slice, orientation_label, kernels, patches_mask,
                     eigens_mask, all_features_mask, all_powers_mask,
                     patches_nonmask, eigens_nonmask, all_features_nonmask,
                     all_powers_nonmask)