ahnlabb / BioformatsLoader.jl

A julia package to load images using bioformats
Other
17 stars 7 forks source link

Loading images from the web. #12

Closed RainerHeintzmann closed 3 years ago

RainerHeintzmann commented 3 years ago

Does BioformatsLoader.jl support loading from a web-address? I think the underlying java implementation does, but there seem to be problems using this feature:

julia> using JavaCall, BioformatsLoader

julia> using Images

julia> JavaCall.addClassPath(BioformatsLoader.get_bf_path())

julia> JavaCall.addOpts("-Xmx2048M"); # Set maximum memory to 1 Gigabyte

julia> BioformatsLoader.init(); # Initializes JavaCall with opt and classpath

julia> img = bf_import(raw"https://mirror.imagej.net/images/m51.tif")
 *** One or more readers is misbehaving. See the debug output for more information. e.g.:
     loci.formats.in.APLReader@292b08d6 -> java.lang.NullPointerException('null') ***

Can this be fixed? Would be a great feature.

ahnlabb commented 3 years ago

I can't see that this feature is provided by the Bio-Formats java implementation. If you have more information on where you've encountered this feature it would be great if you shared that here. I can see that the python-bioformats package provides this feature, however, they are using urllib to perform the download in python. I agree that it would be useful (particularly internally for testing) and on the latest master I have added the BioformatsLoader.bf_import_url function. Please test that function and tell me if exposing that function would solve this issue.

RainerHeintzmann commented 3 years ago

It works like a charm! Why not allowing bf_import() to branch to bf_import_url() in case the file starts with http: or https: ?

RainerHeintzmann commented 3 years ago

By the way: You may want to add 'Downloads' to the dependencies. This is a warning one gets during build.

ahnlabb commented 3 years ago

Why not allowing bf_import() to branch to bf_import_url() in case the file starts with http: or https: ?

I'm still pondering this, I feel like if bf_import is flexible with paths/URLs people will expect it to handle all URLs in a somewhat consistent manner (at least file:// in addition to http:// and https://) and in that case maybe I would need to depend on URIs.jl.

I can definitely see that it could be convenient and with bf_import I've tried to create a "magic" function that handles most use cases since it seems like users who have used Bio-Formats from MATLAB or ImageJ expect this and don't want to deal with the details of the Bio-Formats java implementation.

What are your thoughts? Could you tell me a bit more about your use case?

RainerHeintzmann commented 3 years ago

That sounds like a sensible choice, using URIs.jl. Indeed, the function is very handy. My use case is simply being able to load all kinds of microscopy data formats.
Admittedly using the ability to load web data is nice for image processing courses and alike, since then you do not need to waist time explaining how to download data, find it and open it. The other alternative would be ``TestImages.jl", but the Fiji community already put together an impressive range of useful datasets.

roflmaostc commented 3 years ago

Since it is merged now, thanks! Would you mind releasing a new minor version (probably 2.1.0?)?

ahnlabb commented 3 years ago

This is now in version 0.3.0