MathOnco / valis

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

Images not appearing in registered slide directory #150

Closed snackthingy closed 2 months ago

snackthingy commented 2 months ago

Hi! Me again!

I figured out my errors from last time and now my code runs without errors and goes to completion every time (although I still get warnings for having channel names which don't align with VALIS but I think I know how to fix that later). My main issue right is that nothing is appearing in my registered slide directory (registered_slide_dst_dir) and I don't know why. I have checked that the pathname is valid like a million times and I have things appearing in my results directory so I don't know what the issue is.

Any help would be appreciated.

Snack

cdgatenbee commented 2 months ago

Hi @snackthingy, Glad you got your other issue figured out, I'll go ahead and close that one. In this case, do you see any output when saving the slides? There should be progress bars to indicate how far along the saving process is, which can sometimes take a little while. If so, the filename for each slide should be the same as the original, but with the ome.tiff extension, in place of the original, e.g. img1.czi would get saved as img1.ome.tiff, and should be located in "registered_slide_dst_dir". Are you able to locate the images by searching for them?

Best, -Chandler

snackthingy commented 2 months ago

Hey Chandler,

I see progress bars for "Finding Features", "Converting Images" and other things of that sort that happen during registration, but after measuring error it kills the JVM without errors--no saving progress bar is displayed. My "registered_slide_dst_dir" is literally empty. Like nothing is there at all but I have all the masks and stuff in the results folder.

cdgatenbee commented 2 months ago

Would you mind sharing your code here? Maybe I can take a look and see what's going wrong.

snackthingy commented 2 months ago

Sure! Here you go! from valis import registration from valis.slide_io import BioFormatsSlideReader slide_src_dir = "/Users/User1/Desktop/Bop/Test Unreg" results_dst_dir = "/Users/User1/Desktop/Bop/Test Results" registered_slide_dst_dir = "/Users/User1/Desktop/Bop/Test Registered"

registrar = registration.Valis(slide_src_dir, results_dst_dir) rigid_registrar, non_rigid_registrar, error_df = registrar.register(reader_cls=BioFormatsSlideReader)

registration.kill_jvm()

cdgatenbee commented 2 months ago

Thanks @snackthingy! Saving the slides is actually a separate function, since you may want to make sure that the alignments look ok before saving slides. So, you'll need to call Valis.warp_and_save_slides after Valis.register, but before registration.kill_jvm():

from valis import registration
from valis.slide_io import BioFormatsSlideReader
slide_src_dir = "/Users/User1/Desktop/Bop/Test Unreg"
results_dst_dir = "/Users/User1/Desktop/Bop/Test Results"
registered_slide_dst_dir = "/Users/User1/Desktop/Bop/Test Registered"

# Perform registration
registrar = registration.Valis(slide_src_dir, results_dst_dir)
rigid_registrar, non_rigid_registrar, error_df = registrar.register(reader_cls=BioFormatsSlideReader)

# Save registered slides if the alignments look good
registrar.warp_and_save_slides(dst_dir=registered_slide_dst_dir, compression="deflate", Q=100)

# Kill JVM if all done
registration.kill_jvm()

Note that if your files are really large, you can lower Q to use lossy compression. If your images are 8bit RGB, you can also probably reduce the file size further by setting compression="jpeg". Anyway, please try that out and let me know how it goes.

Best, -Chandler

snackthingy commented 2 months ago

That worked and the images got saved correctly however, I am now realizing that there's no alignment actually going on. The z-stack I had is going away however they are not actually being aligned. In full honesty I've never done an alignment before so I am not 100% sure what I'm looking for in terms of successful alignment but I am 90% sure this isn't it (it looks exactly the same as the original just there's no z-stack and it's just the first layer)