Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saving to TIFF - FileIO tries to save with OMETIFF #160

Closed
MLackner opened this issue Nov 23, 2017 · 6 comments · Fixed by #166
Closed

Saving to TIFF - FileIO tries to save with OMETIFF #160

MLackner opened this issue Nov 23, 2017 · 6 comments · Fixed by #166

Comments

@MLackner
Copy link

MLackner commented Nov 23, 2017

The save function for tiff images tries to default to OMETIFF which does not have a saver defined:

using FileIO
using TestImages

img = load("moonsurface.tiff")
save("img.tiff", img)

Gives the following error:

Error encountered while saving "img.tiff".
Fatal error:
ERROR: OMETIFF writer error: save not defined
  Will try next writer.

Stacktrace:
 [1] #save#21(::Array{Any,1}, ::Function, ::FileIO.File{FileIO.DataFormat{:OMETIFF}}, ::Array{ColorTypes.Gray{FixedPointNumbers.Normed{UInt8,8}},2}, ::Vararg{Array{ColorTypes.Gray{FixedPointNumbers.Normed{UInt8,8}},2},N} where N) at /Users/lackner/.julia/v0.6/FileIO/src/loadsave.jl:113
 [2] save(::FileIO.File{FileIO.DataFormat{:OMETIFF}}, ::Array{ColorTypes.Gray{FixedPointNumbers.Normed{UInt8,8}},2}) at /Users/lackner/.julia/v0.6/FileIO/src/loadsave.jl:106
 [3] #save#14(::Array{Any,1}, ::Function, ::String, ::Array{ColorTypes.Gray{FixedPointNumbers.Normed{UInt8,8}},2}, ::Vararg{Array{ColorTypes.Gray{FixedPointNumbers.Normed{UInt8,8}},2},N} where N) at /Users/lackner/.julia/v0.6/FileIO/src/loadsave.jl:61
 [4] save(::String, ::Array{ColorTypes.Gray{FixedPointNumbers.Normed{UInt8,8}},2}) at /Users/lackner/.julia/v0.6/FileIO/src/loadsave.jl:61

I've got ImageMagick installed.

Edit:
Found a workaround by saving via:

io = open("img.tiff", "w")
save(Stream(format"TIFF", io), img)
close(io)
@timholy
Copy link
Member

timholy commented Nov 24, 2017

CC @tlnagy. I messed up in merging #147 by not noticing that it only supports loading, not saving. Probably need to use add_loader and add_saver explicitly, not the short form of add_format; see the README.

@tlnagy
Copy link
Contributor

tlnagy commented Nov 24, 2017 via email

@tlnagy
Copy link
Contributor

tlnagy commented Nov 28, 2017

This actually is harder than I originally thought because currently there is no way to supply a function to add_loader and I'm not sure how to get achieve the add_format functionality without triggering add_saver. My understanding of the exact mechanics inside FileIO is pretty shaky though. Any thoughts @timholy?

@timholy
Copy link
Member

timholy commented Nov 28, 2017

What happens when the regular tiff reader is passed an OME TIFF file? If it errors, couldn't you add OMETIFF via add_loader rather than defining it as a separate format?

If that's not possible, then life is harder. When saving the only way to detect the format is through the filename, but

julia> splitext("test.ome.tif")
("test.ome", ".tif")

yields the regular TIFF extension. I see three potential solutions:

  • (best but hardest) change FileIO to allow one to define a "cascade" of extensions, i.e., defining [".tif", ".ome"] as the extension for format"OMETIFF".
  • (easy but unsatisfying) remove the registration of OMETIFF by reverting add support for loading OME-TIFFs #147. This would require users to know about OMETIFF.jl and use it manually
  • (dirty rotten hack) reverse the order of the TIFF and OMETIFF lines in registry.jl. Should work because of the 1 in this line.

tlnagy added a commit to tlnagy/FileIO.jl that referenced this issue Nov 28, 2017
@tlnagy
Copy link
Contributor

tlnagy commented Nov 28, 2017

Thanks for the clarification. A regular TIFF reader can read a OME-TIFF file and vice versa (this was done on purpose). The only difference is the extension name and the presence of extra metadata in OME-TIFFs.

I chose option 3 in #166 for now, but I'll open a feature request for option 1 to keep track of this feature request.

@timholy
Copy link
Member

timholy commented Nov 28, 2017

Oh, and to answer

Why doesn't FileIO fall back to Imagemagick automatically since OMETIFF saver is missing?

It's because format"OMETIFF" != format"TIFF". As far as FileIO is concerned, these two have absolutely nothing to do with each other.

Given that they are, in fact, a single format, we probably want to move towards a FileIO design that respects that. We might want a single format, format"TIFF", and use some more subtle mechanism to determine which package to call. For example, one option would be to try OMETIFF, if installed, and then if OMETIFF doesn't detect the extra metadata have it throw an error. That would cause the standard TIFF reader to be called. That might be a little expensive (unwinding stack frames takes a lot of time), so presumably a better option would be to put more smarts into FileIO.

The main issue is that FileIO's architecture might have to change a bit, so that detection-functions can winnow the list of available packages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants