当前位置: 首页>>代码示例>>Python>>正文


Python SimpleITK.sitkFloat32方法代码示例

本文整理汇总了Python中SimpleITK.sitkFloat32方法的典型用法代码示例。如果您正苦于以下问题:Python SimpleITK.sitkFloat32方法的具体用法?Python SimpleITK.sitkFloat32怎么用?Python SimpleITK.sitkFloat32使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SimpleITK的用法示例。


在下文中一共展示了SimpleITK.sitkFloat32方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: resample_images

# 需要导入模块: import SimpleITK [as 别名]
# 或者: from SimpleITK import sitkFloat32 [as 别名]
def resample_images(
            image: sitk.Image,
            transforms: List[sitk.Euler3DTransform],
            interpolation: Interpolation,
            ) -> List[sitk.Image]:
        floating = reference = image
        default_value = np.float64(sitk.GetArrayViewFromImage(image).min())
        transforms = transforms[1:]  # first is identity
        images = [image]  # first is identity
        for transform in transforms:
            resampler = sitk.ResampleImageFilter()
            resampler.SetInterpolator(get_sitk_interpolator(interpolation))
            resampler.SetReferenceImage(reference)
            resampler.SetOutputPixelType(sitk.sitkFloat32)
            resampler.SetDefaultPixelValue(default_value)
            resampler.SetTransform(transform)
            resampled = resampler.Execute(floating)
            images.append(resampled)
        return images 
开发者ID:fepegar,项目名称:torchio,代码行数:21,代码来源:random_motion.py

示例2: N4BiasFieldCorrection

# 需要导入模块: import SimpleITK [as 别名]
# 或者: from SimpleITK import sitkFloat32 [as 别名]
def N4BiasFieldCorrection(src_path, dst_path):
        '''
        This function carry out BiasFieldCorrection for the files in a specific directory
        :param src_path: path of the source file
        :param dst_path: path of the target file
        :return:
        '''
        print("N4 bias correction runs.")
        inputImage = sitk.ReadImage(src_path)

        maskImage = sitk.OtsuThreshold(inputImage, 0, 1, 200)
        sitk.WriteImage(maskImage, dst_path)

        inputImage = sitk.Cast(inputImage, sitk.sitkFloat32)

        corrector = sitk.N4BiasFieldCorrectionImageFilter()

        # corrector.SetMaximumNumberOfIterations(10)

        output = corrector.Execute(inputImage, maskImage)
        sitk.WriteImage(output, dst_path)
        print("Finished N4 Bias Field Correction.....")

    # normalize the data(zero mean and unit variance) 
开发者ID:JohnleeHIT,项目名称:Brats2019,代码行数:26,代码来源:utils.py

示例3: write_image

# 需要导入模块: import SimpleITK [as 别名]
# 或者: from SimpleITK import sitkFloat32 [as 别名]
def write_image(
        image_sitk,
        path_to_file,
        compress=True,
        verbose=True,
        description=None,
    ):
        info = "Write image to %s" % path_to_file
        if compress:
            image_sitk = sitk.Cast(image_sitk, sitk.sitkFloat32)
            info += " (float32)"
        if verbose:
            ph.print_info("%s ... " % info, newline=False)
        header_update = DataWriter._get_header_update(description=description)

        sitkh.write_nifti_image_sitk(
            image_sitk, path_to_file, header_update=header_update)
        if verbose:
            print("done") 
开发者ID:gift-surg,项目名称:NiftyMIC,代码行数:21,代码来源:data_writer.py

示例4: itkRegionGrow

# 需要导入模块: import SimpleITK [as 别名]
# 或者: from SimpleITK import sitkFloat32 [as 别名]
def itkRegionGrow(im_arr, type_str, seedlist, lower=0, upper=1):

    func_1 = 'CT'
    func_2 = 'CC'

    # get an image from the array input
    image = itkEdgePreservedSmoothing.itkEdgePreservedSmoothing(im_arr, 'CF')
    image = sitk.GetImageFromArray(im_arr)
    image = sitk.Cast(image, sitk.sitkFloat32)

    # find out the way to process the image according to type_str
    if type_str == func_1:
        im_new = sitk.ConnectedThreshold(image, seedlist, lower, upper)

    elif type_str == func_2:
        im_new = sitk.ConfidenceConnected(image, seedlist)

    else:
        print('Please check your spelling,'
              'and try again.')
    return im_new


# an example of using the function 
开发者ID:DlutMedimgGroup,项目名称:MedImg_Py_Library,代码行数:26,代码来源:itkRegionGrow.py

示例5: get_transformed_image

# 需要导入模块: import SimpleITK [as 别名]
# 或者: from SimpleITK import sitkFloat32 [as 别名]
def get_transformed_image(self, prediction_np, reference_sitk=None, output_spacing=None, transformation=None):
        """
        Returns the transformed predictions as a list of sitk images. If the transformation is None, the prediction_np image
        will not be transformed, but only split and converted to a list of sitk images.
        :param prediction_np: The predicted np array.
        :param reference_sitk: The reference sitk image from which origin/spacing/direction is taken from.
        :param output_spacing: The output spacing of the prediction_np array.
        :param transformation: The sitk transformation used to transform the reference_sitk image to the network input.
        :return: A list of the transformed sitk predictions.
        """
        if transformation is not None:
            predictions_sitk = utils.sitk_image.transform_np_output_to_sitk_input(output_image=prediction_np,
                                                                                  output_spacing=output_spacing,
                                                                                  channel_axis=self.channel_axis,
                                                                                  input_image_sitk=reference_sitk,
                                                                                  transform=transformation,
                                                                                  interpolator=self.interpolator,
                                                                                  output_pixel_type=sitk.sitkFloat32)
            prediction_np = utils.sitk_np.sitk_list_to_np(predictions_sitk, axis=0)
        else:
            if self.channel_axis != 0:
                prediction_np = utils.np_image.split_by_axis(prediction_np, self.channel_axis)
                prediction_np = np.stack(prediction_np, axis=0)
        return prediction_np 
开发者ID:christianpayer,项目名称:MedicalDataAugmentationTool,代码行数:26,代码来源:segmentation_test.py

示例6: get_transformed_image_sitk

# 需要导入模块: import SimpleITK [as 别名]
# 或者: from SimpleITK import sitkFloat32 [as 别名]
def get_transformed_image_sitk(self, prediction_np, reference_sitk=None, output_spacing=None, transformation=None):
        """
        Returns a list of transformed sitk images from the prediction np array for the given reference image and transformation.
        :param prediction_np: The np array to transform.
        :param reference_sitk: The reference sitk image.
        :param output_spacing: The output spacing of the np array.
        :param transformation: The transformation. If transformation is None, the prediction np array will not be transformed.
        :return: A list of transformed sitk images.
        """
        if transformation is not None:
            predictions_sitk = utils.sitk_image.transform_np_output_to_sitk_input(output_image=prediction_np,
                                                                                  output_spacing=output_spacing,
                                                                                  channel_axis=None,
                                                                                  input_image_sitk=reference_sitk,
                                                                                  transform=transformation,
                                                                                  interpolator=self.interpolator,
                                                                                  output_pixel_type=sitk.sitkFloat32)
        else:
            predictions_np = utils.np_image.split_by_axis(prediction_np, self.channel_axis)
            predictions_sitk = [utils.sitk_np.np_to_sitk(prediction_np) for prediction_np in predictions_np]
        return predictions_sitk 
开发者ID:christianpayer,项目名称:MedicalDataAugmentationTool,代码行数:23,代码来源:heatmap_test.py

示例7: normalize_image

# 需要导入模块: import SimpleITK [as 别名]
# 或者: from SimpleITK import sitkFloat32 [as 别名]
def normalize_image(image,
                    valid_min=-1024,
                    valid_max=3071):
    image = sitk.Cast(image, sitk.sitkFloat32)
    f_min_max = sitk.MinimumMaximumImageFilter()
    f_min_max.Execute(image)
    min_ = f_min_max.GetMinimum()
    max_ = f_min_max.GetMaximum()
    log.debug(f'Got image with value range [{min_}, {max_}]')
    if min_ < valid_min or max_ > valid_max:
        log.warning(
            f'Got image with non-default hounsfield scale range: Got range ' \
            f'[{min_}, {max_}]. Values will be clipped to [{valid_min}, {valid_max}].'
        )
        f_clamp = sitk.ClampImageFilter()
        f_clamp.SetLowerBound(valid_min)
        f_clamp.SetUpperBound(valid_max)
        image = f_clamp.Execute(image)

    f_subtract = sitk.SubtractImageFilter()
    image = f_subtract.Execute(image, valid_min)
    f_divide = sitk.DivideImageFilter()

    return f_divide.Execute(image, valid_max - valid_min) 
开发者ID:IPMI-ICNS-UKE,项目名称:gdl-fire-4d,代码行数:26,代码来源:preprocessing.py

示例8: load_itk

# 需要导入模块: import SimpleITK [as 别名]
# 或者: from SimpleITK import sitkFloat32 [as 别名]
def load_itk(filename):
    """
    load mhd files and normalization 0-255
    :param filename:
    :return:
    """
    rescalFilt = sitk.RescaleIntensityImageFilter()
    rescalFilt.SetOutputMaximum(255)
    rescalFilt.SetOutputMinimum(0)
    # Reads the image using SimpleITK
    itkimage = rescalFilt.Execute(sitk.Cast(sitk.ReadImage(filename), sitk.sitkFloat32))
    return itkimage 
开发者ID:junqiangchen,项目名称:LiTS---Liver-Tumor-Segmentation-Challenge,代码行数:14,代码来源:getPatchImageAndMask.py

示例9: loadImages

# 需要导入模块: import SimpleITK [as 别名]
# 或者: from SimpleITK import sitkFloat32 [as 别名]
def loadImages(self):
        self.sitkImages=dict()
        rescalFilt=sitk.RescaleIntensityImageFilter()
        rescalFilt.SetOutputMaximum(1)
        rescalFilt.SetOutputMinimum(0)

        stats = sitk.StatisticsImageFilter()
        m = 0.
        for f in self.fileList:
            self.sitkImages[f]=rescalFilt.Execute(sitk.Cast(sitk.ReadImage(join(self.srcFolder, f)),sitk.sitkFloat32))
            stats.Execute(self.sitkImages[f])
            m += stats.GetMean()

        self.meanIntensityTrain=m/len(self.sitkImages) 
开发者ID:faustomilletari,项目名称:VNet,代码行数:16,代码来源:DataManager.py

示例10: loadGT

# 需要导入模块: import SimpleITK [as 别名]
# 或者: from SimpleITK import sitkFloat32 [as 别名]
def loadGT(self):
        self.sitkGT=dict()

        for f in self.gtList:
            self.sitkGT[f]=sitk.Cast(sitk.ReadImage(join(self.srcFolder, f))>0.5,sitk.sitkFloat32) 
开发者ID:faustomilletari,项目名称:VNet,代码行数:7,代码来源:DataManager.py

示例11: apply_bspline_transform

# 需要导入模块: import SimpleITK [as 别名]
# 或者: from SimpleITK import sitkFloat32 [as 别名]
def apply_bspline_transform(
            self,
            tensor: torch.Tensor,
            affine: np.ndarray,
            bspline_params: np.ndarray,
            interpolation: Interpolation,
            ) -> torch.Tensor:
        assert tensor.dim() == 4
        assert len(tensor) == 1
        image = self.nib_to_sitk(tensor[0], affine)
        floating = reference = image
        bspline_transform = self.get_bspline_transform(
            image,
            self.num_control_points,
            bspline_params,
        )
        self.parse_free_form_transform(
            bspline_transform, self.max_displacement)
        resampler = sitk.ResampleImageFilter()
        resampler.SetReferenceImage(reference)
        resampler.SetTransform(bspline_transform)
        resampler.SetInterpolator(get_sitk_interpolator(interpolation))
        resampler.SetDefaultPixelValue(tensor.min().item())
        resampler.SetOutputPixelType(sitk.sitkFloat32)
        resampled = resampler.Execute(floating)

        np_array = sitk.GetArrayFromImage(resampled)
        np_array = np_array.transpose()  # ITK to NumPy
        tensor[0] = torch.from_numpy(np_array)
        return tensor 
开发者ID:fepegar,项目名称:torchio,代码行数:32,代码来源:random_elastic_deformation.py

示例12: gen_warp_field

# 需要导入模块: import SimpleITK [as 别名]
# 或者: from SimpleITK import sitkFloat32 [as 别名]
def gen_warp_field(shape, sigma=0.1, grid_size=3):
    '''Generate an spline warp field'''
    import SimpleITK as sitk
    # Initialize bspline transform
    args = shape+(sitk.sitkFloat32,)
    ref_image = sitk.Image(*args)
    tx = sitk.BSplineTransformInitializer(ref_image, [grid_size, grid_size])

    # Initialize shift in control points:
    # mesh size = number of control points - spline order
    p = sigma * np.random.randn(grid_size+3, grid_size+3, 2)

    # Anchor the edges of the image
    p[:, 0, :] = 0
    p[:, -1:, :] = 0
    p[0, :, :] = 0
    p[-1:, :, :] = 0

    # Set bspline transform parameters to the above shifts
    tx.SetParameters(p.flatten())

    # Compute deformation field
    displacement_filter = sitk.TransformToDisplacementFieldFilter()
    displacement_filter.SetReferenceImage(ref_image)
    displacement_field = displacement_filter.Execute(tx)

    return displacement_field 
开发者ID:fvisin,项目名称:dataset_loaders,代码行数:29,代码来源:data_augmentation.py

示例13: read

# 需要导入模块: import SimpleITK [as 别名]
# 或者: from SimpleITK import sitkFloat32 [as 别名]
def read(filename, dtype=th.float32, device='cpu'):
        """
        Static method to directly read an image through the Image class

        filename (str): filename of the image
        dtype: specific dtype for representing the tensor
        device: on which device the image has to be allocated
        return (Image): an airlab image
        """
        return Image(sitk.ReadImage(filename, sitk.sitkFloat32), dtype, device) 
开发者ID:airlab-unibas,项目名称:airlab,代码行数:12,代码来源:image.py

示例14: read_image_as_tensor

# 需要导入模块: import SimpleITK [as 别名]
# 或者: from SimpleITK import sitkFloat32 [as 别名]
def read_image_as_tensor(filename, dtype=th.float32, device='cpu'):

    itk_image = sitk.ReadImage(filename, sitk.sitkFloat32)

    return create_tensor_image_from_itk_image(itk_image, dtype=dtype, device=device) 
开发者ID:airlab-unibas,项目名称:airlab,代码行数:7,代码来源:image.py

示例15: resample_image

# 需要导入模块: import SimpleITK [as 别名]
# 或者: from SimpleITK import sitkFloat32 [as 别名]
def resample_image(image, out_spacing=(1.0, 1.0, 1.0), out_size=None, is_label=False, pad_value=0):
    """Resamples an image to given element spacing and output size."""

    original_spacing = np.array(image.GetSpacing())
    original_size = np.array(image.GetSize())

    if out_size is None:
        out_size = np.round(np.array(original_size * original_spacing / np.array(out_spacing))).astype(int)
    else:
        out_size = np.array(out_size)

    original_direction = np.array(image.GetDirection()).reshape(len(original_spacing),-1)
    original_center = (np.array(original_size, dtype=float) - 1.0) / 2.0 * original_spacing
    out_center = (np.array(out_size, dtype=float) - 1.0) / 2.0 * np.array(out_spacing)

    original_center = np.matmul(original_direction, original_center)
    out_center = np.matmul(original_direction, out_center)
    out_origin = np.array(image.GetOrigin()) + (original_center - out_center)

    resample = sitk.ResampleImageFilter()
    resample.SetOutputSpacing(out_spacing)
    resample.SetSize(out_size.tolist())
    resample.SetOutputDirection(image.GetDirection())
    resample.SetOutputOrigin(out_origin.tolist())
    resample.SetTransform(sitk.Transform())
    resample.SetDefaultPixelValue(pad_value)

    if is_label:
        resample.SetInterpolator(sitk.sitkNearestNeighbor)
    else:
        #resample.SetInterpolator(sitk.sitkBSpline)
        resample.SetInterpolator(sitk.sitkLinear)

    return resample.Execute(sitk.Cast(image, sitk.sitkFloat32)) 
开发者ID:biomedia-mira,项目名称:istn,代码行数:36,代码来源:processing.py


注:本文中的SimpleITK.sitkFloat32方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。