MathOnco / valis

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

Passing a rigid transformation to the registrar #147

Open pauldoucet opened 1 month ago

pauldoucet commented 1 month ago

Good morning,

Thank you for your great work. Let's say that I need to register a slide to its reference and that I already know the affine transformation to the reference (affine transformation coordinate system is the full resolution source WSI in pixels). Is there a way to set my already predetermined affine transformation in the registrar in order to bypass the rigid-registration.

I attempted to set the M attribute with some scaling factory, but there is a scaling problem:

  sxy = src.slide_dimensions_wh[0] / src.processed_img_shape_rc[::-1]

  M[0, 2] = M[0, 2] / sxy[0]
  M[1, 2] = M[1, 2] / sxy[1]

  registrar.slide_dict['src'].M = M
cdgatenbee commented 1 month ago

Hi @pauldoucet,

Apologies for the delayed response, I've been out of town for the last 2 weeks, and had limited internet access. To answer your question though, it's not that well documented, but it is possible to pass in rigid transformations using the do_rigid argument. The affine transform just needs to be the inverse transform, found by aligning fixed to moving. If the affine transform was found by aligning the moving image to the fixed image, you'll first need to invert the affine transform. If M was found using the full resolution src/moving image, and you're aligning to the full resolution dst/fixed image, you just need to create a dictionary, where the key is the filename of the moving/src image, and the value is another dictionary, where the 3x3 affine matrix is the value for the "M" key. Together, the code would be

from valis import registration
rigid_M_dict = {"src":{"M":M}}
registrar = registration.Valis(src_dir, dst_dir, reference_img_f=dst_f, do_rigid=rigid_M_dict)
rigid_registrar, non_rigid_registrar, error_df = registrar.register()

Please try that out and let me know how it goes.

Best, -Chandler

pauldoucet commented 4 weeks ago

Thank you, I'll give it a try,

Best,

Paul

pauldoucet commented 1 week ago

Hello, Is there a way to completely skip the coarse non-rigid/rigid registration and only apply a micro-registration?

I tried the following without success:

registrar = registration.Valis(
    '', 
    'local/registrar', 
    reference_img_f=he_path, 
    align_to_reference=True,
    img_list=img_list,
    check_for_reflections=False,
    do_rigid=False
)

registrar.register(
    brightfield_processing_cls=preprocessing.HEDeconvolution,
)

registrar.register_micro(
    max_non_rigid_registration_dim_px=10000,
    align_to_reference=True, 
    brightfield_processing_cls=preprocessing.HEDeconvolution,
    reference_img_f=he_path
)