Skip to content

Commit

Permalink
Merge pull request #1362 from apalugniok/cropped-image
Browse files Browse the repository at this point in the history
Fix image axis limits and add image movement and resizing.
  • Loading branch information
apalugniok authored Jan 19, 2018
2 parents fcb5b35 + a79a40b commit 1ed7899
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/backends/glvisualize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1215,7 +1215,7 @@ end

function gl_image(img, kw_args)
rect = kw_args[:primitive]
kw_args[:primitive] = GeometryTypes.SimpleRectangle{Float32}(rect.x, rect.y, rect.h, rect.w) # seems to be flipped
kw_args[:primitive] = GeometryTypes.SimpleRectangle{Float32}(rect.x, rect.y, rect.w, rect.h)
visualize(img, Style(:default), kw_args)
end

Expand Down
3 changes: 2 additions & 1 deletion src/backends/gr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1199,6 +1199,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
elseif st == :image
z = transpose_z(series, series[:z].surf, true)'
w, h = size(z)
xmin, xmax = ignorenan_extrema(series[:x]); ymin, ymax = ignorenan_extrema(series[:y])
if eltype(z) <: Colors.AbstractGray
grey = round.(UInt8, float(z) * 255)
rgba = map(c -> UInt32( 0xff000000 + Int(c)<<16 + Int(c)<<8 + Int(c) ), grey)
Expand All @@ -1208,7 +1209,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
round(Int, green(c) * 255) << 8 +
round(Int, red(c) * 255) ), z)
end
GR.drawimage(0, w, h, 0, w, h, rgba)
GR.drawimage(xmin, xmax, ymax, ymin, w, h, rgba)
end

# this is all we need to add the series_annotations text
Expand Down
4 changes: 3 additions & 1 deletion src/backends/pyplot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)

if st == :image
# @show typeof(z)
xmin, xmax = ignorenan_extrema(series[:x]); ymin, ymax = ignorenan_extrema(series[:y])
img = Array(transpose_z(series, z.surf))
z = if eltype(img) <: Colors.AbstractGray
float(img)
Expand All @@ -743,7 +744,8 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
zorder = series[:series_plotindex],
cmap = py_colormap([:black, :white]),
vmin = 0.0,
vmax = 1.0
vmax = 1.0,
extent = (xmin, xmax, ymax, ymin)
)
push!(handles, handle)

Expand Down
7 changes: 3 additions & 4 deletions src/pipeline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,9 @@ end
function _expand_subplot_extrema(sp::Subplot, d::KW, st::Symbol)
# adjust extrema and discrete info
if st == :image
w, h = size(d[:z])
expand_extrema!(sp[:xaxis], (0,w))
expand_extrema!(sp[:yaxis], (0,h))
sp[:yaxis].d[:flip] = true
xmin, xmax = ignorenan_extrema(d[:x]); ymin, ymax = ignorenan_extrema(d[:y])
expand_extrema!(sp[:xaxis], (xmin, xmax))
expand_extrema!(sp[:yaxis], (ymin, ymax))
elseif !(st in (:pie, :histogram, :bins2d, :histogram2d))
expand_extrema!(sp, d)
end
Expand Down
36 changes: 36 additions & 0 deletions src/series.jl
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,12 @@ end
n, m = size(mat)
if is_seriestype_supported(:image)
seriestype := :image
yflip --> true
SliceIt, 1:m, 1:n, Surface(mat)
else
seriestype := :heatmap
yflip --> true
cbar --> false
fillcolor --> ColorGradient([:black, :white])
SliceIt, 1:m, 1:n, Surface(convert(Matrix{Float64}, mat))
end
Expand All @@ -337,10 +339,12 @@ end

if is_seriestype_supported(:image)
seriestype := :image
yflip --> true
SliceIt, 1:m, 1:n, Surface(mat)
else
seriestype := :heatmap
yflip --> true
cbar --> false
z, plotattributes[:fillcolor] = replace_image_with_heatmap(mat)
SliceIt, 1:m, 1:n, Surface(z)
end
Expand Down Expand Up @@ -465,6 +469,38 @@ end
SliceIt, x, y, Surface(z)
end

# # images - grays

@recipe function f(x::AVec, y::AVec, mat::AMat{T}) where T<:Gray
if is_seriestype_supported(:image)
seriestype := :image
yflip --> true
SliceIt, x, y, Surface(mat)
else
seriestype := :heatmap
yflip --> true
cbar --> false
fillcolor --> ColorGradient([:black, :white])
SliceIt, x, y, Surface(convert(Matrix{Float64}, mat))
end
end

# # images - colors

@recipe function f(x::AVec, y::AVec, mat::AMat{T}) where T<:Colorant
if is_seriestype_supported(:image)
seriestype := :image
yflip --> true
SliceIt, x, y, Surface(mat)
else
seriestype := :heatmap
yflip --> true
cbar --> false
z, plotattributes[:fillcolor] = replace_image_with_heatmap(mat)
SliceIt, x, y, Surface(z)
end
end

#
#
# # --------------------------------------------------------------------
Expand Down

0 comments on commit 1ed7899

Please sign in to comment.