Skip to content

Commit

Permalink
Merge pull request #156 from JuliaImages/teh/v0.7
Browse files Browse the repository at this point in the history
Update to 0.7 and 1.0
  • Loading branch information
timholy authored Sep 4, 2018
2 parents c18c64c + a995d29 commit fcf1c68
Show file tree
Hide file tree
Showing 19 changed files with 197 additions and 182 deletions.
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ addons:
- xauth
- libgtk-3-0
julia:
- 0.6
- 0.7
- 1.0
notifications:
email: false
script:
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
- julia -e 'versioninfo(); Pkg.clone(pwd()); Pkg.build("ImageView")'
- xvfb-run julia -e 'Pkg.test("ImageView")'
- julia -e 'using Pkg; Pkg.clone(pwd()); Pkg.build("ImageView")'
- xvfb-run julia -e 'using Pkg; Pkg.test("ImageView")'
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ grid, frames, canvases = canvasgrid((1,2)) # 1 row, 2 columns
imshow(canvases[1,1], testimage("lighthouse"))
imshow(canvases[1,2], testimage("mandrill"))
win = Window(grid)
showall(win)
Gtk.showall(win)
```

![canvasgrid snapshot](readme_images/canvasgrid.jpg)
Expand Down Expand Up @@ -180,7 +180,7 @@ zr, slicedata = roi(mri, (1,2))
gd = imshow_gui((200, 200), slicedata, (1,2))
imshow(gd["frame"][1,1], gd["canvas"][1,1], mri, nothing, zr, slicedata)
imshow(gd["frame"][1,2], gd["canvas"][1,2], mriseg, nothing, zr, slicedata)
showall(gd["window"])
Gtk.showall(gd["window"])
```

You should see something like this:
Expand Down
5 changes: 2 additions & 3 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
julia 0.6 0.7
julia 0.7
Images 0.6.0
GtkReactive 0.4.2
GtkReactive 0.5.1
FixedPointNumbers 0.3
Colors
ColorVectorSpace
Expand All @@ -12,4 +12,3 @@ MappedArrays
AxisArrays
StatsBase
RoundingIntegers
Compat 0.18
76 changes: 35 additions & 41 deletions src/ImageView.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
__precompile__()

module ImageView

using FixedPointNumbers, Colors, ColorVectorSpace, Images, StatsBase
using MappedArrays, AxisArrays, RoundingIntegers
using MappedArrays, RoundingIntegers
using Gtk.ShortNames, GtkReactive, Graphics
using Compat
using Gtk.GConstants.GtkAlign: GTK_ALIGN_START, GTK_ALIGN_END, GTK_ALIGN_FILL
import AxisArrays
using AxisArrays: Axis, axisnames, axisvalues

import Images: scaleminmax

Expand Down Expand Up @@ -48,7 +47,7 @@ function closeall()
nothing
end

const window_wrefs = WeakKeyDict{Gtk.GtkWindowLeaf,Void}()
const window_wrefs = WeakKeyDict{Gtk.GtkWindowLeaf,Nothing}()

"""
imshow()
Expand Down Expand Up @@ -111,7 +110,7 @@ function imshow!(canvas::GtkReactive.Canvas,
annotations::Signal{Dict{UInt,Any}})
draw(canvas, imgsig, annotations) do cnvs, image, anns
copy!(cnvs, image)
set_coordinates(cnvs, indices(image))
set_coordinates(cnvs, axes(image))
draw_annotations(cnvs, anns)
end
end
Expand All @@ -122,7 +121,7 @@ function imshow!(canvas::GtkReactive.Canvas,
annotations::Signal{Dict{UInt,Any}})
draw(canvas, annotations) do cnvs, anns
copy!(cnvs, img)
set_coordinates(cnvs, indices(img))
set_coordinates(cnvs, axes(img))
draw_annotations(cnvs, anns)
end
nothing
Expand Down Expand Up @@ -151,7 +150,7 @@ Finally, you may specify [`GtkReactive.ZoomRegion`](@ref) and
`annotations` that you wish to apply.
"""
function imshow(img::AbstractArray;
axes = default_axes(img), name="ImageView", scalei=identity, aspect=:auto,
axes=default_axes(img), name="ImageView", scalei=identity, aspect=:auto,
kwargs...)
imgmapped = kwhandler(_mappedarray(scalei, img), axes; kwargs...)
zr, sd = roi(imgmapped, axes)
Expand Down Expand Up @@ -187,12 +186,12 @@ function imshow(img::AbstractArray, clim,
roidict = imshow(guidict["frame"], guidict["canvas"], img,
wrap_signal(clim), zr, sd, anns)

showall(guidict["window"])
Gtk.showall(guidict["window"])
Dict("gui"=>guidict, "clim"=>clim, "roi"=>roidict, "annotations"=>anns)
end

function imshow(frame::Gtk.GtkFrame, canvas::GtkReactive.Canvas,
img::AbstractArray, clim::Union{Void,Signal{<:CLim}},
img::AbstractArray, clim::Union{Nothing,Signal{<:CLim}},
zr::Signal{ZoomRegion{T}}, sd::SliceData,
anns::Signal{Dict{UInt,Any}}=Signal(Dict{UInt,Any}())) where T
imgsig = map(zr, sd.signals...; name="imgsig") do r, s...
Expand Down Expand Up @@ -233,7 +232,7 @@ function imshow(img,

roidict = imshow(guidict["frame"], guidict["canvas"], img, zr, sd, anns)

showall(guidict["window"])
Gtk.showall(guidict["window"])
Dict("gui"=>guidict, "roi"=>roidict)
end

Expand Down Expand Up @@ -281,7 +280,7 @@ function imshow_gui(canvassize::Tuple{Int,Int},
end
push!(vbox, g)
status = Label("")
setproperty!(status, :halign, Gtk.GConstants.GtkAlign.START)
set_gtk_property!(status, :halign, Gtk.GConstants.GtkAlign.START)
push!(vbox, status)

guidict = Dict("window"=>win, "vbox"=>vbox, "frame"=>frames, "status"=>status,
Expand Down Expand Up @@ -314,8 +313,8 @@ GtkAspectRatioFrames that contain each canvas, and `canvases` is an
"""
function canvasgrid(gridsize::Tuple{Int,Int}, aspect=:auto)
g = Grid()
frames = Matrix{Any}(gridsize)
canvases = Matrix{Any}(gridsize)
frames = Matrix{Any}(undef, gridsize)
canvases = Matrix{Any}(undef, gridsize)
for j = 1:gridsize[2], i = 1:gridsize[1]
f, c = frame_canvas(aspect)
g[j,i] = f
Expand All @@ -327,8 +326,8 @@ end

function frame_canvas(aspect)
f = aspect==:none ? Frame() : AspectFrame("", 0.5, 0.5, 1)
setproperty!(f, :expand, true)
setproperty!(f, :shadow_type, Gtk.GConstants.GtkShadowType.NONE)
set_gtk_property!(f, :expand, true)
set_gtk_property!(f, :shadow_type, Gtk.GConstants.GtkShadowType.NONE)
c = canvas(UserUnit)
push!(f, widget(c))
f, c
Expand Down Expand Up @@ -383,7 +382,7 @@ Display `img`, but showing the pixel's `label` rather than the color
value in the status bar.
"""
function imshowlabeled(img::AbstractArray, label::AbstractArray; proplist...)
indices(img) == indices(label) || throw(DimensionMismatch("indices $(indices(label)) of label array disagree with indices $(indices(img)) of the image"))
axes(img) == axes(label) || throw(DimensionMismatch("axes $(axes(label)) of label array disagree with axes $(axes(img)) of the image"))
guidict = imshow(img; proplist...)
gui = guidict["gui"]
sd = guidict["roi"]["slicedata"]
Expand All @@ -397,13 +396,13 @@ end
function hoverinfo(lbl, btn, img, sd::SliceData{transpose}) where transpose
io = IOBuffer()
y, x = round(Int, btn.position.y.val), round(Int, btn.position.x.val)
indices = sliceinds(img, transpose ? (x, y) : (y, x), makeslices(sd)...)
if checkbounds(Bool, img, indices...)
axes = sliceinds(img, transpose ? (x, y) : (y, x), makeslices(sd)...)
if checkbounds(Bool, img, axes...)
print(io, '[', y, ',', x, "] ")
showcompact(io, img[indices...])
setproperty!(lbl, :label, String(take!(io)))
show(IOContext(io, :compact=>true), img[axes...])
set_gtk_property!(lbl, :label, String(take!(io)))
else
setproperty!(lbl, :label, "")
set_gtk_property!(lbl, :label, "")
end
end

Expand Down Expand Up @@ -438,7 +437,7 @@ default_axes(img::AxisArray) = axisnames(img)[[1,2]]
#default_view(img) = view(img, :, :, ntuple(d->1, ndims(img)-2)...)
#default_view(img::Signal) = default_view(value(img))

# default_slices(img) = ntuple(d->PlayerInfo(Signal(1), indices(img, d+2)), ndims(img)-2)
# default_slices(img) = ntuple(d->PlayerInfo(Signal(1), axes(img, d+2)), ndims(img)-2)

function histsignals(enabled::Signal, defaultimg, img::Signal, clim::Signal{CLim{T}}) where {T<:GrayLike}
return [map(filterwhen(enabled, defaultimg, img); name="histsig") do image
Expand All @@ -448,7 +447,7 @@ function histsignals(enabled::Signal, defaultimg, img::Signal, clim::Signal{CLim
if smax == smin
smax = smin+1
end
rng = linspace(smin, smax, 300)
rng = range(smin, stop=smax, length=300)
fit(Histogram, mappedarray(nanz, vec(channelview(image))), rng; closed=:right)
end]
end
Expand Down Expand Up @@ -523,9 +522,9 @@ end

prep_contrast(canvas, img::Signal, f) =
map(image->mappedarray(f, image), img; name="f-mapped image")
prep_contrast(canvas, img::Signal{A}, ::Void) where {A<:AbstractArray} =
prep_contrast(canvas, img::Signal{A}, ::Nothing) where {A<:AbstractArray} =
prep_contrast(canvas, img, clamp01nan)
prep_contrast(canvas, img::Signal, ::Void) = img
prep_contrast(canvas, img::Signal, ::Nothing) = img

nanz(x) = ifelse(isnan(x), zero(x), x)
nanz(x::FixedPoint) = x
Expand All @@ -535,7 +534,7 @@ function create_contrast_popup(canvas, enabled, hists, clim)
popupmenu = Menu()
contrast = MenuItem("Contrast...")
push!(popupmenu, contrast)
showall(popupmenu)
Gtk.showall(popupmenu)
push!(canvas.preserved, map(canvas.mouse.buttonpress; name="open contrast GUI") do btn
if btn.button == 3 && btn.clicktype == BUTTON_PRESS
popup(popupmenu, btn.gtkevent)
Expand All @@ -557,9 +556,9 @@ map_image_roi(img::Signal, zr::Signal{ZoomRegion{T}}, slices...) where {T} = img

function set_aspect!(frame::AspectFrame, image)
ps = map(abs, pixelspacing(image))
sz = map(length, indices(image))
sz = map(length, axes(image))
r = sz[2]*ps[2]/(sz[1]*ps[1])
setproperty!(frame, :ratio, r)
set_gtk_property!(frame, :ratio, r)
nothing
end
set_aspect!(frame, image) = nothing
Expand Down Expand Up @@ -600,19 +599,15 @@ function canvas_size(screensize_xy, requestedsize_xy; minsize=100)
(round(Int, f*requestedsize_xy[1]), round(Int, f*requestedsize_xy[2]))
end

function kwhandler(img, axes; flipx=false, flipy=false, kwargs...)
function kwhandler(img, axs; flipx=false, flipy=false, kwargs...)
if flipx || flipy
inds = Range[indices(img)...]
setrange!(inds, _axisdim(img, axes[1]), flipy)
setrange!(inds, _axisdim(img, axes[2]), flipx)
inds = AbstractRange[axes(img)...]
setrange!(inds, _axisdim(img, axs[1]), flipy)
setrange!(inds, _axisdim(img, axs[2]), flipx)
img = view(img, inds...)
end
for (k, v) in kwargs
if k == :xy
error("The `xy` keyword has been renamed `axes`, and it takes dimensions or Symbols (if using an AxisArray)")
end
end
pixelspacing_dep(img, kwargs)
# isempty(kwargs) || error("cannot handle ", kwargs)
img
end
function setrange!(inds, ax::Integer, flip)
ind = inds[ax]
Expand All @@ -634,11 +629,10 @@ _mappedarray(f, img::ImageMeta) = shareproperties(img, _mappedarray(f, data(img)

wrap_signal(x) = Signal(x)
wrap_signal(x::Signal) = x
wrap_signal(::Void) = nothing
wrap_signal(::Nothing) = nothing

include("link.jl")
include("contrast_gui.jl")
include("annotations.jl")
include("deprecated.jl")

end # module
10 changes: 5 additions & 5 deletions src/annotations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function canvasbb(c)
BoundingBox(1, sz[1], 1, sz[2])
end
function zoombb(zr)
inds = indices(value(zr))
inds = axes(value(zr))
BoundingBox(first(inds[2]), last(inds[2]), first(inds[1]), last(inds[1]))
end

Expand Down Expand Up @@ -172,7 +172,7 @@ mutable struct AnnotationLines{R<:Union{Real, Tuple{Real, Real}}, T}
coordinate_order::Vector{Int}

function AnnotationLines{R,T}(lines::T, z, t, linecolor, linewidth, coord_order_str) where {R,T}
ord = sortperm(Vector{UInt8}(coord_order_str))
ord = sortperm(codeunits(coord_order_str))
@assert coord_order_str[ord] == "xxyy"
new{R,T}(lines, z, t, linecolor, linewidth, ord)
end
Expand Down Expand Up @@ -200,7 +200,7 @@ AnnotationLine(pt1::Tuple{Real,Real}, pt2::Tuple{Real,Real}; args...) =
AnnotationLine((pt1, pt2); args...)

function AnnotationLine(c1::Real, c2::Real, c3::Real, c4::Real; coord_order="xyxy", args...)
ord = sortperm(Vector{UInt8}(coord_order))
ord = sortperm(codeunits(coord_order))
@assert coord_order[ord] == "xxyy"
(x1,x2,y1,y2) = [c1,c2,c3,c4][ord]
AnnotationLine((Float64(x1), Float64(y1)),
Expand All @@ -222,7 +222,7 @@ end

function AnnotationBox(c1::Real, c2::Real, c3::Real, c4::Real; z = NaN, t = NaN,
color=RGB(1,1,1), linewidth=1.0, coord_order="xyxy")
ord = sortperm(Vector{UInt8}(coord_order))
ord = sortperm(codeunits(coord_order))
@assert coord_order[ord] == "xxyy"
(x1, x2, y1, y2) = [c1, c2, c3, c4][ord]
(x1, x2) = minmax(x1, x2)
Expand All @@ -246,7 +246,7 @@ variants. Depends on the [`pixelspacing`](@ref) of `img`.
"""
function normalized_lengths(imsl::AbstractMatrix, width, height)
ps = pixelspacing(imsl)
inds = indices(imsl)
inds = axes(imsl)
w = width/(ps[2]*length(inds[2]))
h = height/(ps[1]*length(inds[1]))
w, h
Expand Down
10 changes: 5 additions & 5 deletions src/contrast_gui.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function contrast_gui(enabled::Signal{Bool}, hist::Signal, clim::Signal; wname="
bigmin = min(cmin,cmax,rmin,rmax)
thismax = min(typemax(T), max(cmin, cmax, rmax))
thismin = max(typemin(T), min(cmin, cmax, rmin))
rng = linspace(thismin, thismax, 255)
rng = range(thismin, stop=thismax, length=255)
cminT, cmaxT = T(min(cmin, cmax)), T(max(cmin, cmax))
if cminT == cmaxT
cminT = min(cminT, cminT-Δ)
Expand All @@ -84,7 +84,7 @@ function contrast_gui(enabled::Signal{Bool}, hist::Signal, clim::Signal; wname="
end
# TODO: we might want to throttle this?
redraw = draw(cgui["canvas"], hist) do cnvs, hst
if getproperty(cgui["window"], :visible, Bool) # protects against window destruction
if get_gtk_property(cgui["window"], :visible, Bool) # protects against window destruction
rng, cl = hst.edges[1], value(clim)
mn, mx = minimum(rng), maximum(rng)
push!(cgui["slider_min"], rng, clamp(cl.min, mn, mx))
Expand All @@ -101,13 +101,13 @@ function contrast_gui_layout(smin::Signal, smax::Signal, rng; wname="Contrast")
slmax = slider(rng; signal=smax)
slmin = slider(rng; signal=smin)
for sl in (slmax, slmin)
setproperty!(sl, :draw_value, false)
set_gtk_property!(sl, :draw_value, false)
end
g[1,1] = widget(slmax)
g[1,3] = widget(slmin)
cnvs = canvas(UserUnit)
g[1,2] = widget(cnvs)
setproperty!(cnvs, :expand, true)
set_gtk_property!(cnvs, :expand, true)
emax_w = Entry(; width_chars=5, hexpand=false, halign=GTK_ALIGN_END, valign=GTK_ALIGN_START)
emin_w = Entry(; width_chars=5, hexpand=false, halign=GTK_ALIGN_END, valign=GTK_ALIGN_END)
g[2,1] = emax_w
Expand All @@ -118,7 +118,7 @@ function contrast_gui_layout(smin::Signal, smax::Signal, rng; wname="Contrast")
emax = textbox(eltype(smax); widget=emax_w, signal=smax) # , range=rng)
emin = textbox(eltype(smin); widget=emin_w, signal=smin) #, range=rng)

showall(win)
Gtk.showall(win)
Dict("window"=>win, "canvas"=>cnvs, "slider_min"=>slmin, "slider_max"=>slmax, "textbox_min"=>emin, "textbox_max"=>emax)
end

Expand Down
26 changes: 0 additions & 26 deletions src/deprecated.jl

This file was deleted.

Loading

0 comments on commit fcf1c68

Please sign in to comment.