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

Value range determined from whole volume, not first slice #261

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
35 changes: 22 additions & 13 deletions src/ImageView.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ using Compat # for @constprop :none
export AnnotationText, AnnotationPoint, AnnotationPoints,
AnnotationLine, AnnotationLines, AnnotationBox
export CLim, annotate!, annotations, canvasgrid, imshow, imshow!, imshow_gui, imlink,
roi, scalebar, slice2d
scalebar, slice2d

const AbstractGray{T} = Color{T,1}
const GrayLike = Union{AbstractGray,Number}
Expand Down Expand Up @@ -198,8 +198,8 @@ Compat.@constprop :none function imshow(@nospecialize(img::AbstractArray);
kwargs...)
imgmapped, kwargs = kwhandler(_mappedarray(scalei, img), axes; kwargs...)
zr, sd = roi(imgmapped, axes)
v = slice2d(imgmapped, zr[], sd)
imshow(Base.inferencebarrier(imgmapped)::AbstractArray, default_clim(v), zr, sd; name=name, aspect=aspect, kwargs...)
#v = slice2d(imgmapped, zr[], sd)
imshow(Base.inferencebarrier(imgmapped)::AbstractArray, default_clim(img), zr, sd; name=name, aspect=aspect, kwargs...)
end

imshow(img::AbstractVector; kwargs...) = (@nospecialize; imshow(reshape(img, :, 1); kwargs...))
Expand Down Expand Up @@ -501,13 +501,23 @@ function hoverinfo(lbl, btn, img, sd::SliceData{transpose}) where transpose
end
end

function valuespan(img::AbstractMatrix)
minval = minimum_finite(img)
maxval = maximum_finite(img)
if minval > maxval
minval = zero(typeof(minval))
maxval = oneunit(typeof(maxval))
elseif minval == maxval
function fast_finite_extrema(a::AbstractArray)
mini = a[1]
maxi = a[1]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if a[1] isn't finite?

@simd for v in a
if isfinite(v)
if v <= mini
mini = v
elseif v > maxi
maxi = v
end
end
end
return mini, maxi
end
function valuespan(img::AbstractArray)
minval, maxval = fast_finite_extrema(img)
if minval == maxval
maxval = minval+1
end
return minval, maxval
Expand All @@ -519,12 +529,11 @@ default_clim(img::AbstractArray{C}) where {C<:AbstractRGB} = _default_clim(img,
default_clim(img::AbstractArray{C}) where {C<:AbstractMultiChannelColor} = _default_clim(img, eltype(C))
_default_clim(img, ::Type{Bool}) = nothing
_default_clim(img, ::Type{T}) where {T} = _deflt_clim(img)
function _deflt_clim(img::AbstractMatrix)
function _deflt_clim(img::AbstractArray)
minval, maxval = valuespan(img)
Observable(CLim(saferound(gray(minval)), saferound(gray(maxval))))
end

function _deflt_clim(img::AbstractMatrix{T}) where {T<:AbstractRGB}
function _deflt_clim(img::AbstractArray{T}) where {T<:AbstractRGB}
minval = RGB(0.0,0.0,0.0)
maxval = RGB(1.0,1.0,1.0)
Observable(CLim(minval, maxval))
Expand Down