How to save slices of the image from nifti image?

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”)
a=sitk.GetArrayFromImage(img)
im=a[:,:,19]

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/SimpleITK.py in RescaleIntensity(image1, outputMinimum, outputMaximum)
58734
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)

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:
http://insightsoftwareconsortium.github.io/SimpleITK-Notebooks/Python_html/02_Pythonic_Image.html

thanks