MathOnco / valis

Virtual Alignment of pathoLogy Image Series
https://valis.readthedocs.io/en/latest/
MIT License
117 stars 28 forks source link

Non Rigid registration #140

Open simomounir opened 2 months ago

simomounir commented 2 months ago

Hi all,

We know from documentation that non-rigid registration needs a moving_img and a fixed_img argument.

Under the example scripts folder https://github.com/MathOnco/valis/blob/main/examples/register_ihc.py in line 60, both non-rigid and rigid registrations happen, but I see no specification of fixed_img and moving_img arguments. Are they just picked randomly? Or can someone give us some example script showing how to play around with non_rigid registration parameters and input?

Thanks in advance for looking into this.

Cheers,

cdgatenbee commented 2 months ago

Hi @simomounir, Apologies for the delayed response, but to answer your question, how Valis determines what the moving and fixed images are will depend on the number of images and what arguments are used. If aligning two images, the "fixed_img" can be specified by setting reference_img_f to the filename of the fixed image, and align_to_reference=True when creating the Valis object. In this case, the "moving" image will be the other image. However, if reference_img_f=None, then the fixed image is the 1st image in the directory, and the 2nd image is moving image. Alternatively, if one provides a list of paths to the images (the img_list argument) in addition to src_dir, then the 1st image in img_list will be the fixed image, and the 2nd image will be the moving image.

Things get a bit more complicated when there are more than 2 images, . The default assumption is that the images are un-ordered (imgs_ordered=False, e.g. not a 3D image stack) and there is no reference image (reference_img_f=None). Given these parameters, Valis will sort the images by similarity, such that each image's neighbors in the z-stack are similar to that image. The images then are aligned from the center out. For example, if there are 5 images, the first fixed image is 3, and the first moving image is 2, which after warping becomes 2', which I'll indicate as 2 -> 3 = 2', or moving -> fixed = registered moving. Image 2' now becomes the fixed image, and 1 is the new moving image, i.e. 1 -> 2' = 1'. The process then gets repeated for the other half of the stack, i.e. 4 -> 3 = 4', 5-> 4' = 5'. In this case, the center image is always a fixed image, and never a moving image.

If a reference image is specified (i.e. reference_img_f is not None) and align_to_reference=False, then reference_img will always be a fixed image, and never a moving image. For example, if reference_img_f is Image 2, then the alignment would go 1 -> 2 = 1', 3 -> 2 = 3', 4 -> 3' = 4', 5 -> 4' = 5'.

If a reference image is specified (i.e. reference_img_f is not None) and align_to_reference=True, then all images get aligned to the reference_img, i.e. 1 -> 2 = 1', 3 -> 2 = 3', 4 -> 2 = 4', 5 -> 2 = 5', again assuming Image 2 is the reference image.

Finally, if imgs_ordered=True, then Valis will not sort the images based on similarity, but will sort them alphanumerically based on their filename, which is often how serial slices from 3D tissues are named. So, in this case, the alignment would go 2 -> 1 = 2', 3 -> 2' = 3', 4 -> 3' = 4', 5 -> 4' = 5'.

Sorry there isn't really a simple answer to your question, but I hope the above helps clarify how Valis determines what is the fixed and moving images. But please let me know if you have any other questions or would like some more clarification.

Best, -Chandler