Exemple #1
0
    def init_layout(self,
                    view_set=cfg.defacing_view_set,
                    num_rows_per_view=cfg.defacing_num_rows_per_view,
                    num_slices_per_view=cfg.defacing_num_slices_per_view,
                    padding=cfg.default_padding):
        """initializes the layout"""

        plt.style.use('dark_background')

        # vmin/vmax are controlled, because we rescale all to [0, 1]
        self.display_params = dict(interpolation='none',
                                   aspect='equal',
                                   origin='lower',
                                   cmap='gray',
                                   vmin=0.0,
                                   vmax=1.0)
        self.figsize = cfg.default_review_figsize

        self.collage = Collage(view_set=view_set,
                               num_slices=num_slices_per_view,
                               num_rows=num_rows_per_view,
                               display_params=self.display_params,
                               bounding_rect=cfg.bbox_defacing_MRI_review,
                               figsize=self.figsize)
        self.fig = self.collage.fig
        self.fig.canvas.set_window_title('VisualQC defacing : {} {} '
                                         ''.format(self.in_dir,
                                                   self.defaced_name))

        self.padding = padding
Exemple #2
0
def test_collage_class():

    img_path = pjoin(base_dir, '3569_bl_PPMI.nii')
    img = read_image(img_path, None)
    scaled = scale_0to1(img)
    c = Collage(num_slices=15, view_set=(0, 1), num_rows=3)

    try:
        c.attach(scaled)
    except:
        raise ValueError('Attach does not work')

    try:
        c.transform_and_attach(scaled, np.square)
    except:
        raise ValueError('transform_and_attach does not work')

    try:
        print(c)
    except:
        raise ValueError('repr implementation failed')
Exemple #3
0
def checkerboard(
    img_spec1=None,
    img_spec2=None,
    patch_size=10,
    view_set=(0, 1, 2),
    num_slices=(10, ),
    num_rows=2,
    rescale_method='global',
    background_threshold=0.05,
    annot=None,
    padding=5,
    output_path=None,
    figsize=None,
):
    """
    Checkerboard mixer.

    Parameters
    ----------
    img_spec1 : str or nibabel image-like object
        MR image (or path to one) to be visualized

    img_spec2 : str or nibabel image-like object
        MR image (or path to one) to be visualized

    patch_size : int or list or (int, int) or None
        size of checker patch (either square or rectangular)
        If None, number of voxels/patch are chosen such that,
            there will be 7 patches through the width/height.

    view_set : iterable
        Integers specifying the dimensions to be visualized.
        Choices: one or more of (0, 1, 2) for a 3D image

    num_slices : int or iterable of size as view_set
        number of slices to be selected for each view
        Must be of the same length as view_set,
            each element specifying the number of slices for each dimension.
            If only one number is given, same number will be chosen for all dimensions.

    num_rows : int
        number of rows (top to bottom) per each of 3 dimensions

    rescale_method : bool or str or list or None
        Range to rescale the intensity values to
        Default: 'global', min and max values computed based on ranges from both images.
        If false or None, no rescaling is done (does not work yet).

    background_threshold : float or str
        A threshold value below which all the background voxels will be set to zero.
        Default : 0.05. Other option is a string specifying a percentile: '5%', '10%'.
        Specify None if you don't want any thresholding.

    annot : str
        Text to display to annotate the visualization

    padding : int
        number of voxels to pad around each panel.

    output_path : str
        path to save the generate collage to.

    figsize : list
        Size of figure in inches to be passed on to plt.figure() e.g. [12, 12] or [20, 20]

    Returns
    -------
    fig : figure handle
        handle to the collage figure generated.

    """

    img_one, img_two = _preprocess_images(img_spec1,
                                          img_spec2,
                                          rescale_method=rescale_method,
                                          bkground_thresh=background_threshold,
                                          padding=padding)

    display_params = dict(interpolation='none',
                          aspect='auto',
                          origin='lower',
                          cmap='gray',
                          vmin=0.0,
                          vmax=1.0)

    mixer = partial(_checker_mixer, checker_size=patch_size)
    collage = Collage(view_set=view_set,
                      num_slices=num_slices,
                      num_rows=num_rows,
                      figsize=figsize,
                      display_params=display_params)
    collage.transform_and_attach((img_one, img_two), func=mixer)
    collage.save(output_path=output_path, annot=annot)

    return collage