Hi,
I want to register 2 dicom images which are of the same examination, but with a slightly different FOV. Each image stack consists of three slices, but their distance is too large, so each slice has to be registered separately.
The issue mostly is that the registration doesn’t like there’s only 2 dimensions, the error message is
Using C# I tried
var registration = new ImageRegistrationMethod();
registration.SetMetricAsMattesMutualInformation(50);
registration.SetInterpolator(InterpolatorEnum.sitkLinear);
registration.SetOptimizerAsGradientDescent(1.0, 100);
registration.SetOptimizerScalesFromPhysicalShift();
var initialTransform = SimpleITK.CenteredTransformInitializer(
imageFixed,
imageMoving,
new AffineTransform(preCI.GetDimension()),
//new Euler3DTransform(),
CenteredTransformInitializerFilter.OperationModeType.GEOMETRY
);
registration.SetInitialTransform(initialTransform);
var finalTransform = registration.Execute(imageFixed, imageMoving);
The last line give the exception
itk::ERROR: RecursiveGaussianImageFilter(00000128B0DDD040): The number of pixels along direction 2 is less than 4. This filter requires a minimum of four pixels along the dimension to be processed.’
Which sounds reasonable since there’s only one slice. Is there a way to restrict the registration to the given image plane?
According to the textual description you are attempting to perform 2D/2D registration. The error message is indicating that the image is actually 3D. Note that an image of size [512, 512, 1] is a 3D image while the same image content with a size of [512, 512] is a 2D image.
If you are reading a 3D slice as a single image its size will be [sx, sy, 1]. You can extract the 2D equivalent with the ExtractImageFilter, or configure this during the image reading. Something along the lines of:
Hi Zivy,
thank you for your answer! When trying your code I realized I have a very outdated version of the sitk library, apparently the one on the nuget packet manager for Visual Studio is not maintained anymore. Now I’m using the latest version from github.
Your suggestion works, I could process the images.
Now I’m trying to save the resampled image back to a dicom file for further processing in a different app (which previously complained the images are not aligned).
When saving the image as dicom, there’s the error
ITK ERROR: GDCMImageIO(000001D6A1242500): Invalid direction cosines, non-orthogonal or unit length.
Did the extraction of the layer remove all the topological info from the image, so the dicom file writer complains these are missing? Can I keep that information, or do I have to reinsert the resampled image in the initial dicom image somehow?
If you used the code which extracted the 2D image during reading, then the metadata information is partially lost.
Instead, read the image as a 3D image use the ExtractImageFilter to get the 2D version and after resampling you can re-construct it as a 3D image by calling the JoinSeriesImageFilter with the image as input. Then copy the meta-data information from the original image using the CopyInformation method.