Can we use Openslide or do we have a tool to open MRXS files from microscope?

I was thinking if there is a way we can open MRXS file in Julia, like Openslide in Python? I tried to install openslide using CondaPkg.jl, but when using PythonCall.jl to import openslide, it does not work. (it works for torch and other packages like rdkit…)

I think the easiest way to help is if you can elaborate on why it doesn’t work or show the error from the installation?
This advice might be useful, particularly (4.).

It would spit Module not found Error, but it was installed shown from conda status

o = pyimport("openslide") 
or @py import openslide

ERROR: Python: ModuleNotFoundError: No module named 'openslide'
Python stacktrace: none
Stacktrace:
 [1] pythrow()
   @ PythonCall ~/.julia/packages/PythonCall/XgP8G/src/err.jl:94
 [2] errcheck
   @ ~/.julia/packages/PythonCall/XgP8G/src/err.jl:10 [inlined]
 [3] pyimport(m::String)
   @ PythonCall ~/.julia/packages/PythonCall/XgP8G/src/concrete/import.jl:11
 [4] top-level scope
   @ ~/百度云同步盘/StudyResearch/AIforLS/AIforLS1.jl:12
conda status
Packages
  numpy v1.22.3
  openslide v3.4.1
  pytorch v1.11.0
  rdkit v2022.03.1

Is there julia package which can read MRXS files?

This is the C package. You probably want openslide-python:
https://anaconda.org/conda-forge/openslide-python

For example:

using CondaPkg
using PythonCall

pkg> conda add openslide-python

ops = pyimport("openslide")
1 Like

Yeah, this works, thank you so much!!! :grinning:

BTW, why CondaPkg can install C package instead of python package?

1 Like

Conda : Conda — Conda documentation

Package, dependency and environment management for any language—Python, R, Ruby, Lua, Scala, Java, JavaScript, C/ C++, Fortran, and more.

Thank you for your information! :+1:

I am aware of that, I thought CondaPkg.jl was specifically for PythonCall.jl :smiley:

For future reference, minimal working example for test data:

mkdir("test_data")
Base.download("https://openslide.cs.cmu.edu/download/openslide-testdata/Mirax/Mirax2-Fluorescence-1.zip", "./test_data/Mirax2-Fluorescence-1.zip")
run(`unzip ./test_data/Mirax2-Fluorescence-1.zip -d ./test_data`) # This may be system dependent
s = ops.OpenSlide("./test_data/Mirax2-Fluorescence-1.mrxs")
# Get metadata properties about the slide:
p = PyDict{String,String}(s.properties)

# Save image data:
im = PyDict{String, Py}(s.associated_images)
im["label"].save("label.png")
1 Like

You are so kind!!! I appreciate your help :smiley:

For what it’s worth you can also get the C library in Julia with

Pkg.add("OpenSlide_jll")

Then of course you’ll want wrapper functions which ccall into the library. Those are quite straightforward to implement except you need to decide how to handle the row-major nature of image patches, whether you want convenience functions which allocate buffers for you, and to what extent you want to integrate with Images.jl. I have written such a package at work but that code is proprietary.

1 Like

Do you mean after using CondaPkg.jl to install the c library Openslide, we can add openslide_jll binary binder to use the C library Openslide?
How do we do that exactly?Could you show some examples? or could you point to some tutorial which explain how to do this in general? compare to just using openslide-python will it be faster?

Thank you!

The OpenSlide_jll would be an alternative that involves neither Conda nor Python in any form. But as I wrote you would need to handle the interfacing with the library yourself.

Ok, here’s a minimal example you can try. After doing

using Pkg
Pkg.add("OpenSlide_jll")
using OpenSlide_jll
function openslide_get_version()
    return unsafe_string(ccall((:openslide_get_version, libopenslide), Cstring, ()))
end

you should be able to run

julia> openslide_get_version()
"3.4.1"
2 Likes

It sounds great :+1:
I got the following error:

ERROR: UndefVarError: libopenslide not defined

Should I install other things except openslide_jll(already installed)?

libopenslide is exported by OpenSlide_jll so if

using OpenSlide_jll
libopenslide

gives an error, something is badly broken.

Ok, thank you! then I will stick to openslide-python for now, will explore this track later.

I was wondering do you know if is there some package that can anonymize the mrxs slide?

Sorry, I really know nothing about mrxs data.

1 Like