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

Quick guide to images on jupyter #379

Closed
alanedelman opened this issue Oct 3, 2015 · 6 comments
Closed

Quick guide to images on jupyter #379

alanedelman opened this issue Oct 3, 2015 · 6 comments

Comments

@alanedelman
Copy link

Students want a basic understanding of how to display images
e.g.

img = imread(foo)

The following display a picture

img
img[1:10,:]
img[:,1:10]

but not

img[1:10,1:10]

This drives people crazy

What should I tell them? or where can I point them?

@timholy
Copy link
Member

timholy commented Oct 3, 2015

I don't use Jupyter so I've not personally put much effort into making it work well, and it looks like no one else has either. But here's what's going on: img[1:10,1:10] returns an Array, and Jupyter is not set up to display all Arrays as an image (otherwise zeros(3,3) would produce a black square rather than the printout of a matrix 😄). I didn't remember that img[:,1:10] gives back an Image; that's probably unintentional, it should give an array too.

getindexim(img, 1:10, 1:10) preserves the Image metadata, and that will display a subregion as an Image.

I'm not saying this is ideal; see #173 for discussion. We can probably reconsider this by adding yet-another-AbstractArray layer, but I do have a few reservations about that until we get triangular dispatch---the dispatch already gets hairy sometimes just with Image{RGB{Float32}, 2, Array{RGB{Float32}, 2}}...

@timholy
Copy link
Member

timholy commented Oct 3, 2015

I didn't remember that img[:,1:10] gives back an Image; that's probably unintentional, it should give an array too.

This actually turns out to be a new consequence of JuliaLang/julia#10525 and my definition of similar.

@timholy
Copy link
Member

timholy commented Oct 3, 2015

Ah, there's one other thing we could do that would avoid an extra layer. The following should turn on display for any AbstractArray{C<:Colorant}:

Base.mimewritable{C<:Colorant}(::MIME"image/png", img::AbstractArray{C}) = sdims(img) == 2 && timedim(img) == 0

Base.writemime{C<:Colorant}(stream::IO, mime::MIME"image/png", img::AbstractArray{C}; kwargs...) =
    writemime(stream, mime, Image(img, spatialorder=["x","y"]); kwargs...)

If you want, I can add this and tag a release just for that. Or you can put this in a file that everyone loads.

@timholy
Copy link
Member

timholy commented Oct 3, 2015

(I should say I can't test because my own IJulia produces no output whatsoever, not even of numbers.)

@SimonDanisch
Copy link
Member

@timholy that's actually how I do it in GLVisualize and works well for me :)
I do it the other way around though:
visualize(image::AbstractImage) = visualize(data(image))
I probably shouldn't since the visualization might need some information stored in the properties.
Good that we talked about this :D

timholy added a commit that referenced this issue Oct 4, 2015
I'm a little concerned about spatialorder in cases where users _don't_ start from an Image, but this is probably our best default until we have a more general solution.
@timholy
Copy link
Member

timholy commented Oct 4, 2015

OK, I fixed my IJulia (there must have been a conflict between the new Conda infrastructure and an old pip-installed version) and verified that the above work. I pushed and tagged a new release. Did not merge into master, since that's focused on migrating to FileIO, but a Pkg.update("Images") should fix this for your students and hopefully drive them less crazy.

@SimonDanisch, we'll want to put the same fix into ImageMagick.jl.

@timholy timholy closed this as completed Oct 4, 2015
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