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

IJulia can't display Float64 Gray images? #548

Closed
tlnagy opened this issue Aug 30, 2016 · 13 comments
Closed

IJulia can't display Float64 Gray images? #548

tlnagy opened this issue Aug 30, 2016 · 13 comments

Comments

@tlnagy
Copy link
Contributor

tlnagy commented Aug 30, 2016

using Colors
using Images
srand(1234)
img = convert(Image{Gray}, rand(10,10))
show(img)
Gray Images.Image with:
  data: 10×10 Array{ColorTypes.Gray{Float64},2}
  properties:
    timedim: 0
    spatialorder:  y x
    pixelspacing:  1.0 1.0
x, y = imgradients(img)
x
WARNING: InexactError()
 in trunc(::Type{UInt8}, ::Float64) at ./float.jl:458
 in convert at /Users/tamasnagy/.julia/v0.5/FixedPointNumbers/src/ufixed.jl:54 [inlined]
 in cnvt at /Users/tamasnagy/.julia/v0.5/Colors/src/conversions.jl:174 [inlined]
 in _convert(::Type{ColorTypes.RGBA{FixedPointNumbers.UFixed{UInt8,8}}}, ::Type{ColorTypes.RGB}, ::Type{ColorTypes.Gray}, ::ColorTypes.Gray{Float64}) at /Users/tamasnagy/.julia/v0.5/Colors/src/conversions.jl:45
 in copy!(::Base.LinearFast, ::Array{ColorTypes.RGBA{FixedPointNumbers.UFixed{UInt8,8}},2}, ::Base.LinearFast, ::Array{ColorTypes.Gray{Float64},2}) at ./abstractarray.jl:559
 in convert(::Type{Array{ColorTypes.RGBA{FixedPointNumbers.UFixed{UInt8,8}},N}}, ::Array{ColorTypes.Gray{Float64},2}) at /Users/tamasnagy/.julia/v0.5/Images/src/core.jl:401
 in _convert(::Type{Images.Image{ColorTypes.RGBA{FixedPointNumbers.UFixed{UInt8,8}},N,A<:AbstractArray}}, ::Images.Image{Float64,2,Array{Float64,2}}) at /Users/tamasnagy/.julia/v0.5/Images/src/core.jl:467
 in save_(::String, ::Images.Image{Float64,2,Array{Float64,2}}, ::String) at /Users/tamasnagy/.julia/v0.5/QuartzImageIO/src/QuartzImageIO.jl:262
 in getblob(::Images.Image{Float64,2,Array{Float64,2}}, ::String) at /Users/tamasnagy/.julia/v0.5/QuartzImageIO/src/QuartzImageIO.jl:286
 in #save#16(::Array{Any,1}, ::Function, ::FileIO.Stream{FileIO.DataFormat{:PNG},IOContext{Base64EncodePipe}}, ::Images.Image{Float64,2,Array{Float64,2}}) at /Users/tamasnagy/.julia/v0.5/QuartzImageIO/src/QuartzImageIO.jl:48
 in save(::FileIO.Stream{FileIO.DataFormat{:PNG},IOContext{Base64EncodePipe}}, ::Images.Image{Float64,2,Array{Float64,2}}) at /Users/tamasnagy/.julia/v0.5/QuartzImageIO/src/QuartzImageIO.jl:48
 in #save#18(::Array{Any,1}, ::Function, ::FileIO.Stream{FileIO.DataFormat{:PNG},IOContext{Base64EncodePipe}}, ::Images.Image{Float64,2,Array{Float64,2}}, ::Vararg{Images.Image{Float64,2,Array{Float64,2}},N}) at /Users/tamasnagy/.julia/v0.5/FileIO/src/loadsave.jl:97
 in #show#143(::Images.ClampMinMax{FixedPointNumbers.UFixed{UInt8,8},Float64}, ::Int64, ::Int64, ::Function, ::IOContext{Base64EncodePipe}, ::MIME{Symbol("image/png")}, ::Images.Image{Float64,2,Array{Float64,2}}) at /Users/tamasnagy/.julia/v0.5/Images/src/writemime.jl:30
 in verbose_show(::Base64EncodePipe, ::MIME{Symbol("image/png")}, ::Images.Image{Float64,2,Array{Float64,2}}) at ./multimedia.jl:50
 in base64encode(::Function, ::MIME{Symbol("image/png")}, ::Vararg{Any,N}) at ./base64.jl:160
 in display_dict(::Images.Image{Float64,2,Array{Float64,2}}) at /Users/tamasnagy/.julia/v0.5/IJulia/src/execute_request.jl:31
 in execute_request(::ZMQ.Socket, ::IJulia.Msg) at /Users/tamasnagy/.julia/v0.5/IJulia/src/execute_request.jl:195
 in eventloop(::ZMQ.Socket) at /Users/tamasnagy/.julia/v0.5/IJulia/src/IJulia.jl:138
 in (::IJulia.##25#31)() at ./task.jl:360
Trying next loading library! Please report this issue on the Github page for QuartzImageIO
WARNING: FileIO.NotInstalledError(:ImageMagick,"")
 in checked_import(::Symbol) at /Users/tamasnagy/.julia/v0.5/FileIO/src/loadsave.jl:12
 in #save#18(::Array{Any,1}, ::Function, ::FileIO.Stream{FileIO.DataFormat{:PNG},IOContext{Base64EncodePipe}}, ::Images.Image{Float64,2,Array{Float64,2}}, ::Vararg{Images.Image{Float64,2,Array{Float64,2}},N}) at /Users/tamasnagy/.julia/v0.5/FileIO/src/loadsave.jl:96
 in #show#143(::Images.ClampMinMax{FixedPointNumbers.UFixed{UInt8,8},Float64}, ::Int64, ::Int64, ::Function, ::IOContext{Base64EncodePipe}, ::MIME{Symbol("image/png")}, ::Images.Image{Float64,2,Array{Float64,2}}) at /Users/tamasnagy/.julia/v0.5/Images/src/writemime.jl:30
 in verbose_show(::Base64EncodePipe, ::MIME{Symbol("image/png")}, ::Images.Image{Float64,2,Array{Float64,2}}) at ./multimedia.jl:50
 in base64encode(::Function, ::MIME{Symbol("image/png")}, ::Vararg{Any,N}) at ./base64.jl:160
 in display_dict(::Images.Image{Float64,2,Array{Float64,2}}) at /Users/tamasnagy/.julia/v0.5/IJulia/src/execute_request.jl:31
 in execute_request(::ZMQ.Socket, ::IJulia.Msg) at /Users/tamasnagy/.julia/v0.5/IJulia/src/execute_request.jl:195
 in eventloop(::ZMQ.Socket) at /Users/tamasnagy/.julia/v0.5/IJulia/src/IJulia.jl:138
 in (::IJulia.##25#31)() at ./task.jl:360

InexactError()
@mronian
Copy link
Contributor

mronian commented Aug 30, 2016

Worked for me -

selection_106

@mronian
Copy link
Contributor

mronian commented Aug 30, 2016

I think you need ImageMagick. Could you try this -

Pkg.add("ImageMagick")

EDIT - Are you using OS X?

@tlnagy
Copy link
Contributor Author

tlnagy commented Aug 31, 2016

That works fine. It's this that fails:

x, y = imgradients(img)
x

@mronian
Copy link
Contributor

mronian commented Aug 31, 2016

Whoops. Did not see that. I think its because the gradients can be negative or > 1. You will have to scale the gradients back to [0-1] if you want to view the image.

@tlnagy
Copy link
Contributor Author

tlnagy commented Aug 31, 2016

Ah. That works for me. What's wrong here? (Also in IJulia)

img[1:5, 1:5]

MethodError: no method matching show(::IOContext{Base64EncodePipe}, ::MIME{Symbol("image/png")}, ::Array{ColorTypes.Gray{Float64},2})
Closest candidates are:
  show(::IO, !Matched::MIME{Symbol("text/csv")}, ::Any) at datafmt.jl:712
  show(::IO, !Matched::MIME{Symbol("text/tab-separated-values")}, ::Any) at datafmt.jl:713
  show(::IO, !Matched::MIME{Symbol("text/plain")}, ::AbstractArray{T,N}) at replutil.jl:153
  ...

 in verbose_show(::Base64EncodePipe, ::MIME{Symbol("image/png")}, ::Array{ColorTypes.Gray{Float64},2}) at ./multimedia.jl:50
 in base64encode(::Function, ::MIME{Symbol("image/png")}, ::Vararg{Any,N}) at ./base64.jl:160
 in display_dict(::Array{ColorTypes.Gray{Float64},2}) at /Users/tamasnagy/.julia/v0.5/IJulia/src/execute_request.jl:31
 in execute_request(::ZMQ.Socket, ::IJulia.Msg) at /Users/tamasnagy/.julia/v0.5/IJulia/src/execute_request.jl:195
 in eventloop(::ZMQ.Socket) at /Users/tamasnagy/.julia/v0.5/IJulia/src/IJulia.jl:138
 in (::IJulia.##25#31)() at ./task.jl:360

@timholy
Copy link
Member

timholy commented Aug 31, 2016

As you can tell, I don't use IJulia. This should be fixed in #549.

With regards to the imgradients problem, that doesn't happen on Linux which uses ImageMagick. Looking over the source of QuartzImageIO, it seems to lack all the logic present in ImageMagick for converting the image into a representation that ImageMagick can handle. This tackles stuff like floating point/16bit data, data not represented as a chunk of contiguous memory, other colorspaces, and out-of-range values.

I'm a bit reluctant to tackle that myself since I don't have a mac to test it on. Moreover, I suspect this part of Images is amenable to simplification now that functions-as-arguments are fast in julia (0.5 and above). Maybe a new goal for #542.

timholy added a commit that referenced this issue Aug 31, 2016
Display AbstractMatrix{Colorant} in IJulia (fixes #548)
@tlnagy
Copy link
Contributor Author

tlnagy commented Aug 31, 2016

Thanks! I could help with the testing on mac, either with the current Images.jl or with the new shiny version.

@tlnagy
Copy link
Contributor Author

tlnagy commented Aug 31, 2016

So I just checked out and built master and it doesn't crash 🎉 but the spacing is funky:

screen shot 2016-08-31 at 11 54 59

@mronian
Copy link
Contributor

mronian commented Sep 1, 2016

@timholy I guess it will be better if we have a dedicated ImageView package 😄 with the code you had on your local machine.

@timholy
Copy link
Member

timholy commented Sep 1, 2016

Well, there's merit in having IJulia work too. And once the Images rewrite is done, ImageView is on the table. (I've offered to release the makeshift ImagePlayer on a no-guarantees-I-won't-support-this basis, but no takers yet...)

I've seen this funky spacing before; perhaps JuliaLang/IJulia.jl#229 has resurfaced?

@SimonDanisch
Copy link
Member

I'd be interested to make a GLVisualize based ImageView much in the style of this GLVisualize demo: https://vimeo.com/180307247
Is there a spec sheet of the things the image viewer should support?

@tlnagy
Copy link
Contributor Author

tlnagy commented Sep 1, 2016

@timholy should I open an issue over on IJulia? I don't seem to be able to re-open this issue.

@timholy timholy reopened this Sep 2, 2016
@timholy
Copy link
Member

timholy commented Sep 2, 2016

@SimonDanisch, that would be awesome. I want there to be something that works without relying on GL, but I would love to use GL whenever it's available.

I am probably going to change the API of ImageView, so I'll answer that question once I get serious about tackling it. Would be fun to work on together!

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

4 participants