MathOnco / valis

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

File size increasing 10 times after registrations #19

Closed tkobayashi6 closed 2 years ago

tkobayashi6 commented 2 years ago

Hello,

The file size of the registration image using VALIS is almost 10 times larger than the original WSI. I checked the source code of VALIS, but could not find the cause.

e.g. Original (ndpi format): 2.7GB ---> Registration (ome.tiff format): 26.3GB

I have two questions.

  1. Is there an optional argument for VALIS to solve this problem?
  2. Is it possible to resize them when saving registration images to reduce image size?

The code used to run the program is as follows

registrar = registration.Valis(
        src_dir=None,
        dst_dir=save_path,
        name=name,
        img_list=img_list,
        reference_img_f=reference_slide,
        align_to_reference=True,
)
rigid_registrar, non_rigid_registrar, error_df = registrar.register()
registrar.warp_and_save_slides(
        dst_dir=save_path,
        crop='reference',
)

Best regards,

cdgatenbee commented 2 years ago

Yikes, that is a big difference! Since you're cropping the new image to have to the reference image's shape, the new WSI should have a similar file size as the reference image. This makes me think the larger file size may be due to the image compression method. The default is lzw compression, but perhaps jpeg compression would be better? Valis uses pyvips to save the images, and so a full list of the compression methods can be found here. To use a different compression method, just set compression="jpeg" (or whichever method you prefer) when calling registrar.warp_and_save_slides.

Regarding your second question, yes, it is possible to reduce the image size before saving. There are actually several ways this could be done. The easiest way would be to set the the level argument when calling registrar.warp_and_save_slides, where level is the pyramid level resolution, so 0 is the full size image, and larger values will get lower resolution images. You can see how many pyramid levels there are, and the size of each one, by looking at each Slide object's slide_dimensions_wh attribute (the Slide objects can be accessed in the Valis object's slide_dict attribute). Alternatively, if you'd like more control over the size of each image, then you could resize each registered image before saving, but this would need to be done outside registrar.warp_and_save_slides, and you would also need to create the ome-xml for each image before saving as an ome.tiff. If you're interested in this approach, I can put together some example code for you. I would normally just do it, but I'm in the process of setting up a new laptop and so it might take a little longer to get it to you. Still happy to put it together if you're interested though.

Best, Chandler