Exemple #1
0
def _wf(data, params, cores, chunksize):
    tomopy = importer.do_importing('tomopy')

    # creating a dictionary with all possible params for this func
    kwargs = dict(level=None,
                  wname=u'db5',
                  sigma=2,
                  pad=True,
                  ncore=cores,
                  nchunk=chunksize)

    # process the input parameters
    params = _get_params(params)

    # dict.get returns a None if the keyword arg is not found
    # this means if the user hasn't passed anything that matches the string
    # then the default is used
    kwargs['level'] = int(
        params.get('level')) if params.get('level') else kwargs['level']
    kwargs['wname'] = str(
        params.get('wname')) if params.get('wname') else kwargs['wname']
    kwargs['sigma'] = int(
        params.get('sigma')) if params.get('sigma') else kwargs['sigma']
    kwargs['pad'] = bool(
        params.get('pad')) if params.get('pad') else kwargs['pad']

    return tomopy.prep.stripe.remove_stripe_fw(data, **kwargs)
    def filter_func(images: Images, minus_log=True, progress=None):
        """
        This filter should be used on transmission images (background corrected
        images).

        It converts the images from transmission to attenuation.

        :param images: Sample data which is to be processed. Expected in radiograms
        :param minus_log: Specify whether to calculate minus log or just return.

        :return: Inverted image
        """
        progress = Progress.ensure_instance(progress, task_name='Minus Log')

        if minus_log:
            # import early to check if tomopy is available
            tomopy = importer.do_importing('tomopy')

            with progress:
                progress.update(msg="Calculating -log on the sample data")
                sample = images.data
                # this check prevents division by 0 errors from the minus_log
                sample[sample == 0] = 1e-6

                # the operation is done in place
                tomopy.prep.normalize.minus_log(sample, out=sample)

        return images
Exemple #3
0
    def filter_func(data: Images,
                    circular_mask_ratio=0.95,
                    circular_mask_value=0.,
                    cores=None,
                    progress=None) -> Images:
        """
        :param data: Input data as a 3D numpy.ndarray
        :param circular_mask_ratio: The ratio to the full image.
                                    The ratio must be 0 < ratio < 1
        :param circular_mask_value: The value that all pixels in the mask
                                    will be set to.

        :return: The processed 3D numpy.ndarray
        """
        progress = Progress.ensure_instance(progress,
                                            num_steps=1,
                                            task_name='Circular Mask')

        if circular_mask_ratio and 0 < circular_mask_ratio < 1:
            tomopy = importer.do_importing('tomopy')

            with progress:
                progress.update(msg="Applying circular mask")

                # for some reason this doesn't like the ncore param, even though
                # it's in the official tomopy docs
                tomopy.circ_mask(arr=data.data,
                                 axis=0,
                                 ratio=circular_mask_ratio,
                                 val=circular_mask_value,
                                 ncore=cores)

        return data
Exemple #4
0
    def filter_func(data,
                    diff=None,
                    radius=_default_radius,
                    mode=_default_mode,
                    axis=0,
                    type=_default_dim,
                    cores=None,
                    progress=None):
        """
        Requires tomopy to be available.

        :param data: Input data as a 3D numpy.ndarray
        :param diff: Pixel value difference above which to crop bright pixels
        :param radius: Size of the median filter to apply
        :param mode: Spot brightness to remove.
                     Either 'bright' or 'dark'.
        :param cores: The number of cores that will be used to process the data.

        :return: The processed 3D numpy.ndarray
        """
        progress = Progress.ensure_instance(progress,
                                            task_name='Outliers',
                                            num_steps=3)
        if not utility.multiprocessing_necessary(data.data.shape, cores):
            cores = 1

        if diff and radius and diff > 0 and radius > 0:
            with progress:
                progress.update(
                    msg="Applying outliers with threshold: {0} and "
                    "radius {1}".format(diff, radius))

                sample = data.data
                # By default tomopy only clears bright outliers.
                # As a workaround inverting the image makes the dark outliers the brightest
                if mode == OUTLIERS_DARK:
                    np.negative(sample, out=sample)

                tomopy = importer.do_importing('tomopy')
                if type == "2D":
                    tomopy.misc.corr.remove_outlier(sample,
                                                    diff,
                                                    radius,
                                                    axis,
                                                    ncore=cores,
                                                    out=sample)
                else:
                    tomopy.misc.corr.remove_outlier1d(sample,
                                                      diff,
                                                      radius,
                                                      axis,
                                                      ncore=cores,
                                                      out=sample)
                progress.update()

                # reverse the inversion
                if mode == OUTLIERS_DARK:
                    np.negative(sample, out=sample)

        return data
def _sf(data, params, cores, chunksize):
    tomopy = importer.do_importing('tomopy')

    # creating a dictionary with all possible params for this func
    kwargs = dict(size=5, ncore=cores, nchunk=chunksize)

    # process the input parameters
    params = _get_params(params)

    # dict.get returns a None if the keyword arg is not found
    # this means if the user hasn't passed anything that matches the string
    # then the default is used
    kwargs['size'] = int(params.get('size')) if params.get('size') else kwargs['size']
    return tomopy.prep.stripe.remove_stripe_sf(data, **kwargs)