示例#1
0
def main():
    subject = ipmi.get_unsegmented_subjects()[0]
    ref_path = subject.t1_path
    flo_path = Path('template_on_00_affine.nii.gz')
    if not flo_path.is_file():
        template_path = template.get_final_template().template_image_path
        trsf_path = subject.template_to_t1_affine_path
        reg.resample(template_path, ref_path, trsf_path, flo_path)

    bending_energies = np.logspace(-3, -1, 10)

    for be in bending_energies:
        # Register
        command = (f'reg_f3d -ref {ref_path} -flo {flo_path} '
                   f'-cpp cpp_be_{be:.5f}.nii.gz '
                   f'-res res_be_{be:.5f}.nii.gz -be {be}'.split())
        call(command)

        # Jacobian
        command = (
            f'reg_jacobian -ref {ref_path} '
            f'-trans cpp_be_{be:.5f}.nii.gz -jac jac_be_{be:.5f}.nii.gz '
            f'-jacL jacL_be_{be:.5f}.nii.gz'.split())
        call(command)

        # Jacobian label maps for 3D Slicer
        make_label_map(f'jacL_be_{be:.5f}.nii.gz', 0,
                       f'jacL_be_{be:.5f}_label_map.nii.gz')
        make_label_map(f'jac_be_{be:.5f}.nii.gz', 1,
                       f'jac_be_{be:.5f}_label_map.nii.gz')

        reg.spline_to_displacement_field(f'{ref_path}',
                                         f'cpp_be_{be:.5f}.nii.gz',
                                         f'cpp_be_{be:.5f}_disp.nii.gz')
import csv

import numpy as np
from scipy.stats import pearsonr

import ipmi
from ipmi.constants import GREY_MATTER, WHITE_MATTER, BRAIN

def compute_and_write_row(writer, x, y, name):
    cc, p = pearsonr(x, y)
    writer.writerow(
        {'Measurement': name, 'Pearson CC': f'{cc:.2f}', 'p': f'{p:.3f}'})


if __name__ == '__main__':
    subjects = ipmi.get_unsegmented_subjects()
    ages = [subject.age for subject in subjects]
    volumes_tuples = [subject.get_volumes_normalised() for subject in subjects]

    gms = np.array([tup.volumes[GREY_MATTER] for tup in volumes_tuples])
    wms = np.array([tup.volumes[WHITE_MATTER] for tup in volumes_tuples])
    brains = np.array([tup.volumes[BRAIN] for tup in volumes_tuples])
    gms_norm = [tup.normalised_volumes[GREY_MATTER] for tup in volumes_tuples]
    wms_norm = [tup.normalised_volumes[WHITE_MATTER] for tup in volumes_tuples]
    brains_norm = [tup.normalised_volumes[BRAIN] for tup in volumes_tuples]

    csv_path = ipmi.path.correlations_report_path

    with open(str(csv_path), 'w') as csvfile:
        fieldnames = 'Measurement', 'Pearson CC', 'p'
        writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
示例#3
0
 def __init__(self):
     self.subjects = ipmi.get_segmented_subjects()
     self.subjects.extend(ipmi.get_unsegmented_subjects())