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

Make it easier to deal with InexactError on save() #422

Closed
xanderdunn opened this issue Dec 5, 2015 · 5 comments
Closed

Make it easier to deal with InexactError on save() #422

xanderdunn opened this issue Dec 5, 2015 · 5 comments

Comments

@xanderdunn
Copy link

I am trying to save("image.png", myimg) where myimg =

RGB Images.Image with:
  data: 160x210 Array{ColorTypes.RGB{Float64},2}
  properties:
    timedim: 0
    spatialorder:  y x
    pixelspacing:  1.0 1.0

And I always get this error:

INFO: Recompiling stale cache file /Users/admin/.julia/lib/v0.4/ImageMagick.ji for module ImageMagick.
WARNING: InexactError()
 in trunc at float.jl:357
 in _map_a! at /Users/admin/.julia/v0.4/Images/src/map.jl:381
 in map! at /Users/admin/.julia/v0.4/Images/src/map.jl:373
 in image2wand at /Users/admin/.julia/v0.4/ImageMagick/src/ImageMagick.jl:151
 in save_ at /Users/admin/.julia/v0.4/ImageMagick/src/ImageMagick.jl:146
 in save at /Users/admin/.julia/v0.4/ImageMagick/src/ImageMagick.jl:64
 in save at /Users/admin/.julia/v0.4/FileIO/src/loadsave.jl:92
 in save at /Users/admin/.julia/v0.4/FileIO/src/loadsave.jl:51
 in getstate at /local/dev/odin-core/AgentEnvironmentInterface/src/environment/pong.jl:94
 in include at /usr/local/Cellar/julia/0.4.1/lib/julia/sys.dylib
 in include_from_node1 at /usr/local/Cellar/julia/0.4.1/lib/julia/sys.dylib
 in process_options at /usr/local/Cellar/julia/0.4.1/lib/julia/sys.dylib
 in _start at /usr/local/Cellar/julia/0.4.1/lib/julia/sys.dylib

Is it the same as #213?

I'm on released Julia 0.4 with:

  • ImageMagick 0.1.1
  • Images 0.5.0
@kalvotom
Copy link

kalvotom commented Dec 6, 2015

I run into a similar problem. My image is gray scale only:

julia> img
Gray Images.Image with:
  data: 60x60 Array{Float64,2}
  properties:
    colorspace: Gray
    spatialorder:  x y

save fails with:

julia> save("fig.png", img)
WARNING: InexactError()
 in trunc at float.jl:357
 [inlined code] from /home/kalvin/.julia/v0.5/FixedPointNumbers/src/ufixed.jl:54
 in _map_a! at /home/kalvin/.julia/v0.5/Images/src/map.jl:381
 in map! at /home/kalvin/.julia/v0.5/Images/src/map.jl:373
 [inlined code] from /home/kalvin/.julia/v0.5/Images/src/map.jl:349
 in image2wand at /home/kalvin/.julia/v0.5/ImageMagick/src/ImageMagick.jl:151
 in save_ at /home/kalvin/.julia/v0.5/ImageMagick/src/ImageMagick.jl:146
 in save at /home/kalvin/.julia/v0.5/ImageMagick/src/ImageMagick.jl:64
 in save at /home/kalvin/.julia/v0.5/FileIO/src/loadsave.jl:92
 in save at /home/kalvin/.julia/v0.5/FileIO/src/loadsave.jl:51
 in eval at ./boot.jl:264

My Julia version is julia version 0.5.0-dev, running on a Linux operating system.

Interestingly, I am able to save the image provided it contains only 0.0 and 1.0 entries...

@timholy
Copy link
Member

timholy commented Dec 9, 2015

This is deliberate; see #256 (comment). The error message is thrown to warn you that your image has values that cannot be represented in the file format.

You can use clamp!(img2, 0, 1) or more generally the ClampMinMax or Clamp01NaN. See the online help on each.

@timholy timholy closed this as completed Dec 9, 2015
@xanderdunn
Copy link
Author

This is what worked for me: save("image.png", rgb_image, mapi=Images.mapinfo(Images.Clamp, rgb_image))

This was very non-intuitive. I was able to figure it out by looking at a test in test.io.jl that doesn't exist anymore.

@timholy
Copy link
Member

timholy commented Dec 9, 2015

It's over at ImageMagick.jl.

@timholy timholy reopened this Dec 9, 2015
@timholy timholy changed the title InexactError on save() Make it easier to deal with InexactError on save() Dec 9, 2015
@timholy timholy closed this as completed in 4143968 Dec 9, 2015
@timholy
Copy link
Member

timholy commented Dec 9, 2015

Oops, meant to push that to a branch. See also JuliaIO/ImageMagick.jl#18.

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

No branches or pull requests

3 participants