MathOnco / valis

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

Apply registration to new image does not work using the warp_slide function. #77

Closed linchundan88 closed 1 year ago

linchundan88 commented 1 year ago

My problem is related to closed issue, i.e, issue 63,49(Apply registration to new image), and 41(H&E deconvolution pre-processing) I have two consecutive slides one was stained by HE(filename :211175HE) and the other was stained by H+DAB(filename: 211175CD8). The slide 211175HE and slide 211175CD8 were split into 211175HE_h,211175HE_e and 211175CD8_h and 211175CD8_d using color deconvolution, respectively. The 211175HE_h was considered as the reference image, and 211175CD8_h registered to it beautifully. I want to use the same transformation parameters to register slide 211175CD8_d.

code file 1: slide_src_dir = f"/data/wsi_registration/my_data1/src/211175" results_dst_dir = f"/data/wsi_registration/my_data1/dest1_results/211175" registered_slide_dst_dir = f"/data/wsi_registration/my_data1/dest1_slides/211175"

img_list = ['/data/wsi_registration/my_data1/src/211175/211175HE_h.tiff', '/data/wsi_registration/my_data1/src/211175/211175CD8_h.tiff'] reference_slide = f"/data/wsi_registration/my_data1/src/211175/211175HE_h.tiff"

Create a Valis object and use it to register the slides in slide_src_dir

registrar = registration.Valis(slide_src_dir, results_dst_dir, img_list = img_list, reference_img_f=reference_slide, align_to_reference=True, max_processed_image_dim_px=8502, max_non_rigid_registration_dim_px=8502) rigid_registrar, non_rigid_registrar, error_df = registrar.register()

Save all registered slides as ome.tiff

registrar.warp_and_save_slides(registered_slide_dst_dir, compression="jpeg", Q=80, crop="all") # overlap, reference, all

code file 2: src_reg = '/data/wsi_registration/my_data1/dest1_results/211175/211175/data/211175_registrar.pickle'
src_slide = '/data/wsi_registration/my_data1/src/211175/211175HE_h.tiff' dst_slide = '/data/wsi_registration/my_data1/src/211175/211175CD8.tiff' dst_dir = '/data/wsi_registration/my_data1/dest2_slides/211175/211175CD8.ome.tiff'

read in the registrar

registrar = pickle.load(open(src_reg,'rb'))

pull out the previously registered slide

slide_obj = registrar.get_slide(src_slide)

warped_slide = slide_obj.warp_slide(level=0, non_rigid=True, crop="reference", src_f=dst_slide) slide_io.save_ome_tiff(img=warped_slide, dst_f=dst_dir, compression="jpeg", Q=80)

My code file1 ran just as expected, however the slide was not registered by code file2 at all.

The paper "Virtual alignment of pathology image series for multi-gigapixel whole slide images" is great, I will cite it in my research paper. Please help me. Thanks in advance.

linchundan88 commented 1 year ago

I have found the reason. slide_obj = registrar.get_slide(src_slide). The src_slide parameter in function get_slide should be the 211175CD8_h.tiff rather than the reference slide. This issue can be closed.