CT resampling, padding issue

Hi,
I need to resample my list of CT mhd files to a pixel spacing 1x1x1mm, and constant size such as (256x256x256) with the same origin and direction. I need to shift the origin as well. My main issue right now, is to have padded values set to a constant like -1024. When I use the SimpleITK.resample function like this (image is the original CT file, new spacing is [1,1,1]):
resampled_img = sitk.Resample(image, [512, 512, 512], sitk.Transform(),
sitk.sitkNearestNeighbor, image.GetOrigin(), new_spacing,
image.GetDirection(), 0.0, image.GetPixelID())
I have an array like this (showing one pixel per 50 pixel) :
[[-1024 -1024 -983 -1024 -1024 0 0 0 0 0 0]
[-1024 -921 -968 -1024 -1024 0 0 0 0 0 0]
[ -953 -829 90 -1024 -1024 0 0 0 0 0 0]
[ -977 -1005 -967 -1011 -1024 0 0 0 0 0 0]
[-1024 -924 -965 -993 -1024 0 0 0 0 0 0]
[ 0 0 0 0 0 0 0 0 0 0 0]
[ 0 0 0 0 0 0 0 0 0 0 0]
[ 0 0 0 0 0 0 0 0 0 0 0]
[ 0 0 0 0 0 0 0 0 0 0 0]
[ 0 0 0 0 0 0 0 0 0 0 0]
[ 0 0 0 0 0 0 0 0 0 0 0]]

Is it possible to place -1024 to the padded area with sitk.resample function, or do I have to change the padded area pixel values after resampling? I have one additional question: If I change the origin of the CT, my original CT image will shift to the middle right? How can I do these calculations without losing original human volume information inside the CT?

Thanks in advance
Best regards
Gökçe

Hello @Gokce_Guven,
Your code is setting the default pixel value (any pixel that is mapped outside the resampled image - your padded region) to zero, just change the 0.0 to -1024. See the documentation for the procedural interface and more details in the documentation for the object oriented interface.

Thanks a lot for your response :slight_smile: I will check them thoroughly.

I have another question regarding resampling the CT image. I check the documentation about how to put the body part in the CT center after resampling as well. after resampling the image with :
spacing = image.GetSpacing()
size = (512,512,512)
origin = image.GetOrigin()
direction = image.GetDirection()
new_spacing = [1,1,1]
pixel_img = sitk.Resample(image, size, sitk.Transform(),
sitk.sitkNearestNeighbor, origin, new_spacing,
direction, -1024, image.GetPixelID())

I have my body part in the up left corner, I checked the sitk.TranslationTransform(dimension, offset) but could not clearly understand how to use Transform() and TranslationTransform() functions. How can I calculate the offset for the TranslationTransform or how should I use sitk.Transform() function? Do I need to calculate the origin or is it ok to use the original image origin? I have another question about the interpolator, my aim is to preserve the original volume of the human body parts, I tried bspline cubic interpolator or nearest neighbour to fill the gap between slices. Since I am pretty new on this area, I couldn’t be sure about which interpolator (linear, nearestneighbour or bspline) to use to get the preserved volume of the body parts. Should I use Bspline? I didn’t understand the pixeltype argument as well. My direction cosine is the same as the original image for now. Any help would be greatly appreciated.

Hello @Gokce_Guven,

You should be using the sitk.sitkLinear interpolator as you are interpolating grayscale values (CT), nearest neighbor is fastest but worst results, linear is the compromise that gives reasonable results and reasonable speed, bspline will give best results but worst speed. Most of the time, linear interpolation will be good enough.

Before you continue working with the toolkit, I highly recommend that you take a couple of hours and complete one of our tutorials. The most recent is available online via this website and git repository.

Thanks a lot for your response. I will check the tutorials throughly.