Is there a better solution for head registration?

What about the random array code snippet:

import numpy as np
im2 = np.random.rand(208,256,240)
print(((im2-im2.mean())**2).mean())
print((im2**2).mean() - im2.mean()**2)

Do the two prints give almost the same value for you?

yes,i use random code , it’s the same
image

then I am super confused why it’s not working for these specific images… what it is about them that makes this fail?

I would be happy to look if you want to share the images. sharing im1 would be sufficient

otherwise I would suggest doing some debugging because ((im2-im2.mean())**2).mean() and (im2**2).mean() - im2.mean()**2 should be almost equal for any real valued arrays, and please let me know if you discover the issue

okay,i will save the two images into SlicerScarlarVolumeNode .mrb format
here is the dropbox link

Thank you for sharing
It was an integer overflow :laughing:

Your arrays have a dtype of 16 bit ints.

if you up to 32-bit then those numbers come out the same and you should no longer have a negative under the square root:

im1 = im1.astype(np.int32)
im2 = im2.astype(np.int32)
2 Likes

thank you very much!
it indeed is the problem of integer overflow.
it’s now work!!

1 Like

i paste my code in slicer here , i found the result of ncc related to the value of [default_sample_value],the [default_sample_value] is the blank area of moved image voxel value,do you have any suggestion on how to set the [default_sample_value] value?
for example:
for T1 as fixed image,CT as moved image ,the [default_sample_value] set to -1000 can represent the register result quanlity
but T1 as fixed image,Flair as moved image,the [default_sample_value] set to -1000 can not represent the register result quanlity,set to 0 is better.
image

The default pixel value should be set based on what you want in the end, and what makes sense for the modality. Whatever value shows up in the "background’ of your image would make sense. For CT -1000 perhaps makes sense because the Hounsfield scale is designed so that air has value -1000. For any other modalities you can look at a sample image and check what is the voxel value in the background region.

I think the effect on NCC of your choice of default pixel value is not directly relevant to registration quality. In fact, if you can do it then I think it’s best to compute NCC only in the intersection of the two image domains, where no value was sampled from outside the boundary of the moving image and the default pixel value is never used. I would say it’s good enough to just choose a default pixel value that makes sense for the modality, not one that maximizes NCC.

thank you , i understand your suggestion , i will try to compute NCC only in the intersection of the two image domains