當前位置: 首頁>>代碼示例>>Python>>正文


Python SimpleITK.GetArrayViewFromImage方法代碼示例

本文整理匯總了Python中SimpleITK.GetArrayViewFromImage方法的典型用法代碼示例。如果您正苦於以下問題:Python SimpleITK.GetArrayViewFromImage方法的具體用法?Python SimpleITK.GetArrayViewFromImage怎麽用?Python SimpleITK.GetArrayViewFromImage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在SimpleITK的用法示例。


在下文中一共展示了SimpleITK.GetArrayViewFromImage方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: resample_images

# 需要導入模塊: import SimpleITK [as 別名]
# 或者: from SimpleITK import GetArrayViewFromImage [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: add_artifact

# 需要導入模塊: import SimpleITK [as 別名]
# 或者: from SimpleITK import GetArrayViewFromImage [as 別名]
def add_artifact(
            self,
            image: sitk.Image,
            transforms: List[sitk.Euler3DTransform],
            times: np.ndarray,
            interpolation: Interpolation,
            ):
        images = self.resample_images(image, transforms, interpolation)
        arrays = [sitk.GetArrayViewFromImage(im) for im in images]
        arrays = [array.transpose() for array in arrays]  # ITK to NumPy
        spectra = [self.fourier_transform(array) for array in arrays]
        self.sort_spectra(spectra, times)
        result_spectrum = np.empty_like(spectra[0])
        last_index = result_spectrum.shape[2]
        indices = (last_index * times).astype(int).tolist()
        indices.append(last_index)
        ini = 0
        for spectrum, fin in zip(spectra, indices):
            result_spectrum[..., ini:fin] = spectrum[..., ini:fin]
            ini = fin
        result_image = np.real(self.inv_fourier_transform(result_spectrum))
        return result_image.astype(np.float32) 
開發者ID:fepegar,項目名稱:torchio,代碼行數:24,代碼來源:random_motion.py

示例3: add_artifact

# 需要導入模塊: import SimpleITK [as 別名]
# 或者: from SimpleITK import GetArrayViewFromImage [as 別名]
def add_artifact(
            self,
            image: sitk.Image,
            spikes_positions: np.ndarray,
            intensity_factor: float,
            ):
        array = sitk.GetArrayViewFromImage(image).transpose()
        spectrum = self.fourier_transform(array)
        shape = np.array(spectrum.shape)
        mid_shape = shape // 2
        indices = np.floor(spikes_positions * shape).astype(int)
        for index in indices:
            diff = index - mid_shape
            i, j, k = mid_shape + diff
            spectrum[i, j, k] = spectrum.max() * intensity_factor
            # If we wanted to add a pure cosine, we should add spikes to both
            # sides of k-space. However, having only one is a better
            # representation og the actual cause of the artifact in real
            # scans.
            #i, j, k = mid_shape - diff
            #spectrum[i, j, k] = spectrum.max() * intensity_factor
        result = np.real(self.inv_fourier_transform(spectrum))
        return result.astype(np.float32) 
開發者ID:fepegar,項目名稱:torchio,代碼行數:25,代碼來源:random_spike.py

示例4: get_borders_mean

# 需要導入模塊: import SimpleITK [as 別名]
# 或者: from SimpleITK import GetArrayViewFromImage [as 別名]
def get_borders_mean(image, filter_otsu=True):
    # pylint: disable=bad-whitespace
    array = sitk.GetArrayViewFromImage(image)
    borders_tuple = (
        array[ 0,  :,  :],
        array[-1,  :,  :],
        array[ :,  0,  :],
        array[ :, -1,  :],
        array[ :,  :,  0],
        array[ :,  :, -1],
    )
    borders_flat = np.hstack([border.ravel() for border in borders_tuple])
    if not filter_otsu:
        return borders_flat.mean()
    borders_reshaped = borders_flat.reshape(1, 1, -1)
    borders_image = sitk.GetImageFromArray(borders_reshaped)
    otsu = sitk.OtsuThresholdImageFilter()
    otsu.Execute(borders_image)
    threshold = otsu.GetThreshold()
    values = borders_flat[borders_flat < threshold]
    if values.any():
        default_value = values.mean()
    else:
        default_value = borders_flat.mean()
    return default_value 
開發者ID:fepegar,項目名稱:torchio,代碼行數:27,代碼來源:random_affine.py

示例5: my_show

# 需要導入模塊: import SimpleITK [as 別名]
# 或者: from SimpleITK import GetArrayViewFromImage [as 別名]
def my_show(*args):
    for count, src in enumerate(args):
        nda = sitk.GetArrayViewFromImage(src)
        plt.subplot(1, len(args), count + 1)
        plt.imshow(nda)
    plt.show() 
開發者ID:DlutMedimgGroup,項目名稱:MedImg_Py_Library,代碼行數:8,代碼來源:ch5_Watershed_demo.py

示例6: sitk_to_np_no_copy

# 需要導入模塊: import SimpleITK [as 別名]
# 或者: from SimpleITK import GetArrayViewFromImage [as 別名]
def sitk_to_np_no_copy(image_sitk):
    return sitk.GetArrayViewFromImage(image_sitk) 
開發者ID:christianpayer,項目名稱:MedicalDataAugmentationTool,代碼行數:4,代碼來源:sitk_np.py

示例7: sitk_to_np

# 需要導入模塊: import SimpleITK [as 別名]
# 或者: from SimpleITK import GetArrayViewFromImage [as 別名]
def sitk_to_np(image_sitk, type=None):
    if type is None:
        return sitk.GetArrayFromImage(image_sitk)
    else:
        return sitk.GetArrayViewFromImage(image_sitk).astype(type) 
開發者ID:christianpayer,項目名稱:MedicalDataAugmentationTool,代碼行數:7,代碼來源:sitk_np.py

示例8: surface_distance

# 需要導入模塊: import SimpleITK [as 別名]
# 或者: from SimpleITK import GetArrayViewFromImage [as 別名]
def surface_distance(label_image_0, label_image_1):
    # code adapted from https://insightsoftwareconsortium.github.io/SimpleITK-Notebooks/Python_html/34_Segmentation_Evaluation.html
    try:
        # calculate distances on label contours
        reference_distance_map = sitk.SignedMaurerDistanceMap(label_image_1, squaredDistance=False, useImageSpacing=True)
        reference_distance_map_arr = sitk.GetArrayViewFromImage(reference_distance_map)
        reference_surface = sitk.LabelContour(label_image_1)
        reference_surface_arr = sitk.GetArrayViewFromImage(reference_surface)

        segmented_distance_map = sitk.SignedMaurerDistanceMap(label_image_0, squaredDistance=False, useImageSpacing=True)
        segmented_distance_map_arr = sitk.GetArrayViewFromImage(segmented_distance_map)
        segmented_surface = sitk.LabelContour(label_image_0)
        segmented_surface_arr = sitk.GetArrayViewFromImage(segmented_surface)

        seg2ref_distances = np.abs(reference_distance_map_arr[segmented_surface_arr == 1])
        ref2seg_distances = np.abs(segmented_distance_map_arr[reference_surface_arr == 1])

        all_surface_distances = np.concatenate([seg2ref_distances, ref2seg_distances])

        # # Multiply the binary surface segmentations with the distance maps. The resulting distance
        # # maps contain non-zero values only on the surface (they can also contain zero on the surface)
        # seg2ref_distance_map = reference_distance_map * sitk.Cast(segmented_surface, sitk.sitkFloat32)
        # ref2seg_distance_map = segmented_distance_map * sitk.Cast(reference_surface, sitk.sitkFloat32)
        #
        # statistics_image_filter = sitk.StatisticsImageFilter()
        # # Get the number of pixels in the reference surface by counting all pixels that are 1.
        # statistics_image_filter.Execute(reference_surface)
        # num_reference_surface_pixels = int(statistics_image_filter.GetSum())
        # # Get the number of pixels in the reference surface by counting all pixels that are 1.
        # statistics_image_filter.Execute(segmented_surface)
        # num_segmented_surface_pixels = int(statistics_image_filter.GetSum())
        #
        # # Get all non-zero distances and then add zero distances if required.
        # seg2ref_distance_map_arr = sitk.GetArrayViewFromImage(seg2ref_distance_map)
        # seg2ref_distances = list(seg2ref_distance_map_arr[seg2ref_distance_map_arr != 0])
        # seg2ref_distances = seg2ref_distances + list(np.zeros(num_segmented_surface_pixels - len(seg2ref_distances)))
        # ref2seg_distance_map_arr = sitk.GetArrayViewFromImage(ref2seg_distance_map)
        # ref2seg_distances = list(ref2seg_distance_map_arr[ref2seg_distance_map_arr != 0])
        # ref2seg_distances = ref2seg_distances + list(np.zeros(num_reference_surface_pixels - len(ref2seg_distances)))
        #
        # all_surface_distances = seg2ref_distances + ref2seg_distances

        current_mean_surface_distance = np.mean(all_surface_distances)
        current_median_surface_distance = np.median(all_surface_distances)
        current_std_surface_distance = np.std(all_surface_distances)
        current_max_surface_distance = np.max(all_surface_distances)
    except:
        current_mean_surface_distance = np.nan
        current_median_surface_distance = np.nan
        current_std_surface_distance = np.nan
        current_max_surface_distance = np.nan
        pass

    return current_mean_surface_distance, current_median_surface_distance, current_std_surface_distance, current_max_surface_distance 
開發者ID:christianpayer,項目名稱:MedicalDataAugmentationTool,代碼行數:56,代碼來源:sitk_image.py

示例9: to_itk_image

# 需要導入模塊: import SimpleITK [as 別名]
# 或者: from SimpleITK import GetArrayViewFromImage [as 別名]
def to_itk_image(image_like):

    if isinstance(image_like, itk.Image):
        return image_like

    if is_arraylike(image_like):
        array = np.asarray(image_like)
        case_use_view = array.flags['OWNDATA']
        if have_dask and isinstance(image_like, dask.array.core.Array):
            case_use_view = False
        array = np.ascontiguousarray(array)
        if case_use_view:
            image_from_array = itk.image_view_from_array(array)
        else:
            image_from_array = itk.image_from_array(array)
        return image_from_array
    elif have_vtk and isinstance(image_like, vtk.vtkImageData):
        from vtk.util import numpy_support as vtk_numpy_support
        array = vtk_numpy_support.vtk_to_numpy(
            image_like.GetPointData().GetScalars())
        array.shape = tuple(image_like.GetDimensions())[::-1]
        image_from_array = itk.image_view_from_array(array)
        image_from_array.SetSpacing(image_like.GetSpacing())
        image_from_array.SetOrigin(image_like.GetOrigin())
        return image_from_array
    elif have_simpleitk and isinstance(image_like, sitk.Image):
        array = sitk.GetArrayViewFromImage(image_like)
        image_from_array = itk.image_view_from_array(array)
        image_from_array.SetSpacing(image_like.GetSpacing())
        image_from_array.SetOrigin(image_like.GetOrigin())
        direction = image_like.GetDirection()
        npdirection = np.asarray(direction)
        npdirection = np.reshape(npdirection, (-1, 3))
        itkdirection = itk.matrix_from_array(npdirection)
        image_from_array.SetDirection(itkdirection)
        return image_from_array
    elif have_imagej:
        import imglyb
        if isinstance(image_like,
                      imglyb.util.ReferenceGuardingRandomAccessibleInterval):
            array = imglyb.to_numpy(image_like)
            image_from_array = itk.image_view_from_array(array)
            return image_from_array
    elif isinstance(image_like, itk.ProcessObject):
        return itk.output(image_like)

    return None 
開發者ID:InsightSoftwareConsortium,項目名稱:itkwidgets,代碼行數:49,代碼來源:_transform_types.py


注:本文中的SimpleITK.GetArrayViewFromImage方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。