ANTsX / ANTs

Advanced Normalization Tools (ANTs)
Apache License 2.0
1.22k stars 381 forks source link

Point based registration #1222

Open Harry-Zzz opened 3 years ago

Harry-Zzz commented 3 years ago

Hi, Thank you for your excellent work, but I have a problem using it. When I use ICP points for auxiliary matching, my file is a point set in CSV or TXT format, which can not be directly input into ICP[fixedPointSet,movingPointSet,metricWeight,,], but needs to be converted into grid. Can I only convert the point set into grid image for ICP registration, or is there an error in my operation. Because I want to be able to input point sets directly, not a grid composed of point sets. Finally, I want to realize point-based auxiliary registration: -m mattes[ fixed.nii.gz, moving.nii.gz, 1 ] -m ICP [fixedPoints.csv, movingPoints.csv,1] Thanks

ntustison commented 3 years ago

Did you look at this example where .csv files are used as input into a point set metric?

Harry-Zzz commented 3 years ago

Thank you for your reply. I have carefully studied the 'chicken' example. The three codes in this example use the nii.gz file in the form of grid as the input of point set. I don't see an example where CSV files can be input into ICP or PSE. If I change the fixedpoint or movingpoint file in the example from nii.gz file to CSV file, the file cannot be read.

ntustison commented 3 years ago

What is the format of your csv file? And please post the actual error message.

Harry-Zzz commented 3 years ago

The CSV file contains the following: image

Error message: Tried to create one of the following: BMPImageIO BioRadImageIO Bruker2dseqImageIO GDCMImageIO GE4ImageIO GE5ImageIO GiplImageIO HDF5ImageIO JPEGImageIO JPEG2000ImageIO LSMImageIO MGHImageIO MINCImageIO MRCImageIO MetaImageIO NiftiImageIO NrrdImageIO PNGImageIO StimulateImageIO TIFFImageIO VTKImageIO You probably failed to set a file suffix, or set the suffix to an unsupported type.

ntustison commented 3 years ago

Please post the fixed and moving point set files.

Harry-Zzz commented 3 years ago

fixed point set files: image moving points set files: image

ntustison commented 3 years ago

The actual .csv files, not images.

Harry-Zzz commented 3 years ago

What I provided before is a screenshot of the contents of the CSV file. The following is the original file: points1_after.csv points1_before.csv This is the file of the same person's calibration points before and after surgery. I want to align the points to assist image registration.

ntustison commented 3 years ago

It took me a bit to remember that the labeled point set reader doesn't take .csv files. Input should be a space-delimited file (no header) with a .txt filename suffix. I'm attaching your modified files. Please try these.

points1_before.txt points1_after.txt

Harry-Zzz commented 3 years ago

I tried the .txt file you gave, and the program can run normally. Thank you very much for your help!

Harry-Zzz commented 3 years ago

I want to realize the function of calibration point assisted image registration, similar to this form:

-m ICP[${fixedPoints},${movingPoints},1] \ -m MI[${fixedimg},${movingimg},1,32] \

I try to use ICP + Mi parameters for image registration. I hope that the internal marker points are as close as possible during image registration, but adding ICP parameters does not help the distance of marker points. I don't know what's wrong. Here's my code: ’‘’ fixedPoints='points2.txt' movingPoints='points5.txt' fixedimg='HeadCT_mosaic_id2.nii.gz' movingimg='HeadCT_mosaicid5.nii.gz' outputDirectory='result' outputPrefix=${outputDirectory}/pimg antsRegistration -d 3 -v 1 \ -o ${outputPrefix} \ -x [${fixedimg},${movingimg}] \ -r [${fixedimg},${movingimg},0] \ -m MI[${fixedimg},${movingimg},1,32] \ -t Affine[0.25] \ -c 2100x1200x1200x0 \ -s 3x2x1x0 \ -f 4x2x2x1 \ -m ICP[${fixedPoints},${movingPoints},1] \ -m MI[${fixedimg},${movingimg},1,32] \ -t SyN[0.2,3,0] \ -c [40x20x0,1e-8,8] \ -s 2x1x0 \ -f 4x2x1 ‘’‘ Here's my data: points5.txt points2.txt HeadCT_mosaic_id5.nii.gz HeadCT_mosaic_id2.nii.gz

Harry-Zzz commented 3 years ago

I saw the content about parameter weight on the wiki page, as shown in the screenshot. I saw from the sample code that the weight of CC is 0.6 and the weight of MI is 0.4. Why does the last sentence of the screenshot say that the weight of CC on T1 is equal to the weight of MI on T2? How should weights be defined? image

cookpa commented 3 years ago

The wiki page is wrong. I will fix it If the weights are 0.6 and 0.4 then the first metric has more weight. If they are 0.5 and 0.5 they are equal.

The weights are normalized so it's also valid to have equal weights of (1,1). Weights (2,1) would weight the first metric 2/3 and the second 1/3.

Harry-Zzz commented 3 years ago

Thank you for your answer. I found that the writing order of parameters will lead to different results, such as:

-m ICP[${fixedPoints},${movingPoints},1] -m MI[${fixedimg},${movingimg},1,32] and -m MI[${fixedimg},${movingimg},1,32] -m ICP[${fixedPoints},${movingPoints},1]

Two different writing methods in the program will get different results. Although they have the same meaning.Why does this happen? Which parameter should I put in the first place and which in the second place?

ntustison commented 3 years ago

If you think that's strange, you should try running it twice without changing the order.

Harry-Zzz commented 3 years ago

I tried a simple affine registration, and the results of different orders are really different. At the same time, I also ran the program twice without changing the order, and the results did not change. This is my code. I don't know if there's anything wrong: ’‘’ fixedPoints='points2.txt' movingPoints='points5.txt' fixedimg='HeadCT_mosaic_id2.nii.gz' movingimg='HeadCT_mosaicid5.nii.gz' outputDirectory='result' outputPrefix=${outputDirectory}/pimg antsRegistration -d 3 -v 1 \ -o ${outputPrefix} \ -r [${fixedimg},${movingimg},0] \ -m ICP[${fixedPoints},${movingPoints},1] \ -m MI[${fixedimg},${movingimg},1,32] \ -t Affine[0.25] \ -c 2100x1200x1200x0 \ -s 3x2x1x0 \ -f 4x2x2x1 ‘’‘

ntustison commented 3 years ago

Outside of the well-known random perturbations associated with running the antsRegistration program, changing the order of the input metrics should not matter. Perhaps those random perturbations are causing the deviation in your results. Without further investigation, it's hard to know what's going on.

cookpa commented 3 years ago

If you use multiple threads, MI metrics will differ between runs. I'm not sure about ICP.

https://github.com/ANTsX/ANTs/wiki/antsRegistration-reproducibility-issues

I would start by taking the affine out of the equation. Run the affine part only, save the output transform, and check the results. Then try this:

export ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS=1

antsRegistration -d 3 -v 1 
-o ${outputPrefix} 
-r [ myAffineRegOutput0GenericAffine.mat ] 
-m ICP[${fixedPoints},${movingPoints},1] 
-m MI[${fixedimg},${movingimg},1,32] 
-t SyN[0.2,3,0] 
-c [40x20x0,1e-8,8] 
-s 2x1x0 
-f 4x2x1

To quantify differences, MeasureImageSimilarity can tell you metric numbers. You can also create a difference image with ImageMath.

You might also want to rethink -x [${fixedimg},${movingimg}]. This will only mask out voxels that are 0. It would be best to make binary masks and confirm they contain the regions you want, or try running without masks (I think you're effectively doing that since most of your image is non-zero).