MathOnco / valis

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

TurboJPEG error? #80

Closed billnjcn111 closed 11 months ago

billnjcn111 commented 11 months ago

when creating a Valis object and use it to register the slides in slide_src_dir: registration.Valis(slide_src_dir, results_dst_dir) showed error: java.lang.RuntimeException: java.lang.RuntimeException: TurboJPEG could not be loaded; my image format is mrxs. Thanks

cdgatenbee commented 11 months ago

Hello @billnjcn111, Could you please verify that you have turbojpeg installed? It's not a Python dependency, and so doesn't get installed via pip and may need to be installed separately.

Best, -Chandler

kayleefang commented 11 months ago

Hi @cdgatenbee, I'm running into the same issue. I've installed jpeg-turbo via homebrew, and added the path pointing to the installation in my PATH, but the error still pops up and I am unable to create the VALIS object.

For reference, I'm running this on MacOS ARM64.

cdgatenbee commented 11 months ago

Hi @kayleefang, Sorry to hear that you're having this issue too. I'm also running on macos arm64, so I don't think this is necessarily an apple silicon issue, so could you tell me a bit more about your environment (i.e. any conda? all homebrew?)? Just wondering if there is any way that maybe libvips/pyvips/java/openslide was installed one way (conda), and turbojpeg another (homebrew), which could be a possible reason why turbojpeg isn't being found. Also, to help narrow things down, are you able to import pyvips, scyjava, and jpype ok? Is it possible to initialize the JVM via slide_io.init_jvm()? Please let me know and we'll go from there.

Best, -Chandler

billnjcn111 commented 11 months ago

I can import pyvips, scyjava, and jpype; slide_io.init_jvm() will just produce the error: java.lang.RuntimeException: TurboJPEG could not be loaded. is it needed? also where should I install it to? Update: even after installing the turboJPEG package to the virtual env, same error

kayleefang commented 11 months ago

Hi @cdgatenbee,

Thanks for your quick response! I'm working in a conda environment, and used pip to install valis in the environment along with necessary packages through pip install valis-wsi. Before this, I installed libvips and turbojpeg through homebrew, and I reinstalled Java and installed Maven as per the installation instructions. Could something with these different installations be causing the issue?

I'm able to import pyvips, scyjava, and jpype perfectly well. Initializing the JVM via slide_io.init_jvm does not return any errors, and running jpype.isJVMStarted() returns True. The issue comes when I run slide_io.get_bf_readable_formats(), which is where the original error is thrown when trying to create the valis object. This causes the "TurboJPEG could not be loaded" error.

cdgatenbee commented 11 months ago

Hi @kayleefang and @billnjcn111, Do you happen to know which version of bioformats you are using? Apparently, 7.0.1 is problematic on M1 macs, and it's recommended to use 7.0.0 until 7.1.0 comes out: https://forum.image.sc/t/bioformats-7-0-1-apple-arm-processor-regression/88713

As an alternative, if you're ok using Docker, there is a container available on DockerHub that has everything installed and should at least get you to where you can test out valis. It's worth noting that it is also possible to launch that container using a different entrypoint so that you can use the container's environment inside of Visual Studio Code, allowing you to run your code and debug like you would normally. If that sounds like something you'd be interested in but have questions about, let me know and I can put together some instructions on how to do it.

Best, -Chandler

kayleefang commented 11 months ago

Hi @cdgatenbee, This seems to be the fix on my machine! Switching bioformats from 7.0.1 to 7.0.0 immediately resolved all the issues. Thank you so much for all of your help!!

cdgatenbee commented 11 months ago

Great, glad to hear it @kayleefang! Good luck, and please let know if you run into any more issues.

Best, -Chandler

billnjcn111 commented 11 months ago

@cdgatenbee @kayleefang can I ask how you changed to 7.0.0 of bio formats? thanks!

cdgatenbee commented 11 months ago

Hi @billnjcn111, Bioformats 7.0.0 is available here, but you just need bioformats_package.jar. After you've downloaded bioformats_package.jar, you can use that version by passing its path to slide_io.init_jvm, which you might want to do at the top of your script:

from valis import registration, slide_io
slide_io.init_jvm(jar="/path/to/bioformats_package.jar")

registrar = registration.Valis(src_dir, dst_dir)
rigid_registrar, non_rigid_registrar, error_df = registrar.register()

Please give that a try and let me know how it goes.

Best, -Chandler

billnjcn111 commented 11 months ago

the error now is gone! it seems everything works now! thanks!

cdgatenbee commented 11 months ago

Great news, @billnjcn111! I'll go ahead and close this issue, but if you run into any other problems please don't hesitate to open a new one.