Beispiel #1
0
    def filter_func(images: Images,
                    min_input: float = 0.0,
                    max_input: float = 10000.0,
                    max_output: float = 256.0,
                    progress=None,
                    data_type=None) -> Images:
        images.data[images.data < min_input] = 0
        images.data[images.data > max_input] = 0
        images.data *= (max_output / images.data.max())

        if data_type is not None:
            if data_type == uint16 and not images.dtype == uint16:
                images.data = images.data.astype(uint16)
            elif data_type == float32 and not images.dtype == float32:
                images.data = images.data.astype(float32)

        return images
Beispiel #2
0
    def filter_func(images: Images,
                    rebin_param=0.5,
                    mode=None,
                    cores=None,
                    chunksize=None,
                    progress=None) -> Images:
        """
        :param images: Sample data which is to be processed. Expects radiograms
        :param rebin_param: int, float or tuple
                            int - Percentage of current size.
                            float - Fraction of current size.
                            tuple - Size of the output image (x, y).
        :param mode: Interpolation to use for re-sizing
                     ('nearest', 'lanczos', 'bilinear', 'bicubic' or 'cubic').
        :param cores: The number of cores that will be used to process the data.
        :param chunksize: The number of chunks that each worker will receive.

        :return: The processed 3D numpy.ndarray
        """
        h.check_data_stack(images)

        if isinstance(rebin_param, tuple):
            param_valid = rebin_param[0] > 0 and rebin_param[1] > 0
        else:
            param_valid = rebin_param > 0

        if param_valid:
            sample = images.data
            sample_name: Optional[str]
            if images.memory_filename is not None:
                sample_name = images.memory_filename
                images.free_memory(delete_filename=False)
            else:
                # this case is true when the filter preview is being calculated
                sample_name = None
                # force single core execution as it's faster for a single image
                cores = 1
            empty_resized_data = _create_reshaped_array(
                sample.shape, sample.dtype, rebin_param, sample_name)

            f = ptsm.create_partial(skimage.transform.resize,
                                    ptsm.return_to_second_but_dont_use_it,
                                    mode=mode,
                                    output_shape=empty_resized_data.shape[1:])
            ptsm.execute(sample,
                         empty_resized_data,
                         f,
                         cores,
                         chunksize,
                         progress=progress,
                         msg="Applying Rebin")
            images.data = empty_resized_data

        return images
Beispiel #3
0
    def filter_func(images: Images,
                    min_input: float = 0.0,
                    max_input: float = 10000.0,
                    max_output: float = 256.0,
                    progress=None,
                    data_type=None) -> Images:
        np.clip(images.data, min_input, max_input, out=images.data)
        # offset - it removes any negative values so that they don't overflow when in uint16 range
        images.data -= nanmin(images.data)
        data_max = nanmax(images.data)
        # slope
        images.data *= (max_output / data_max)

        if data_type is not None:
            if data_type == uint16 and not images.dtype == uint16:
                images.data = images.data.astype(uint16)
            elif data_type == float32 and not images.dtype == float32:
                images.data = images.data.astype(float32)

        return images
Beispiel #4
0
    def filter_func(images: Images,
                    region_of_interest: Optional[Union[List[int], List[float],
                                                       SensibleROI]] = None,
                    progress=None) -> Images:
        """Execute the Crop Coordinates by Region of Interest filter. This does
        NOT do any checks if the Region of interest is out of bounds!

        If the region of interest is out of bounds, the crop will **FAIL** at
        runtime.

        If the region of interest is in bounds, but has overlapping coordinates
        the crop give back a 0 shape of the coordinates that were wrong.

        :param images: Input data as a 3D numpy.ndarray

        :param region_of_interest: Crop original images using these coordinates.
                                   The selection is a rectangle and expected order
                                   is - Left Top Right Bottom.

        :return: The processed 3D numpy.ndarray
        """

        if region_of_interest is None:
            region_of_interest = SensibleROI.from_list([0, 0, 50, 50])
        if isinstance(region_of_interest, list):
            region_of_interest = SensibleROI.from_list(region_of_interest)

        assert isinstance(region_of_interest, SensibleROI)

        h.check_data_stack(images)

        sample = images.data
        shape = (sample.shape[0], region_of_interest.height,
                 region_of_interest.width)
        if any((s < 0 for s in shape)):
            raise ValueError(
                "It seems the Region of Interest is outside of the current image dimensions.\n"
                "This can happen on the image preview right after a previous Crop Coordinates."
            )

        # allocate output first BEFORE freeing the original data,
        # otherwise it's possible to free and then fail allocation for output
        # at which point you're left with no data
        output = pu.allocate_output(images, shape)
        images.data = execute_single(sample,
                                     region_of_interest,
                                     progress,
                                     out=output)

        return images
Beispiel #5
0
    def filter_func(images: Images,
                    rebin_param=0.5,
                    mode=None,
                    cores=None,
                    chunksize=None,
                    progress=None) -> Images:
        """
        :param images: Sample data which is to be processed. Expects radiograms
        :param rebin_param: int, float or tuple
                            int - Percentage of current size.
                            float - Fraction of current size.
                            tuple - Size of the output image (x, y).
        :param mode: Interpolation to use for re-sizing
                     ('nearest', 'lanczos', 'bilinear', 'bicubic' or 'cubic').
        :param cores: The number of cores that will be used to process the data.
        :param chunksize: The number of chunks that each worker will receive.

        :return: The processed 3D numpy.ndarray
        """
        h.check_data_stack(images)

        if isinstance(rebin_param, tuple):
            param_valid = rebin_param[0] > 0 and rebin_param[1] > 0
        else:
            param_valid = rebin_param > 0

        if param_valid:
            sample = images.data
            sample_name: Optional[str]
            # allocate output first BEFORE freeing the original data,
            # otherwise it's possible to free and then fail allocation for output
            # at which point you're left with no data
            empty_resized_data = _create_reshaped_array(images, rebin_param)

            f = ptsm.create_partial(skimage.transform.resize,
                                    ptsm.return_to_second_but_dont_use_it,
                                    mode=mode,
                                    output_shape=empty_resized_data.shape[1:])
            ptsm.execute(sample,
                         empty_resized_data,
                         f,
                         cores,
                         chunksize,
                         progress=progress,
                         msg="Applying Rebin")
            images.data = empty_resized_data

        return images
    def filter_func(images: Images,
                    region_of_interest: Optional[Union[List[int], List[float], SensibleROI]] = None,
                    progress=None) -> Images:
        """
        Execute the Crop Coordinates by Region of Interest filter.
        This does NOT do any checks if the Region of interest is out of bounds!

        If the region of interest is out of bounds, the crop will **FAIL** at
        runtime.

        If the region of interest is in bounds, but has overlapping coordinates
        the crop give back a 0 shape of the coordinates that were wrong.

        :param images: Input data as a 3D numpy.ndarray

        :param region_of_interest: Crop original images using these coordinates.
                                   The selection is a rectangle and expected order
                                   is - Left Top Right Bottom.

        :return: The processed 3D numpy.ndarray
        """

        if region_of_interest is None:
            region_of_interest = SensibleROI.from_list([0, 0, 50, 50])
        if isinstance(region_of_interest, list):
            region_of_interest = SensibleROI.from_list(region_of_interest)

        assert isinstance(region_of_interest, SensibleROI)

        h.check_data_stack(images)

        sample = images.data
        shape = (sample.shape[0], region_of_interest.height, region_of_interest.width)
        sample_name = images.memory_filename
        if sample_name is not None:
            images.free_memory(delete_filename=False)
        output = pu.create_array(shape, sample.dtype, sample_name)
        images.data = execute_single(sample, region_of_interest, progress, out=output)

        return images
Beispiel #7
0
    def filter_func(images: Images,
                    rebin_param=0.5,
                    mode=None,
                    cores=None,
                    chunksize=None,
                    progress=None) -> Images:
        """
        :param images: Sample data which is to be processed. Expects radiograms
        :param rebin_param: int, float or tuple
                            int - Percentage of current size.
                            float - Fraction of current size.
                            tuple - Size of the output image (x, y).
        :param mode: Interpolation to use for re-sizing
                     ('nearest', 'lanczos', 'bilinear', 'bicubic' or 'cubic').
        :param cores: The number of cores that will be used to process the data.
        :param chunksize: The number of chunks that each worker will receive.

        :return: The processed 3D numpy.ndarray
        """
        h.check_data_stack(images)

        if isinstance(rebin_param, tuple):
            param_valid = rebin_param[0] > 0 and rebin_param[1] > 0
        else:
            param_valid = rebin_param > 0

        if param_valid:
            sample = images.data
            empty_resized_data = _create_reshaped_array(images, rebin_param)

            f = ps.create_partial(skimage.transform.resize,
                                  ps.return_to_second_at_i,
                                  mode=mode,
                                  output_shape=empty_resized_data.shape[1:])
            ps.shared_list = [sample, empty_resized_data]
            ps.execute(f, sample.shape[0], cores, "Applying Rebin", progress)
            images.data = empty_resized_data

        return images