Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Point based registration #1222

Open
Harry-Zzz opened this issue Aug 12, 2021 · 18 comments
Open

Point based registration #1222

Harry-Zzz opened this issue Aug 12, 2021 · 18 comments

Comments

@Harry-Zzz
Copy link

Harry-Zzz commented Aug 12, 2021

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,<samplingPercentage=[0,1]>,<boundaryPointsOnly=0>], 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
Copy link
Member

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

@Harry-Zzz
Copy link
Author

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
Copy link
Member

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

@Harry-Zzz
Copy link
Author

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
Copy link
Member

Please post the fixed and moving point set files.

@Harry-Zzz
Copy link
Author

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

@ntustison
Copy link
Member

The actual .csv files, not images.

@Harry-Zzz
Copy link
Author

Harry-Zzz commented Aug 13, 2021

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
Copy link
Member

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
Copy link
Author

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

@Harry-Zzz
Copy link
Author

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_mosaic_id5.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
Copy link
Author

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
Copy link
Member

cookpa commented Sep 8, 2021

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
Copy link
Author

Harry-Zzz commented Sep 9, 2021

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
Copy link
Member

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

@Harry-Zzz
Copy link
Author

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_mosaic_id5.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
Copy link
Member

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
Copy link
Member

cookpa commented Sep 9, 2021

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants