I'm trying to change the spacing of a 2D dicom image to that of 3D dicom volume.I realised that simply using the SetSpacing() function of the SimpleITK library won't do it and that I had to resample my 2D image in order to actually change the spacing.However I'm not sure whether I did it right:what should the size of the resampled image be ? Does changing the spacing mean resizing the image as well? And how can I really check whether or not I really changed the spacing.(As the GetSpacing() function only retrieves the information in thr metadata).
import cv2
import SimpleITK as sitk`
volume=sitk.ReadImage('/image path')
template=sitk.ReadImage('image path')#2D image
#resample 2D image to match 3D volume
resample = sitk.ResampleImageFilter()
resample.SetInterpolator(sitk.sitkLinear)
resample.SetOutputDirection(template.GetDirection())
resample.SetOutputOrigin(template.GetOrigin())
resample.SetOutputSpacing(volume.GetSpacing())
newSize = (int(template.GetSize()[0]*(template.GetSpacing()[0]/volume.GetSpacing()[0])), int(template.GetSize()[1]*(template.GetSpacing()[1]/volume.GetSpacing()[1])),1)
resample.SetSize(newSize)
template_resampled = resample.Execute(template)
(to clarify, my 2D image is called template because I aim to apply template matching using the 3D volume and the 2d image with the adequate spacing)