Exemplo n.º 1
0
 def _generate_report(self):
     from niworkflows.viz.utils import plot_segs
     plot_segs(image_nii=self._anat_file,
               seg_niis=self._seg_files,
               mask_nii=self._mask_file,
               out_file=self.inputs.out_report,
               masked=self._masked,
               title=self._report_title,
               compress=self.inputs.compress_report)
Exemplo n.º 2
0
    def _generate_report(self):
        '''
        Construct a parcellation overlay image
        '''
        import niworkflows.viz.utils as nwviz
        from ..patches.niworkflows import _3d_in_file, _plot_anat_with_contours
        '''
        MONKEY PATCH:
        _3d_in_file in niworkflows.viz.utils cannot accept Nifti1Images
        as inputs.

        This is a small patch that will stop it from failing when this is
        the case
        '''

        # _3d_in_file more robust to accepting a Nifti1Image
        nwviz._3d_in_file = _3d_in_file

        # plot_anat_with_contours accepts filled
        nwviz._plot_anat_with_contours = _plot_anat_with_contours

        segs = _parcel2segs(self._parcellation)
        nwviz.compose_view(
            nwviz.plot_segs(
                image_nii=self._bg_nii,
                seg_niis=segs,
                bbox_nii=self._mask_nii,
                out_file=None,  # this arg doesn't matter
                colors=self._colors,
                filled=True,
                alpha=0.3),
            fg_svgs=None,
            out_file=self._out_report)
Exemplo n.º 3
0
def make_brain(*, anatomical, mask, out_file):
    """
    Creates `out_file`.svg of brain `mask` on input `anatomical`

    Parameters
    ----------
    anatomical : str
        Path to anatomical T1w image (*with skull*)
    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'

    compose_view(
        plot_segs(image_nii=anatomical,
                  seg_niis=[mask],
                  bbox_nii=mask,
                  out_file='reports.svg',
                  masked=False,
                  compress='auto'),
        fg_svgs=None,
        out_file=out_file
    )

    return out_file
Exemplo n.º 4
0
 def _generate_report(self):
     from niworkflows.viz.utils import plot_segs
     compose_view(plot_segs(image_nii=self._anat_file,
                            seg_niis=self._seg_files,
                            bbox_nii=self._mask_file,
                            out_file=self.inputs.out_report,
                            masked=self._masked,
                            compress=self.inputs.compress_report),
                  fg_svgs=None,
                  out_file=self._out_report)
Exemplo n.º 5
0
    def _generate_report(self):
        from seaborn import color_palette
        from niworkflows.viz.utils import plot_segs, compose_view

        seg_files = self.inputs.in_rois
        mask_file = None if not isdefined(self.inputs.in_mask) else self.inputs.in_mask

        # Remove trait decoration and replace None with []
        levels = [level for level in self.inputs.levels or []]
        colors = [c for c in self.inputs.colors or []]

        if len(seg_files) == 1:  # in_rois is a segmentation
            nsegs = len(levels)
            if nsegs == 0:
                levels = np.unique(
                    np.round(nb.load(seg_files[0]).get_fdata(dtype="float32"))
                )
                levels = (levels[levels > 0] - 0.5).tolist()
                nsegs = len(levels)

            levels = [levels]
            missing = nsegs - len(colors)
            if missing > 0:
                colors = colors + color_palette("husl", missing)
            colors = [colors]
        else:  # in_rois is a list of masks
            nsegs = len(seg_files)
            levels = [[0.5]] * nsegs
            missing = nsegs - len(colors)
            if missing > 0:
                colors = [[c] for c in colors + color_palette("husl", missing)]

        if mask_file:
            seg_files.insert(0, mask_file)
            if levels:
                levels.insert(0, [0.5])
            colors.insert(0, [self.inputs.mask_color])
            nsegs += 1

        self._out_report = os.path.abspath(self.inputs.out_report)
        compose_view(
            plot_segs(
                image_nii=self.inputs.in_file,
                seg_niis=seg_files,
                bbox_nii=mask_file,
                levels=levels,
                colors=colors,
                out_file=self.inputs.out_report,
                masked=self.inputs.masked,
                compress=self.inputs.compress_report,
            ),
            fg_svgs=None,
            out_file=self._out_report,
        )
Exemplo n.º 6
0
    def _generate_report(self):
        from niworkflows.viz.utils import plot_segs, compose_view
        seg_files = self.inputs.in_rois
        mask_file = None if not isdefined(self.inputs.in_mask) \
            else self.inputs.in_mask

        # Remove trait decoration and replace None with []
        levels = [l for l in self.inputs.levels or []]
        colors = [c for c in self.inputs.colors or []]

        if len(seg_files) == 1:  # in_rois is a segmentation
            nsegs = len(levels)
            if nsegs == 0:
                levels = np.unique(np.round(
                    nb.load(seg_files[0]).get_data()).astype(int))
                levels = (levels[levels > 0] - 0.5).tolist()
                nsegs = len(levels)

            levels = [levels]
            missing = nsegs - len(colors)
            if missing > 0:
                colors = colors + color_palette("husl", missing)
            colors = [colors]
        else:  # in_rois is a list of masks
            nsegs = len(seg_files)
            levels = [[0.5]] * nsegs
            missing = nsegs - len(colors)
            if missing > 0:
                colors = [[c] for c in colors + color_palette("husl", missing)]

        if mask_file:
            seg_files.insert(0, mask_file)
            if levels:
                levels.insert(0, [0.5])
            colors.insert(0, [self.inputs.mask_color])
            nsegs += 1

        self._out_report = os.path.abspath(self.inputs.out_report)
        compose_view(
            plot_segs(
                image_nii=self.inputs.in_file,
                seg_niis=seg_files,
                bbox_nii=mask_file,
                levels=levels,
                colors=colors,
                out_file=self.inputs.out_report,
                masked=self.inputs.masked,
                compress=self.inputs.compress_report,
            ),
            fg_svgs=None,
            out_file=self._out_report
        )
Exemplo n.º 7
0
 def _generate_report(self):
     from niworkflows.viz.utils import plot_segs
     compose_view(
         plot_segs(
             image_nii=self._anat_file,
             seg_niis=self._seg_files,
             bbox_nii=self._mask_file,
             out_file=self.inputs.out_report,
             masked=self._masked,
             compress=self.inputs.compress_report
         ),
         fg_svgs=None,
         out_file=self._out_report
     )
Exemplo n.º 8
0
    def _generate_report(self):
        from niworkflows.viz.utils import plot_segs, compose_view
        seg_files = self.inputs.in_rois
        mask_file = None
        if isdefined(self.inputs.in_mask):
            mask_file = self.inputs.in_mask
            seg_files.insert(0, self.inputs.in_mask)

        self._out_report = os.path.abspath(self.inputs.out_report)
        compose_view(plot_segs(image_nii=self.inputs.in_file,
                               seg_niis=seg_files,
                               bbox_nii=mask_file,
                               out_file=self.inputs.out_report,
                               masked=self.inputs.masked,
                               colors=self.inputs.colors,
                               compress=self.inputs.compress_report),
                     fg_svgs=None,
                     out_file=self._out_report)
Exemplo n.º 9
0
    def _run_interface(self, runtime):
        """ there is not inner interface to run """
        from niworkflows.viz.utils import plot_segs, compose_view
        seg_files = self.inputs.in_rois
        mask_file = None
        if isdefined(self.inputs.in_mask):
            mask_file = self.inputs.in_mask
            seg_files.insert(0, self.inputs.in_mask)

        self._out_report = os.path.abspath(self.inputs.out_report)
        compose_view(plot_segs(image_nii=self.inputs.in_file,
                               seg_niis=seg_files,
                               bbox_nii=mask_file,
                               out_file=self.inputs.out_report,
                               masked=self.inputs.masked,
                               colors=self.inputs.colors,
                               compress=self.inputs.compress_report),
                     fg_svgs=None,
                     out_file=self._out_report)
        return runtime
Exemplo n.º 10
0
def make_segmentation(*, anatomical, segmentation, mask, out_file):
    """
    Creates `out_file`.svg of `segmentation` countours on input `anatomical`

    Parameters
    ----------
    anatomical : str
        Path to anatomical T1w image (*without skull*)
    segmentation : str
        Path to segmentation file with tissue types (1-6)
    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'
    segs = segmentation_to_files(segmentation)

    compose_view(
        plot_segs(image_nii=anatomical,
                  seg_niis=[mask] + segs,
                  bbox_nii=mask,
                  out_file='reports.svg',
                  masked=False,
                  compress='auto'),
        fg_svgs=None,
        out_file=out_file
    )

    for fname in segs: os.remove(fname)

    return out_file