How to save slices of the image from nifti image?

(leena) #1

I have read an image and converted into array. then I took a slice. but it seems to work.But when I apply RescaleIntensity or any other function I’m getting error

import SimpleITK as sitk
img = sitk.ReadImage(“S1.nii”)

Error is:

TypeError Traceback (most recent call last)
in ()
----> 1 img_255 = sitk.Cast(sitk.RescaleIntensity(im), sitk.sitkUInt8)

~/sitkpy/lib/python3.5/site-packages/SimpleITK/ in RescaleIntensity(image1, outputMinimum, outputMaximum)
58735 “”"

58736 return _SimpleITK.RescaleIntensity(image1, outputMinimum, outputMaximum)
58737 class RichardsonLucyDeconvolutionImageFilter(ImageFilter_2):
58738 “”"

TypeError: in method ‘RescaleIntensity’, argument 1 of type ‘itk::simple::Image const &’
img_255 = sitk.Cast(sitk.RescaleIntensity(im), sitk.sitkUInt8)

(Bradley Lowekamp) #2

There is no need to convert to a numpy array. SimpleITK filters and functions operate on sitkImage’s and NOT numpy arrays. That is the case of your expecption.

The SimpleITK Image support pythonic slicing, so you don’t have a need to convert to numpy here. See this notebook:

(leena) #3