Good day, while i try to export single image from .nii file in result i get an image but with defective pixels. I also tried to cast image from sitkUInt8 to sitkUInt16 but it become worse.
Your input image is probably 16 bit. Certainly more than 8 bit. So when you are casting it to an 8 bit unsigned int, the pixel values are overflowing. If you really want 8-bit pixels, you’re going to have to re-map the intensities to the 0-255 range.
What you are seeing is overflow. The Cast operation does a simple cast between data types and that is not what you want. The original CT image has a high dynamic range, intensity values in Hounsfield Units outside the [0,255] range. Simple solution:
A solution with more fine grained control over mapping the intensities is provided by the IntensityWindowingImageFilter. As the example was showing a sagittal view, you will also need to make the image isotropic (see discussion and make_isotropic function in this Jupyter notebook).