What is the code for sitk.Tramsform()?

def make_isotropicBCC(
    image,
    interpolator=sitk.sitkLinear,
    spacing=None,
    default_value=0,
    standardize_axes=False,):
   
    original_spacing = image.GetSpacing()
    
    # Make image isotropic via resampling.
    original_size = image.GetSize()
    
    if spacing is None:
        spacing = min(original_spacing)
    
    new_spacing = [spacing] * image.GetDimension()
   
    new_size = [
        int(round(osz * ospc / spacing))
        for osz, ospc in zip(original_size, original_spacing)
    ]
    
    new_direction = tuple((0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0))#image.GetDirection()
    
    new_origin = image.GetOrigin()
    
    # Only need to standardize axes if user requested and the original
    # axes were not standard.
    if standardize_axes and not np.array_equal(np.array(new_direction), np.identity(image.GetDimension()).ravel()):
        new_direction = np.identity(image.GetDimension()).ravel()
        # Compute bounding box for the original, non standard axes image.
        boundary_points = []
        for boundary_index in list(itertools.product(*zip([0, 0, 0], image.GetSize()))):
            boundary_points.append(image.TransformIndexToPhysicalPoint(boundary_index))
        max_coords = np.max(boundary_points, axis=0)
        min_coords = np.min(boundary_points, axis=0)
        new_origin = min_coords
        new_size = (((max_coords - min_coords) / spacing).round().astype(int)).tolist()
    return sitk.Resample(
        image,
        new_size,
        sitk.Transform(),
        interpolator,
        new_origin,
        new_spacing,
        new_direction,
        default_value,
        image.GetPixelID(),
    )

The above is my function I built using simpleITK, I am trying to understand what is code for sitk.Transform() in the above? I could not get a GitHub link to the code, because I want to understand how the transformation and resampling works for the above function.

Hello @pranoy-ray,

The Resample function used in the code expects a spatial transformation mapping points between the new image and the original image being resampled. As the intent is just to resample the original image in place, identity spatial transformation, we use the generic Transform, which by default is the identity.

2 Likes

Wow that partly answers my question. This is interesting to me, can you share some more math (Mathematical description) on this “identity spatial transformation” and the resampling?

Hello @pranoy-ray,

For a detailed description of resampling in ITK, please see the ITK software guide, section 2.9.4 Resample Image Filter.

Edited:

Hi, I have been reading the software guide. I see that Gaussian Smoothing and Intensity Windowing is applied to the input by default. How do I disable that in Python?

Hello @pranoy-ray,

If you are only using the resample filter, there is no intensity windowing, so nothing to disable.

What bout Gaussian Smoothing @zivy ? Is that activated by default?

No. Resampling just does resampling, no additional data modifications. If you want to perform smoothing prior to resampling, as in the case of multi-scale analysis, then you need to do it explicitly with the relevant filter.

1 Like

Thank you for your reply