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

Overlay doesn't work with PyPlot #460

Closed
bjarthur opened this issue Mar 25, 2016 · 3 comments
Closed

Overlay doesn't work with PyPlot #460

bjarthur opened this issue Mar 25, 2016 · 3 comments

Comments

@bjarthur
Copy link
Collaborator

i can ImageView.view an Overlay just fine, but i cannot PyPlot.imshow. is it because raw and separate don't work?

julia> using Images, ColorTypes, TestImages

julia> mandril = testimage("mandril_gray")
Gray Images.Image with:
  data: 512x512 Array{ColorTypes.Gray{FixedPointNumbers.UFixed{UInt8,8}},2}
  properties:
    imagedescription: <suppressed>
    spatialorder:  x y
    pixelspacing:  1 1

julia> ovr = Overlay((mandril,mandril),(RGB(1,0,0),RGB(0,1,0)));

julia> using PyPlot

julia> imshow(ovr)
2016-03-25 08:53:03.909 julia[5481:41933] setCanCycle: is deprecated.  Please use setCollectionBehavior instead
2016-03-25 08:53:03.918 julia[5481:41933] setCanCycle: is deprecated.  Please use setCollectionBehavior instead
ERROR: PyError (:PyObject_Call) <type 'exceptions.TypeError'>
TypeError(u'Image data can not convert to float',)
  File "/Users/arthurb/.julia/v0.4/Conda/deps/usr/lib/python2.7/site-packages/matplotlib/pyplot.py", line 3022, in imshow
    **kwargs)
  File "/Users/arthurb/.julia/v0.4/Conda/deps/usr/lib/python2.7/site-packages/matplotlib/__init__.py", line 1811, in inner
    return func(ax, *args, **kwargs)
  File "/Users/arthurb/.julia/v0.4/Conda/deps/usr/lib/python2.7/site-packages/matplotlib/axes/_axes.py", line 4943, in imshow
    im.set_data(X)
  File "/Users/arthurb/.julia/v0.4/Conda/deps/usr/lib/python2.7/site-packages/matplotlib/image.py", line 449, in set_data
    raise TypeError("Image data can not convert to float")

 [inlined code] from /Users/arthurb/.julia/v0.4/PyCall/src/exception.jl:81
 in pycall at /Users/arthurb/.julia/v0.4/PyCall/src/PyCall.jl:344
 in imshow at /Users/arthurb/.julia/v0.4/PyPlot/src/PyPlot.jl:460

julia> raw(ovr)
ERROR: auto_unbox: unable to determine argument type
 in raw at /Users/arthurb/.julia/v0.4/Images/src/core.jl:318

julia> separate(ovr)
ERROR: MethodError: `reinterpret` has no method matching reinterpret(::Type{FixedPointNumbers.UFixed{UInt8,8}}, ::Images.Overlay{FixedPointNumbers.UFixed{UInt8,8},2,2,Tuple{Images.Image{ColorTypes.Gray{FixedPointNumbers.UFixed{UInt8,8}},2,Array{ColorTypes.Gray{FixedPointNumbers.UFixed{UInt8,8}},2}},Images.Image{ColorTypes.Gray{FixedPointNumbers.UFixed{UInt8,8}},2,Array{ColorTypes.Gray{FixedPointNumbers.UFixed{UInt8,8}},2}}},Tuple{Images.ScaleMinMax{Float32,FixedPointNumbers.UFixed{UInt8,8},Float32},Images.ScaleMinMax{Float32,FixedPointNumbers.UFixed{UInt8,8},Float32}}}, ::Tuple{Int64,Int64,Int64})
Closest candidates are:
  reinterpret{T,S,N}(::Type{T}, ::Array{S,N}, ::NTuple{N,Int64})
  reinterpret{T,Tv,Ti,N}(::Type{T}, ::SparseMatrixCSC{Tv,Ti}, ::NTuple{N,Int64})
  reinterpret{T,S}(::Type{T}, ::S)
  ...
 in separate at /Users/arthurb/.julia/v0.4/Images/src/core.jl:408
@mronian
Copy link
Contributor

mronian commented Mar 27, 2016

I get the reinterpret has no method matching error sometimes while using the save method on the images returned from the histeq method in #458.

@timholy
Copy link
Member

timholy commented Mar 28, 2016

Ah, overlay images shouldn't even be using reinterpret---overlays are "lazy overlays," meaning they don't require you to combine the arrays. (Intended to make it possible to construct overlays with TB-sized images, and have them display on-the-fly.) The downside, of course, is that the more fancy types one has, the greater the risk that some operations haven't been defined.

Probably the easiest approach would be to create a specialized method of separate for overlay types, implemented as separate(copy(img)) or something.

As for the raw error, I haven't looked at that. Which line does 318 correspond to?

@bjarthur
Copy link
Collaborator Author

bjarthur commented Apr 7, 2016

thanks tim! and not just for your work on the Images and Colors family of packages, but your contributions to julia Base in general. i am continually perplexed as to how you manage to run a lab as well!

as a note, Overlays now do work with PyPlot, but in the specific example above, one must explicitly convert to Float, and make sure that the color dimension is last:

imshow(convert(Array{Float32,3}, separate(ovr)))

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