def emit_registered(self, values):
        id, image, classification = values
        registered_image, _ = [image, None
                               ] if id == 0 else afr.affine_registration(
                                   image, self.reference_image)

        features = skimage.filters.gaussian(registered_image -
                                            self.reference_image,
                                            sigma=2)[self.mask].flatten()
        self.log("registered image {} {}".format(id, features))
        self.emit([id, features, classification])
Beispiel #2
0
def _reg_prealign(row, force_recompute=False):
    prealign_file = _get_fname(row, '_reg_prealign.npy')
    if not op.exists(prealign_file) or force_recompute:
        moving = nib.load(_b0(row, force_recompute=force_recompute))
        static = dpd.read_mni_template()
        moving_data = moving.get_data()
        moving_affine = moving.affine
        static_data = static.get_data()
        static_affine = static.affine
        _, aff = reg.affine_registration(moving_data, static_data,
                                         moving_affine, static_affine)
        np.save(prealign_file, aff)
    return prealign_file
Beispiel #3
0
 def _reg_prealign(self, row):
     prealign_file = self._get_fname(row,
                                     '_prealign_from-DWI_to-MNI_xfm.npy')
     if self.force_recompute or not op.exists(prealign_file):
         moving = nib.load(self._b0(row))
         static = dpd.read_mni_template()
         moving_data = moving.get_fdata()
         moving_affine = moving.affine
         static_data = static.get_fdata()
         static_affine = static.affine
         _, aff = reg.affine_registration(moving_data, static_data,
                                          moving_affine, static_affine)
         np.save(prealign_file, aff)
         meta_fname = self._get_fname(row,
                                      '_prealign_from-DWI_to-MNI_xfm.json')
         meta = dict(type="rigid")
         afd.write_json(meta_fname, meta)
     return prealign_file
Beispiel #4
0
#
# .. note::
#     To find the right place for the waypoint ROIs, we calculate a non-linear
#     transformation between the individual's brain and the MNI T2 template.
#     Before calculating this non-linear warping, we perform a pre-alignment
#     using an affine transformation.

print("Registering to template...")
MNI_T2_img = afd.read_mni_template()

if not op.exists(op.join(working_dir, 'mapping.nii.gz')):
    import dipy.core.gradients as dpg
    gtab = dpg.gradient_table(hardi_fbval, hardi_fbvec)
    b0 = np.mean(img.get_fdata()[..., gtab.b0s_mask], -1)
    # Prealign using affine registration
    _, prealign = reg.affine_registration(b0, MNI_T2_img.get_fdata(),
                                          img.affine, MNI_T2_img.affine)

    # Then register using a non-linear registration using the affine for
    # prealignment
    warped_hardi, mapping = reg.syn_register_dwi(hardi_fdata,
                                                 gtab,
                                                 prealign=prealign)
    reg.write_mapping(mapping, op.join(working_dir, 'mapping.nii.gz'))
else:
    mapping = reg.read_mapping(op.join(working_dir, 'mapping.nii.gz'), img,
                               MNI_T2_img)

mapping_img = nib.load(op.join(working_dir, 'mapping.nii.gz'))
mapping_img_data = mapping_img.get_fdata()

# Working with diffeomorphic map data
Beispiel #5
0
#
#     To find the right place for the waypoint ROIs, we calculate a non-linear
#     transformation between the individual's brain DWI measurement (the b0
#     measurements) and the MNI T1 template.
#     Before calculating this non-linear warping, we perform a pre-alignment
#     using an affine transformation.

print("Registering to template...")

MNI_T1w_img = afd.read_mni_template(weight="T1w")

if not op.exists(op.join(working_dir, 'mapping.nii.gz')):
    import dipy.core.gradients as dpg
    gtab = dpg.gradient_table(hardi_fbval, hardi_fbvec)
    # Prealign using affine registration
    _, prealign = reg.affine_registration(apm, MNI_T1w_img.get_fdata(),
                                          img.affine, MNI_T1w_img.affine)

    # Then register using a non-linear registration using the affine for
    # prealignment
    warped_hardi, mapping = reg.syn_register_dwi(hardi_fdata,
                                                 gtab,
                                                 prealign=prealign)
    reg.write_mapping(mapping, op.join(working_dir, 'mapping.nii.gz'))
else:
    mapping = reg.read_mapping(op.join(working_dir, 'mapping.nii.gz'), img,
                               MNI_T1w_img)

##########################################################################
# Bundle specification
# -------------------------------------------
#