def _generate_report(self): """Generate the visual report.""" from nilearn.image import threshold_img, load_img from nilearn.masking import apply_mask, unmask from niworkflows.viz.utils import plot_registration NIWORKFLOWS_LOG.info("Generating visual report") fixed_image_nii = load_img(self._fixed_image) moving_image_nii = load_img(self._moving_image) contour_nii = load_img( self._contour) if self._contour is not None else None if self._fixed_image_mask: fixed_image_nii = unmask( apply_mask(fixed_image_nii, self._fixed_image_mask), self._fixed_image_mask, ) # since the moving image is already in the fixed image space we # should apply the same mask moving_image_nii = unmask( apply_mask(moving_image_nii, self._fixed_image_mask), self._fixed_image_mask, ) mask_nii = load_img(self._fixed_image_mask) else: mask_nii = threshold_img(fixed_image_nii, 1e-3) n_cuts = 7 if not self._fixed_image_mask and contour_nii: cuts = cuts_from_bbox(contour_nii, cuts=n_cuts) else: cuts = cuts_from_bbox(mask_nii, cuts=n_cuts) # Call composer compose_view( plot_registration( fixed_image_nii, "fixed-image", estimate_brightness=True, cuts=cuts, label=self._fixed_image_label, contour=contour_nii, compress=self.inputs.compress_report, dismiss_affine=self._dismiss_affine, ), plot_registration( moving_image_nii, "moving-image", estimate_brightness=True, cuts=cuts, label=self._moving_image_label, contour=contour_nii, compress=self.inputs.compress_report, dismiss_affine=self._dismiss_affine, ), out_file=self._out_report, )
def _generate_report(self): """ Generates the visual report """ from niworkflows.viz.utils import plot_registration NIWORKFLOWS_LOG.info('Generating visual report') anat = load_img(self._anat_file) contour_nii = load_img(self._contour) if self._contour is not None else None if self._mask_file: anat = unmask(apply_mask(anat, self._mask_file), self._mask_file) mask_nii = load_img(self._mask_file) else: mask_nii = threshold_img(anat, 1e-3) n_cuts = 7 if not self._mask_file and contour_nii: cuts = cuts_from_bbox(contour_nii, cuts=n_cuts) else: cuts = cuts_from_bbox(mask_nii, cuts=n_cuts) # Call composer compose_view( plot_registration(anat, 'fixed-image', estimate_brightness=True, cuts=cuts, contour=contour_nii, compress=self.inputs.compress_report), [], out_file=self._out_report )
def _generate_report(self): """Generates the visual report.""" from niworkflows.viz.utils import plot_registration NIWORKFLOWS_LOG.info("Generating visual report") anat = load_img(self._anat_file) contour_nii = load_img( self._contour) if self._contour is not None else None if self._mask_file: anat = unmask(apply_mask(anat, self._mask_file), self._mask_file) mask_nii = load_img(self._mask_file) else: mask_nii = threshold_img(anat, 1e-3) n_cuts = 7 if not self._mask_file and contour_nii: cuts = cuts_from_bbox(contour_nii, cuts=n_cuts) else: cuts = cuts_from_bbox(mask_nii, cuts=n_cuts) # Call composer compose_view( plot_registration( anat, "fixed-image", estimate_brightness=True, cuts=cuts, contour=contour_nii, compress=self.inputs.compress_report, ), [], out_file=self._out_report, )
def _run_interface(self, runtime): from niworkflows.viz.utils import ( plot_registration, cuts_from_bbox, compose_view, ) from nibabel import load rootdir = Path(self.inputs.subjects_dir) / self.inputs.subject_id _anat_file = str(rootdir / "mri" / "brain.mgz") _contour_file = str(rootdir / "mri" / "ribbon.mgz") anat = load(_anat_file) contour_nii = load(_contour_file) n_cuts = 7 cuts = cuts_from_bbox(contour_nii, cuts=n_cuts) self._results["out_report"] = str(Path(runtime.cwd) / self.inputs.out_report) # Call composer compose_view( plot_registration( anat, "fixed-image", estimate_brightness=True, cuts=cuts, contour=contour_nii, compress=self.inputs.compress_report, ), [], out_file=self._results["out_report"], ) return runtime
def _run_interface(self, runtime): from niworkflows.viz.utils import plot_registration, cuts_from_bbox, compose_view from nilearn.image import load_img rootdir = Path(self.inputs.subjects_dir) / self.inputs.subject_id _anat_file = str(rootdir / 'mri' / 'brain.mgz') _contour_file = str(rootdir / 'mri' / 'ribbon.mgz') anat = load_img(_anat_file) contour_nii = load_img(_contour_file) n_cuts = 7 cuts = cuts_from_bbox(contour_nii, cuts=n_cuts) self._results['out_report'] = str( Path(runtime.cwd) / self.inputs.out_report) # Call composer compose_view(plot_registration(anat, 'fixed-image', estimate_brightness=True, cuts=cuts, contour=contour_nii, compress=self.inputs.compress_report), [], out_file=self._results['out_report']) return runtime
def _generate_report(self): """ Generates the visual report """ from niworkflows.viz.utils import plot_registration NIWORKFLOWS_LOG.info('Generating visual report') fixed_image_nii = load_img(self._fixed_image) moving_image_nii = load_img(self._moving_image) contour_nii = load_img(self._contour) if self._contour is not None else None if self._fixed_image_mask: fixed_image_nii = unmask(apply_mask(fixed_image_nii, self._fixed_image_mask), self._fixed_image_mask) # since the moving image is already in the fixed image space we # should apply the same mask moving_image_nii = unmask(apply_mask(moving_image_nii, self._fixed_image_mask), self._fixed_image_mask) mask_nii = load_img(self._fixed_image_mask) else: mask_nii = threshold_img(fixed_image_nii, 1e-3) n_cuts = 7 if not self._fixed_image_mask and contour_nii: cuts = cuts_from_bbox(contour_nii, cuts=n_cuts) else: cuts = cuts_from_bbox(mask_nii, cuts=n_cuts) # Call composer compose_view( plot_registration(fixed_image_nii, 'fixed-image', estimate_brightness=True, cuts=cuts, label=self._fixed_image_label, contour=contour_nii, compress=self.inputs.compress_report), plot_registration(moving_image_nii, 'moving-image', estimate_brightness=True, cuts=cuts, label=self._moving_image_label, contour=contour_nii, compress=self.inputs.compress_report), out_file=self._out_report )
def _run_interface(self, runtime): fixed_img = load_img(self.inputs.fixed_img) moving_img = load_img(self.inputs.moving_img) mask = load_img(self.inputs.mask_img) out_dir = os.path.realpath(self.inputs.out_dir) cuts = cuts_from_bbox(mask, self.inputs.cuts) _, fname, _ = split_filename(self.inputs.moving_img) compose_view(plot_registration(fixed_img, 'fixed-image', estimate_brightness=True, cuts=cuts, label='fixed'), plot_registration(moving_img, 'moving-image', estimate_brightness=True, cuts=cuts, label='moving'), out_file=os.path.join(out_dir, (fname + '_vizQC.svg'))) return runtime
def make_registration(*, moving, fixed, mask, out_file): """ Creates `out_file`.svg of registration between `moving` and `fixed` Parameters ---------- moving : str Path to file that was registered to `fixed` fixed : str Path to file that `moving` was registered to mask : str Path to brain mask file out_file : str Path to where svg will be saved Returns ------- out_file : str Where svg was saved """ if not out_file.endswith('.svg'): out_file += '.svg' cuts = cuts_from_bbox(nib.load(mask), cuts=7) compose_view( plot_registration(nib.load(fixed), 'fixed-image', estimate_brightness=True, cuts=cuts, label='fixed'), plot_registration(nib.load(moving), 'moving-image', estimate_brightness=True, cuts=cuts, label='moving'), out_file=out_file ) return out_file