From 877811979295f9b8200f5a7d0fc160fa7be71f41 Mon Sep 17 00:00:00 2001 From: Michael Krabbe Borregaard Date: Wed, 23 Jan 2019 22:35:13 +0100 Subject: [PATCH] Inplace clamp --- src/series.jl | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/series.jl b/src/series.jl index ab2dd3a0..fd9f5fdb 100644 --- a/src/series.jl +++ b/src/series.jl @@ -323,15 +323,20 @@ end # # images - grays -clamp_greys(mat::AMat{T}) where T<:Gray = Gray.(clamp!([m.val for m in mat], 0, 1)) +function clamp_greys!(mat::AMat{T}) where T<:Gray + for i in eachindex(mat) + mat[i].val < 0 && (mat[i] = Gray(0)) + mat[i].val > 1 && (mat[i] = Gray(1)) + end + mat +end @recipe function f(mat::AMat{T}) where T<:Gray n, m = size(mat) if is_seriestype_supported(:image) seriestype := :image yflip --> true - any(x-> x.val<0 || x.val >1, mat) && (mat = clamp_greys(mat)) - SliceIt, 1:m, 1:n, Surface(mat) + SliceIt, 1:m, 1:n, Surface(clamp_greys!(mat)) else seriestype := :heatmap yflip --> true