From ede42f8188d19aaf835971049df9d10ffb3dbf05 Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Sun, 18 Jun 2017 17:42:55 -0500 Subject: [PATCH 1/3] Eliminate old deprecations --- src/Images.jl | 4 - src/deprecated.jl | 79 ---- src/edge.jl | 2 +- src/exposure.jl | 2 +- src/map-deprecated.jl | 736 ------------------------------------- src/overlays-deprecated.jl | 56 --- test/old/algorithms.jl | 477 ------------------------ test/old/core.jl | 377 ------------------- test/old/corner.jl | 188 ---------- test/old/edge.jl | 405 -------------------- test/old/exposure.jl | 274 -------------- test/old/map.jl | 309 ---------------- test/old/overlays.jl | 78 ---- test/old/parallel.jl | 22 -- test/old/restrict.jl | 27 -- test/old/runtests.jl | 25 -- test/old/writemime.jl | 50 --- test/runtests.jl | 3 - 18 files changed, 2 insertions(+), 3112 deletions(-) delete mode 100644 src/map-deprecated.jl delete mode 100644 src/overlays-deprecated.jl delete mode 100644 test/old/algorithms.jl delete mode 100644 test/old/core.jl delete mode 100644 test/old/corner.jl delete mode 100644 test/old/edge.jl delete mode 100644 test/old/exposure.jl delete mode 100644 test/old/map.jl delete mode 100644 test/old/overlays.jl delete mode 100644 test/old/parallel.jl delete mode 100644 test/old/restrict.jl delete mode 100644 test/old/runtests.jl delete mode 100644 test/old/writemime.jl diff --git a/src/Images.jl b/src/Images.jl index 58a2920d..95436bab 100644 --- a/src/Images.jl +++ b/src/Images.jl @@ -22,7 +22,6 @@ using Base: depwarn using Base.Order: Ordering, ForwardOrdering, ReverseOrdering using Compat -import Compat.view # "deprecated imports" are below @@ -66,8 +65,6 @@ Indicate that `x` should be interpreted as a [percentile](https://en.wikipedia.o """ immutable Percentile{T} <: Real p::T end -include("map-deprecated.jl") -include("overlays-deprecated.jl") include("labeledarrays.jl") include("algorithms.jl") include("exposure.jl") @@ -79,7 +76,6 @@ include("corner.jl") include("distances.jl") include("bwdist.jl") using .FeatureTransform -include("deprecated.jl") include("convexhull.jl") export # types diff --git a/src/deprecated.jl b/src/deprecated.jl index 962cbf75..2779f921 100644 --- a/src/deprecated.jl +++ b/src/deprecated.jl @@ -1,82 +1,3 @@ -export - AbstractImage, - AbstractImageDirect, - AbstractImageIndexed, - Image, - LabeledArray, - Overlay, - OverlayImage, - BitShift, - ClampMin, - ClampMax, - ClampMinMax, - Clamp, - Clamp01NaN, - MapInfo, - MapNone, - ScaleAutoMinMax, - ScaleMinMax, - ScaleMinMaxNaN, - ScaleSigned, - SliceData - -const yx = ["y", "x"] -const xy = ["x", "y"] - -SliceData(args...) = error("SliceData has been removed, please use julia's regular indexing operations") -reslice!(args...) = error("reslice! has been removed, along with SliceData; please use julia's regular indexing operations") -rerange!(args...) = error("reslice! has been removed, along with SliceData; please use julia's regular indexing operations") - -# These should have been deprecated long ago -@deprecate uint32color(img) immap(mapinfo(UInt32, img), img) -@deprecate uint32color!(buf, img::AbstractArray) map!(mapinfo(UInt32, img), buf, img) -@deprecate uint32color!(buf, img::AbstractArray, mi::MapInfo) map!(mi, buf, img) -@deprecate uint32color!{T,N}(buf::Array{UInt32,N}, img::AbstractArray{T,N}) map!(mapinfo(UInt32, img), buf, img) -@deprecate uint32color!{T,N,N1}(buf::Array{UInt32,N}, img::ChannelView{T,N1}) map!(mapinfo(UInt32, img), buf, img, Val{1}) -@deprecate uint32color!{T,N}(buf::Array{UInt32,N}, img::AbstractArray{T,N}, mi::MapInfo) map!(mi, buf, img) -@deprecate uint32color!{T,N,N1}(buf::Array{UInt32,N}, img::ChannelView{T,N1}, mi::MapInfo) map!(mi, buf, img, Val{1}) - -@deprecate flipx(img) flipdim(img, 2) -@deprecate flipy(img) flipdim(img, 1) -@deprecate flipz(img) flipdim(img, 3) - -@deprecate ando3 KernelFactors.ando3 -@deprecate ando4 KernelFactors.ando3 -@deprecate ando5 KernelFactors.ando3 -@deprecate gaussian2d() Kernel.gaussian(0.5) -@deprecate gaussian2d(σ::Number) Kernel.gaussian(σ) -@deprecate gaussian2d(σ::Number, filter_size) Kernel.gaussian((σ,σ), (filter_size...,)) -@deprecate imaverage KernelFactors.boxcar -@deprecate imdog Kernel.DoG -@deprecate imlog Kernel.LoG -@deprecate imlaplacian Kernel.Laplacian - -@deprecate extremefilt!(A::AbstractArray, ::Base.Order.ForwardOrdering, region=coords_spatial(A)) extremefilt!(A, max, region) -@deprecate extremefilt!(A::AbstractArray, ::Base.Order.ReverseOrdering, region=coords_spatial(A)) extremefilt!(A, min, region) -@deprecate extremefilt!{C<:AbstractRGB}(A::AbstractArray{C}, ::Base.Order.ForwardOrdering, region=coords_spatial(A)) extremefilt!(A, (x,y)->mapc(max,x,y), region) -@deprecate extremefilt!{C<:AbstractRGB}(A::AbstractArray{C}, ::Base.Order.ReverseOrdering, region=coords_spatial(A)) extremefilt!(A, (x,y)->mapc(min,x,y), region) - -function restrict{S<:String}(img::AbstractArray, region::Union{Tuple{String,Vararg{String}}, Vector{S}}) - depwarn("restrict(img, strings) is deprecated, please use restrict(img, axes) with an AxisArray", :restrict) - so = spatialorder(img) - regioni = Int[] - for i = 1:length(region) - push!(regioni, require_dimindex(img, region[i], so)) - end - restrict(img, regioni) -end - -function magnitude_phase(img::AbstractArray, method::AbstractString, border::AbstractString="replicate") - f = ImageFiltering.kernelfunc_lookup(method) - depwarn("magnitude_phase(img, method::AbstractString, [border]) is deprecated, use magnitude_phase(img, $f, [border]) instead", :magnitude_phase) - magnitude_phase(img, f, border) -end - -Base.@deprecate_binding LabeledArray ColorizedArray -@deprecate ColorizedArray{T,N}(intensity::AbstractArray{T,N}, label::AbstractArray, colors::Vector{RGB}) ColorizedArray(intensity, IndirectArray(label, colors)) - -@deprecate imcomplement(img::AbstractArray) complement.(img) - function canny{T<:NumberLike}(img_gray::AbstractMatrix{T}, sigma::Number = 1.4, upperThreshold::Number = 0.90, lowerThreshold::Number = 0.10; percentile::Bool = true) depwarn("canny(img, sigma, $upperThreshold, $lowerThreshold; percentile=$percentile) is deprecated.\n Please use canny(img, ($upperThreshold, $lowerThreshold), sigma) or canny(img, (Percentile($(100*upperThreshold)), Percentile($(100*lowerThreshold))), sigma)",:canny) if percentile diff --git a/src/edge.jl b/src/edge.jl index 58053fce..d40e1de6 100644 --- a/src/edge.jl +++ b/src/edge.jl @@ -432,7 +432,7 @@ function padindexes{T,n}(img::AbstractArray{T,n}, dim, prepad, postpad, border:: M = size(img, dim) I = Vector{Int}(M + prepad + postpad) I = [(1 - prepad):(M + postpad);] - @compat if border == "replicate" + if border == "replicate" I = min.(max.(I, 1), M) elseif border == "circular" I = 1 .+ mod.(I .- 1, M) diff --git a/src/exposure.jl b/src/exposure.jl index 357faae5..aced1267 100644 --- a/src/exposure.jl +++ b/src/exposure.jl @@ -242,7 +242,7 @@ function _histmatch(img::AbstractArray, oedges::Range, ohist::AbstractArray{Int} ocdf = cumsum(ohist) norm_ocdf = ocdf / ocdf[end] lookup_table = zeros(Int, length(norm_cdf)) - @compat for I in eachindex(cdf) + for I in eachindex(cdf) lookup_table[I] = indmin(abs.(norm_ocdf .- norm_cdf[I])) end hist_matched_img = similar(img) diff --git a/src/map-deprecated.jl b/src/map-deprecated.jl deleted file mode 100644 index 5adb35bf..00000000 --- a/src/map-deprecated.jl +++ /dev/null @@ -1,736 +0,0 @@ -#### Elementwise manipulations (scaling/clamping/type conversion) #### - -# This file exists primarily to handle conversions for display and -# saving to disk. Both of these operations require Normed-valued -# elements, but with display we always want to convert to 8-bit -# whereas saving can handle 16-bit. -# We also can't trust that user images are clamped properly. -# Finally, this supports adjustable contrast limits. - -# Structure of MapInfo subtype definitions: -# - type definition -# - constructors for scalars -# - constructors for AbstractArrays -# - similar (syntax: similar(mapi, ToType, FromType)) -# - implementation of map() for scalars -# - implementation of map() for AbstractArrays -# map(mapi::MapInfo{T}, x) should return an object of type T (for x not an array) -# map1(mapi::MapInfo{T}, x) is designed to allow T<:Color to work on -# scalars x::Fractional - -hasparameters{T}(::Type{T}, n) = !isabstract(T) && length(T.parameters) ∈ n - -isdefined(:UnionAll) && include_string(""" -hasparameters(::UnionAll, n) = false -""") - -# Dispatch-based elementwise manipulations -""" -`MapInfo{T}` is an abstract type that encompasses objects designed to -perform intensity or color transformations on pixels. For example, -before displaying an image in a window, you might need to adjust the -contrast settings; `MapInfo` objects provide a means to describe these -transformations without calculating them immediately. This delayed -execution can be useful in many contexts. For example, if you want to -display a movie, it would be quite wasteful to have to first transform -the entire movie; instead, `MapInfo` objects allow one to specify a -transformation to be performed on-the-fly as particular frames are -displayed. - -You can create your own custom `MapInfo` objects. For example, given a -grayscale image, you could color "saturated" pixels red using - -```jl -immutable ColorSaturated{C<:AbstractRGB} <: MapInfo{C} -end - -Base.map{C}(::ColorSaturated{C}, val::Union{Number,Gray}) = ifelse(val == 1, C(1,0,0), C(val,val,val)) - -imgc = map(ColorSaturated{RGB{N0f8}}(), img) -``` - -For pre-defined types see `MapNone`, `BitShift`, `ClampMinMax`, `ScaleMinMax`, -`ScaleAutoMinMax`, and `ScaleSigned`. -""" -@compat abstract type MapInfo{T} end -eltype{T}(mapi::MapInfo{T}) = T - -## Centralize calls to map, to reduce the potential for ambiguity -map(mapi::MapInfo, x::Number) = immap(mapi, x) -map(mapi::MapInfo, x::Colorant) = immap(mapi, x) -map(mapi::MapInfo, A::AbstractArray) = immap(mapi, A) - -## MapNone -"`MapNone(T)` is a `MapInfo` object that converts `x` to have type `T`." -immutable MapNone{T} <: MapInfo{T} - function (::Type{MapNone{T}}){T}() - depwarn("MapNone is deprecated, use x->$T(x)", :MapNone) - new{T}() - end -end - -# Constructors -MapNone{T}(::Type{T}) = MapNone{T}() -MapNone{T}(val::T) = MapNone{T}() -MapNone{T}(A::AbstractArray{T}) = MapNone{T}() - -similar{T}(mapi::MapNone, ::Type{T}, ::Type) = MapNone{T}() - -# Implementation -immap{T}(mapi::MapNone{T}, val::Union{Number,Colorant}) = convert(T, val) -map1(mapi::Union{MapNone{RGB24}, MapNone{ARGB32}}, b::Bool) = ifelse(b, 0xffuf8, 0x00uf8) -map1(mapi::Union{MapNone{RGB24},MapNone{ARGB32}}, val::Fractional) = convert(N0f8, val) -map1{CT<:Colorant}(mapi::MapNone{CT}, val::Fractional) = convert(eltype(CT), val) - -immap(::MapNone{UInt32}, val::RGB24) = val.color -immap(::MapNone{UInt32}, val::ARGB32) = val.color -immap(::MapNone{RGB24}, val::UInt32) = reinterpret(RGB24, val) -immap(::MapNone{ARGB32}, val::UInt32) = reinterpret(ARGB32, val) - -# immap{T<:Colorant}(mapi::MapNone{T}, img::AbstractImageIndexed{T}) = convert(Image{T}, img) -# immap{C<:Colorant}(mapi::MapNone{C}, img::AbstractImageDirect{C}) = img # ambiguity resolution -immap{T}(mapi::MapNone{T}, img::AbstractArray{T}) = img - - -## BitShift -""" -`BitShift{T,N}` performs a "saturating rightward bit-shift" operation. -It is particularly useful in converting high bit-depth images to 8-bit -images for the purpose of display. For example, - -``` -map(BitShift(N0f8, 8), 0xa2d5uf16) === 0xa2uf8 -``` - -converts a `N0f16` to the corresponding `N0f8` by discarding the -least significant byte. However, - -``` -map(BitShift(N0f8, 7), 0xa2d5uf16) == 0xffuf8 -``` - -because `0xa2d5>>7 == 0x0145 > typemax(UInt8)`. - -When applicable, the main advantage of using `BitShift` rather than -`MapNone` or `ScaleMinMax` is speed. -""" -immutable BitShift{T,N} <: MapInfo{T} - function (::Type{BitShift{T,N}}){T,N}() - depwarn("BitShift is deprecated, use x->x>>>$N", :BitShift) - new{T,N}() - end -end -BitShift{T}(::Type{T}, n::Int) = BitShift{T,n}() # note that this is not type-stable - -similar{S,T,N}(mapi::BitShift{S,N}, ::Type{T}, ::Type) = BitShift{T,N}() - -# Implementation -immutable BS{N} end -_immap{T<:Unsigned,N}(::Type{T}, ::Type{BS{N}}, val::Unsigned) = (v = val>>>N; tm = oftype(val, typemax(T)); convert(T, ifelse(v > tm, tm, v))) -_immap{T<:Normed,N}(::Type{T}, ::Type{BS{N}}, val::Normed) = reinterpret(T, _immap(FixedPointNumbers.rawtype(T), BS{N}, reinterpret(val))) -immap{T<:Real,N}(mapi::BitShift{T,N}, val::Real) = _immap(T, BS{N}, val) -immap{T<:Real,N}(mapi::BitShift{T,N}, val::Gray) = _immap(T, BS{N}, val.val) -immap{T<:Real,N}(mapi::BitShift{Gray{T},N}, val::Gray) = Gray(_immap(T, BS{N}, val.val)) -map1{N}(mapi::Union{BitShift{RGB24,N},BitShift{ARGB32,N}}, val::Unsigned) = _immap(UInt8, BS{N}, val) -map1{N}(mapi::Union{BitShift{RGB24,N},BitShift{ARGB32,N}}, val::Normed) = _immap(N0f8, BS{N}, val) -map1{CT<:Colorant,N}(mapi::BitShift{CT,N}, val::Normed) = _immap(eltype(CT), BS{N}, val) - - -## Clamp types -# The Clamp types just enforce bounds, but do not scale or offset - -# Types and constructors -@compat abstract type AbstractClamp{T} <: MapInfo{T} end -""" -`ClampMin(T, minvalue)` is a `MapInfo` object that clamps pixel values -to be greater than or equal to `minvalue` before converting to type `T`. - -See also: `ClampMax`, `ClampMinMax`. -""" -immutable ClampMin{T,From} <: AbstractClamp{T} - min::From - - function (::Type{ClampMin{T,From}}){T,From}(min) - depwarn("ClampMin is deprecated, use x->max(x, $min)", :ClampMin) - new{T,From}(min) - end -end -ClampMin{T,From}(::Type{T}, min::From) = ClampMin{T,From}(min) -ClampMin{T}(min::T) = ClampMin{T,T}(min) -""" -`ClampMax(T, maxvalue)` is a `MapInfo` object that clamps pixel values -to be less than or equal to `maxvalue` before converting to type `T`. - -See also: `ClampMin`, `ClampMinMax`. -""" -immutable ClampMax{T,From} <: AbstractClamp{T} - max::From - - function (::Type{ClampMax{T,From}}){T,From}(max) - depwarn("ClampMax is deprecated, use x->min(x, $max)", :ClampMax) - new{T,From}(max) - end -end -ClampMax{T,From}(::Type{T}, max::From) = ClampMax{T,From}(max) -ClampMax{T}(max::T) = ClampMax{T,T}(max) -immutable ClampMinMax{T,From} <: AbstractClamp{T} - min::From - max::From - - function (::Type{ClampMinMax{T,From}}){T,From}(min, max) - depwarn("ClampMinMax is deprecated, use x->clamp(x, $min, $max)", :ClampMinMax) - new{T,From}(min, max) - end -end -""" -`ClampMinMax(T, minvalue, maxvalue)` is a `MapInfo` object that clamps -pixel values to be between `minvalue` and `maxvalue` before converting -to type `T`. - -See also: `ClampMin`, `ClampMax`, and `Clamp`. -""" -ClampMinMax{T,From}(::Type{T}, min::From, max::From) = ClampMinMax{T,From}(min,max) -ClampMinMax{T}(min::T, max::T) = ClampMinMax{T,T}(min,max) -""" -`Clamp(C)` is a `MapInfo` object that clamps color values to be within -gamut. For example, - -``` -map(Clamp(RGB{N0f8}), RGB(1.2, -0.4, 0.6)) === RGB{N0f8}(1, 0, 0.6) -``` -""" -immutable Clamp{T} <: AbstractClamp{T} - function (::Type{Clamp{T}}){T}() - depwarn("Clamp is deprecated, use a colorspace-specific function (clamp01 for gray/RGB)", :Clamp) - new{T}() - end -end -Clamp{T}(::Type{T}) = Clamp{T}() - -similar{T,F}(mapi::ClampMin, ::Type{T}, ::Type{F}) = ClampMin{T,F}(convert(F, mapi.min)) -similar{T,F}(mapi::ClampMax, ::Type{T}, ::Type{F}) = ClampMax{T,F}(convert(F, mapi.max)) -similar{T,F}(mapi::ClampMinMax, ::Type{T}, ::Type{F}) = ClampMin{T,F}(convert(F, mapi.min), convert(F, mapi.max)) -similar{T,F}(mapi::Clamp, ::Type{T}, ::Type{F}) = Clamp{T}() - -# Implementation -immap{T<:Real,F<:Real}(mapi::ClampMin{T,F}, val::F) = convert(T, max(val, mapi.min)) -immap{T<:Real,F<:Real}(mapi::ClampMax{T,F}, val::F) = convert(T, min(val, mapi.max)) -immap{T<:Real,F<:Real}(mapi::ClampMinMax{T,F}, val::F) = convert(T,min(max(val, mapi.min), mapi.max)) -immap{T<:Fractional,F<:Real}(mapi::ClampMin{Gray{T},F}, val::F) = convert(Gray{T}, max(val, mapi.min)) -immap{T<:Fractional,F<:Real}(mapi::ClampMax{Gray{T},F}, val::F) = convert(Gray{T}, min(val, mapi.max)) -immap{T<:Fractional,F<:Real}(mapi::ClampMinMax{Gray{T},F}, val::F) = convert(Gray{T},min(max(val, mapi.min), mapi.max)) -immap{T<:Fractional,F<:Fractional}(mapi::ClampMin{Gray{T},F}, val::Gray{F}) = convert(Gray{T}, max(val, mapi.min)) -immap{T<:Fractional,F<:Fractional}(mapi::ClampMax{Gray{T},F}, val::Gray{F}) = convert(Gray{T}, min(val, mapi.max)) -immap{T<:Fractional,F<:Fractional}(mapi::ClampMinMax{Gray{T},F}, val::Gray{F}) = convert(Gray{T},min(max(val, mapi.min), mapi.max)) -immap{T<:Fractional,F<:Fractional}(mapi::ClampMin{Gray{T},Gray{F}}, val::Gray{F}) = convert(Gray{T}, max(val, mapi.min)) -immap{T<:Fractional,F<:Fractional}(mapi::ClampMax{Gray{T},Gray{F}}, val::Gray{F}) = convert(Gray{T}, min(val, mapi.max)) -immap{T<:Fractional,F<:Fractional}(mapi::ClampMinMax{Gray{T},Gray{F}}, val::Gray{F}) = convert(Gray{T},min(max(val, mapi.min), mapi.max)) -map1{T<:Union{RGB24,ARGB32},F<:Fractional}(mapi::ClampMin{T,F}, val::F) = convert(N0f8, max(val, mapi.min)) -map1{T<:Union{RGB24,ARGB32},F<:Fractional}(mapi::ClampMax{T,F}, val::F) = convert(N0f8, min(val, mapi.max)) -map1{T<:Union{RGB24,ARGB32},F<:Fractional}(mapi::ClampMinMax{T,F}, val::F) = convert(N0f8,min(max(val, mapi.min), mapi.max)) -map1{CT<:Colorant,F<:Fractional}(mapi::ClampMin{CT,F}, val::F) = convert(eltype(CT), max(val, mapi.min)) -map1{CT<:Colorant,F<:Fractional}(mapi::ClampMax{CT,F}, val::F) = convert(eltype(CT), min(val, mapi.max)) -map1{CT<:Colorant,F<:Fractional}(mapi::ClampMinMax{CT,F}, val::F) = convert(eltype(CT), min(max(val, mapi.min), mapi.max)) - -immap{To<:Real}(::Clamp{To}, val::Real) = clamp01(To, val) -immap{To<:Real}(::Clamp{Gray{To}}, val::AbstractGray) = Gray(clamp01(To, val.val)) -immap{To<:Real}(::Clamp{Gray{To}}, val::Real) = Gray(clamp01(To, val)) -map1{CT<:AbstractRGB}(::Clamp{CT}, val::Real) = clamp01(eltype(CT), val) -map1{P<:TransparentRGB}(::Clamp{P}, val::Real) = clamp01(eltype(P), val) - -# Also available as a stand-alone function -function ImageCore.clamp01{T}(::Type{T}, x::Real) - depwarn("clamp01(T, x) is deprecated, use x->T(clamp01(x))", :clamp01) - T(clamp01(x)) -end - -# clamp is generic for any colorspace; this version does the right thing for any RGB type -clamp(x::Union{AbstractRGB, TransparentRGB}) = clamp01(x) - -## ScaleMinMax -""" -`ScaleMinMax(T, min, max, [scalefactor])` is a `MapInfo` object that -clamps the image at the specified `min`/`max` values, subtracts the -`min` value, scales the result by multiplying by `scalefactor`, and -finally converts to type `T`. If `scalefactor` is not specified, it -defaults to scaling the interval `[min,max]` to `[0,1]`. - -Alternative constructors include `ScaleMinMax(T, img)` for which -`min`, `max`, and `scalefactor` are computed from the minimum and -maximum values found in `img`. - -See also: `ScaleMinMaxNaN`, `ScaleAutoMinMax`, `MapNone`, `BitShift`. -""" -immutable ScaleMinMax{To,From,S<:AbstractFloat} <: MapInfo{To} - min::From - max::From - s::S - - function (::Type{ScaleMinMax{To,From,S}}){To,From,S}(min, max, s) - depwarn("ScaleMinMax is deprecated, use scaleminmax([$To,] $min, $max)", :ScaleMinMax) - min >= max && error("min must be smaller than max") - new{To,From,S}(min, max, s) - end -end - -ScaleMinMax{To,From}(::Type{To}, min::From, max::From, s::AbstractFloat) = ScaleMinMax{To,From,typeof(s)}(min, max, s) -ScaleMinMax{To,From}(::Type{To}, min::From, max::From, s) = ScaleMinMax(To, min, max, convert_float(To, Float32, s)) -convert_float{To<:AbstractFloat,T}(::Type{To}, ::Type{T}, s) = convert(To, s) -convert_float{To,T}(::Type{To}, ::Type{T}, s) = convert(T, s) -ScaleMinMax{To<:Union{Fractional,Colorant},From}(::Type{To}, mn::From, mx::From) = ScaleMinMax(To, mn, mx, 1.0f0/(convert(Float32, mx)-convert(Float32, mn))) - -# ScaleMinMax constructors that take AbstractArray input -ScaleMinMax{To,From<:Real}(::Type{To}, img::AbstractArray{From}, mn::Real, mx::Real) = ScaleMinMax(To, convert(From,mn), convert(From,mx), 1.0f0/(convert(Float32, convert(From, mx))-convert(Float32,convert(From, mn)))) -ScaleMinMax{To,From<:Real}(::Type{To}, img::AbstractArray{Gray{From}}, mn::Real, mx::Real) = ScaleMinMax(To, convert(From,mn), convert(From,mx), 1.0f0/(convert(Float32, convert(From,mx))-convert(Float32, convert(From,mn)))) -ScaleMinMax{To,From<:Real,R<:Real}(::Type{To}, img::AbstractArray{From}, mn::Gray{R}, mx::Gray{R}) = ScaleMinMax(To, convert(From,mn.val), convert(From,mx.val), 1.0f0/(convert(Float32, convert(From,mx.val))-convert(Float32, convert(From,mn.val)))) -ScaleMinMax{To,From<:Real,R<:Real}(::Type{To}, img::AbstractArray{Gray{From}}, mn::Gray{R}, mx::Gray{R}) = ScaleMinMax(To, convert(From,mn.val), convert(From,mx.val), 1.0f0/(convert(Float32, convert(From,mx.val))-convert(Float32, convert(From,mn.val)))) -ScaleMinMax{To}(::Type{To}, img::AbstractArray) = ScaleMinMax(To, img, minfinite(img), maxfinite(img)) -ScaleMinMax{To<:Real,CV<:AbstractRGB}(::Type{To}, img::AbstractArray{CV}) = (imgr = channelview(img); ScaleMinMax(To, minfinite(imgr), maxfinite(imgr))) -ScaleMinMax{To<:Colorant,CV<:AbstractRGB}(::Type{To}, img::AbstractArray{CV}) = (imgr = channelview(img); ScaleMinMax(To, minfinite(imgr), maxfinite(imgr))) - -similar{T,F,To,From,S}(mapi::ScaleMinMax{To,From,S}, ::Type{T}, ::Type{F}) = ScaleMinMax{T,F,S}(convert(F,mapi.min), convert(F.mapi.max), mapi.s) - -# these functions are moved to ImageTransformations -convertsafely{T<:AbstractFloat}(::Type{T}, val) = convert(T, val) -convertsafely{T<:Integer}(::Type{T}, val::Integer) = convert(T, val) -convertsafely{T<:Integer}(::Type{T}, val::AbstractFloat) = round(T, val) -convertsafely{T}(::Type{T}, val) = convert(T, val) - -# Implementation -function immap{To<:RealLike,From<:RealLike}(mapi::ScaleMinMax{To,From}, val::Union{Real,Colorant}) - t = clamp(gray(val), gray(mapi.min), gray(mapi.max)) - f = mapi.s*t - mapi.s*mapi.min # better than mapi.s*(t-mapi.min) (overflow) - convertsafely(To, f) -end -# function immap{To<:RealLike,From<:RealLike}(mapi::ScaleMinMax{To,From}, val::Union{Real,Colorant}) -# immap(mapi, convert(From, val)) -# end -function map1{To<:Union{RGB24,ARGB32},From<:Real}(mapi::ScaleMinMax{To,From}, val::From) - t = clamp(val, mapi.min, mapi.max) - f = mapi.s*t - mapi.s*mapi.min - convert(N0f8, f) -end -function map1{To<:Colorant,From<:Real}(mapi::ScaleMinMax{To,From}, val::From) - t = clamp(val, mapi.min, mapi.max) - f = mapi.s*t - mapi.s*mapi.min - convertsafely(eltype(To), f) -end -function map1{To<:Union{RGB24,ARGB32},From<:Real}(mapi::ScaleMinMax{To,From}, val::Union{Real,Colorant}) - map1(mapi, convert(From, val)) -end -function map1{To<:Colorant,From<:Real}(mapi::ScaleMinMax{To,From}, val::Union{Real,Colorant}) - map1(mapi, convert(From, val)) -end - -## ScaleSigned -""" -`ScaleSigned(T, scalefactor)` is a `MapInfo` object designed for -visualization of images where the pixel's sign has special meaning. -It multiplies the pixel value by `scalefactor`, then clamps to the -interval `[-1,1]`. If `T` is a floating-point type, it stays in this -representation. If `T` is an `AbstractRGB`, then it is encoded as a -magenta (positive)/green (negative) image, with the intensity of the -color proportional to the clamped absolute value. -""" -immutable ScaleSigned{T, S<:AbstractFloat} <: MapInfo{T} - s::S - - function (::Type{ScaleSigned{T,S}}){T,S}(s) - depwarn("ScaleSigned is deprecated, use scalesigned", :ScaleSigned) - new{T,S}(s) - end -end -ScaleSigned{T}(::Type{T}, s::AbstractFloat) = ScaleSigned{T, typeof(s)}(s) - -ScaleSigned{T}(::Type{T}, img::AbstractArray) = ScaleSigned(T, 1.0f0/maxabsfinite(img)) -ScaleSigned(img::AbstractArray) = ScaleSigned(Float32, img) - -similar{T,To,S}(mapi::ScaleSigned{To,S}, ::Type{T}, ::Type) = ScaleSigned{T,S}(mapi.s) - -immap{T}(mapi::ScaleSigned{T}, val::Real) = convert(T, clamppm(mapi.s*val)) -function immap{C<:AbstractRGB}(mapi::ScaleSigned{C}, val::Real) - x = clamppm(mapi.s*val) - g = N0f8(abs(x)) - ifelse(x >= 0, C(g, zero(N0f8), g), C(zero(N0f8), g, zero(N0f8))) -end - -clamppm(x::Real) = ifelse(x >= 0, min(x, one(x)), max(x, -one(x))) - -## ScaleAutoMinMax -# Works only on whole arrays, not values -""" -`ScaleAutoMinMax(T)` constructs a `MapInfo` object that causes images -to be dynamically scaled to their specific min/max values, using the -same algorithm for `ScaleMinMax`. When displaying a movie, the min/max -will be recalculated for each frame, so this can result in -inconsistent contrast scaling. -""" -immutable ScaleAutoMinMax{T} <: MapInfo{T} - function (::Type{ScaleAutoMinMax{T}}){T}() - depwarn("ScaleAutoMinMax is deprecated, use scaleminmax as an argument to takemap", :ScaleAutoMinMax) - new{T}() - end -end -ScaleAutoMinMax{T}(::Type{T}) = ScaleAutoMinMax{T}() -ScaleAutoMinMax() = ScaleAutoMinMax{N0f8}() - -similar{T}(mapi::ScaleAutoMinMax, ::Type{T}, ::Type) = ScaleAutoMinMax{T}() - -## NaN-nulling mapping -""" -`ScaleMinMaxNaN(smm)` constructs a `MapInfo` object from a -`ScaleMinMax` object `smm`, with the additional property that `NaN` -values map to zero. - -See also: `ScaleMinMax`. -""" -immutable ScaleMinMaxNaN{To,From,S} <: MapInfo{To} - smm::ScaleMinMax{To,From,S} - function (::Type{ScaleMinMaxNaN{To,From,S}}){To,From,S}(smm) - depwarn("ScaleMinMaxNaN is deprecated, use scaleminmax in conjunction with clamp01nan or x->ifelse(isnan(x), zero(x), x)", :ScaleMinMaxNaN) - new{To,From,S}(smm) - end -end - -""" -`Clamp01NaN(T)` or `Clamp01NaN(img)` constructs a `MapInfo` object -that clamps grayscale or color pixels to the interval `[0,1]`, sending -`NaN` pixels to zero. -""" -immutable Clamp01NaN{T} <: MapInfo{T} - function (::Type{Clamp01NaN{T}}){T}() - depwarn("Clamp01NaN is deprecated, use clamp01nan", :Clamp01NaN) - new{T}() - end -end - -Clamp01NaN{T}(A::AbstractArray{T}) = Clamp01NaN{T}() - -# Implementation -similar{T,F,To,From,S}(mapi::ScaleMinMaxNaN{To,From,S}, ::Type{T}, ::Type{F}) = ScaleMinMaxNaN{T,F,S}(similar(mapi.smm, T, F)) -similar{T}(mapi::Clamp01NaN, ::Type{T}, ::Type) = Clamp01NaN{T}() - -immap{To}(smmn::ScaleMinMaxNaN{To}, g::Number) = isnan(g) ? zero(To) : immap(smmn.smm, g) -immap{To}(smmn::ScaleMinMaxNaN{To}, g::Gray) = isnan(g) ? zero(To) : immap(smmn.smm, g) - -function immap{T<:RGB}(::Clamp01NaN{T}, c::AbstractRGB) - r, g, b = red(c), green(c), blue(c) - if isnan(r) || isnan(g) || isnan(b) - return T(0,0,0) - end - T(clamp(r, 0, 1), clamp(g, 0, 1), clamp(b, 0, 1)) -end -function immap{T<:Union{Fractional,Gray}}(::Clamp01NaN{T}, c::Union{Fractional,AbstractGray}) - g = gray(c) - if isnan(g) - return T(0) - end - T(clamp(g, 0, 1)) -end - -# Conversions to RGB{T}, RGBA{T}, RGB24, ARGB32, -# for grayscale, AbstractRGB, and abstract ARGB inputs. -# This essentially "vectorizes" map over a single pixel's color channels using map1 -for SI in (MapInfo, AbstractClamp) - for ST in subtypes(SI) - isabstract(ST) && continue - ST == ScaleSigned && continue # ScaleSigned gives an RGB from a scalar, so don't "vectorize" it - @eval begin - # Grayscale and GrayAlpha inputs - immap(mapi::$ST{RGB24}, g::Gray) = immap(mapi, g.val) - immap(mapi::$ST{RGB24}, g::Real) = (x = map1(mapi, g); convert(RGB24, RGB{N0f8}(x,x,x))) - function immap(mapi::$ST{RGB24}, g::AbstractFloat) - if isfinite(g) - x = map1(mapi, g) - convert(RGB24, RGB{N0f8}(x,x,x)) - else - RGB24(0) - end - end - immap{G<:Gray}(mapi::$ST{RGB24}, g::TransparentColor{G}) = immap(mapi, gray(g)) - immap(mapi::$ST{ARGB32}, g::Gray) = immap(mapi, g.val) - function immap(mapi::$ST{ARGB32}, g::Real) - x = map1(mapi, g) - convert(ARGB32, ARGB{N0f8}(x,x,x,0xffuf8)) - end - function immap{G<:Gray}(mapi::$ST{ARGB32}, g::TransparentColor{G}) - x = map1(mapi, gray(g)) - convert(ARGB32, ARGB{N0f8}(x,x,x,map1(mapi, g.alpha))) - end - end - for O in (:RGB, :BGR) - @eval begin - immap{T}(mapi::$ST{$O{T}}, g::Gray) = immap(mapi, g.val) - function immap{T}(mapi::$ST{$O{T}}, g::Real) - x = map1(mapi, g) - $O{T}(x,x,x) - end - end - end - for OA in (:RGBA, :ARGB, :BGRA) - exAlphaGray = ST == MapNone ? :nothing : quote - function immap{T,G<:Gray}(mapi::$ST{$OA{T}}, g::TransparentColor{G}) - x = map1(mapi, gray(g)) - $OA{T}(x,x,x,map1(mapi, g.alpha)) - end # avoids an ambiguity warning with MapNone definitions - end - @eval begin - immap{T}(mapi::$ST{$OA{T}}, g::Gray) = immap(mapi, g.val) - function immap{T}(mapi::$ST{$OA{T}}, g::Real) - x = map1(mapi, g) - $OA{T}(x,x,x) - end - $exAlphaGray - end - end - @eval begin - # AbstractRGB and abstract ARGB inputs - immap(mapi::$ST{RGB24}, rgb::AbstractRGB) = - convert(RGB24, RGB{N0f8}(map1(mapi, red(rgb)), map1(mapi, green(rgb)), map1(mapi, blue(rgb)))) - immap{C<:AbstractRGB, TC}(mapi::$ST{RGB24}, argb::TransparentColor{C,TC}) = - convert(RGB24, RGB{N0f8}(map1(mapi, red(argb)), map1(mapi, green(argb)), - map1(mapi, blue(argb)))) - immap{C<:AbstractRGB, TC}(mapi::$ST{ARGB32}, argb::TransparentColor{C,TC}) = - convert(ARGB32, ARGB{N0f8}(map1(mapi, red(argb)), map1(mapi, green(argb)), - map1(mapi, blue(argb)), map1(mapi, alpha(argb)))) - immap(mapi::$ST{ARGB32}, rgb::AbstractRGB) = - convert(ARGB32, ARGB{N0f8}(map1(mapi, red(rgb)), map1(mapi, green(rgb)), map1(mapi, blue(rgb)))) - end - if ST == Clamp01NaN - for O in (:RGB, :BGR) - @eval begin - immap{T,C<:AbstractRGB, TC}(mapi::$ST{$O{T}}, argb::TransparentColor{C,TC}) = - $O{T}(map1(mapi, red(argb)), map1(mapi, green(argb)), map1(mapi, blue(argb))) - end - end - @eval begin - immap{T}(mapi::$ST{BGR{T}}, rgb::AbstractRGB) = - BGR{T}(map1(mapi, red(rgb)), map1(mapi, green(rgb)), map1(mapi, blue(rgb))) - end - else - for O in (:RGB, :BGR) - @eval begin - immap{T}(mapi::$ST{$O{T}}, rgb::AbstractRGB) = - $O{T}(map1(mapi, red(rgb)), map1(mapi, green(rgb)), map1(mapi, blue(rgb))) - immap{T,C<:AbstractRGB, TC}(mapi::$ST{$O{T}}, argb::TransparentColor{C,TC}) = - $O{T}(map1(mapi, red(argb)), map1(mapi, green(argb)), map1(mapi, blue(argb))) - end - end - end - for OA in (:RGBA, :ARGB, :BGRA) - @eval begin - immap{T, C<:AbstractRGB, TC}(mapi::$ST{$OA{T}}, argb::TransparentColor{C,TC}) = - $OA{T}(map1(mapi, red(argb)), map1(mapi, green(argb)), - map1(mapi, blue(argb)), map1(mapi, alpha(argb))) - immap{T}(mapi::$ST{$OA{T}}, argb::ARGB32) = immap(mapi, convert(RGBA{N0f8}, argb)) - immap{T}(mapi::$ST{$OA{T}}, rgb::AbstractRGB) = - $OA{T}(map1(mapi, red(rgb)), map1(mapi, green(rgb)), map1(mapi, blue(rgb))) - immap{T}(mapi::$ST{$OA{T}}, rgb::RGB24) = immap(mapi, convert(RGB{N0f8}, argb)) - end - end - end -end - -## Fallback definitions of map() for array types - -function immap{T}(mapi::MapInfo{T}, img::AbstractArray) - out = similar(img, T) - map!(mapi, out, img) -end - -# immap{C<:Colorant,R<:Real}(mapi::MapNone{C}, img::AbstractImageDirect{R}) = mapcd(mapi, img) # ambiguity resolution -# immap{C<:Colorant,R<:Real}(mapi::MapInfo{C}, img::AbstractImageDirect{R}) = mapcd(mapi, img) -# function mapcd{C<:Colorant,R<:Real}(mapi::MapInfo{C}, img::AbstractImageDirect{R}) -# # For this case we have to check whether color is defined along an array axis -# cd = colordim(img) -# if cd > 0 -# dims = setdiff(1:ndims(img), cd) -# out = similar(img, C, size(img)[dims]) -# map!(mapi, out, img, Val{cd}) -# else -# out = similar(img, C) -# map!(mapi, out, img) -# end -# out # note this isn't type-stable -# end - -# function immap{T<:Colorant}(mapi::MapInfo{T}, img::AbstractImageIndexed) -# out = Image(Array(T, size(img)), properties(img)) -# map!(mapi, out, img) -# end - -map!{T,T1,T2,N}(mapi::MapInfo{T1}, out::AbstractArray{T,N}, img::AbstractArray{T2,N}) = - _map_a!(mapi, out, img) -function _map_a!{T,T1,T2,N}(mapi::MapInfo{T1}, out::AbstractArray{T,N}, img::AbstractArray{T2,N}) - mi = take(mapi, img) - dimg = data(img) - dout = data(out) - size(dout) == size(dimg) || throw(DimensionMismatch()) - if eltype(dout) == UInt32 && isa(immap(mi, first(dimg)), Union{RGB24,ARGB32}) - for I in eachindex(dout, dimg) - @inbounds dout[I] = immap(mi, dimg[I]).color - end - else - for I in eachindex(dout, dimg) - @inbounds dout[I] = immap(mi, dimg[I]) - end - end - out -end - -take(mapi::MapInfo, img::AbstractArray) = mapi -take{T}(mapi::ScaleAutoMinMax{T}, img::AbstractArray) = ScaleMinMax(T, img) - -# Indexed images (colormaps) -map!{T,T1,N}(mapi::MapInfo{T}, out::AbstractArray{T,N}, img::IndirectArray{T1,N}) = - _mapindx!(mapi, out, img) -function _mapindx!{T,T1,N}(mapi::MapInfo{T}, out::AbstractArray{T,N}, img::IndirectArray{T1,N}) - dimg = data(img) - dout = data(out) - colmap = immap(mapi, dimg.values) - for I in eachindex(dout, dimg) - @inbounds dout[I] = colmap[dimg.index[I]] - end - out -end - - -#### MapInfo defaults -# Each "client" can define its own methods. "clients" include Normed, -# RGB24/ARGB32, and ImageMagick - -const bitshiftto8 = ((N6f10, 2), (N4f12, 4), (N2f14, 6), (N0f16, 8)) - -# typealias GrayType{T<:Fractional} Union{T, Gray{T}} -@compat const GrayArray{T<:Union{Fractional,Bool}} = Union{AbstractArray{T}, AbstractArray{Gray{T}}} -# note, though, that we need to override for AbstractImage in case the -# "colorspace" property is defined differently - -# mapinfo{T<:Union{Real,Colorant}}(::Type{T}, img::AbstractArray{T}) = MapNone(img) -""" -`mapi = mapinf(T, img)` returns a `MapInfo` object that is deemed -appropriate for converting pixels of `img` to be of type `T`. `T` can -either be a specific type (e.g., `RGB24`), or you can specify an -abstract type like `Clamp` and it will return one of the `Clamp` -family of `MapInfo` objects. - -You can define your own rules for `mapinfo`. For example, the -`ImageMagick` package defines methods for how pixels values should be -converted before saving images to disk. -""" -mapinfo{T<:Normed}(::Type{T}, img::AbstractArray{T}) = MapNone(img) -mapinfo{T<:AbstractFloat}(::Type{T}, img::AbstractArray{T}) = MapNone(img) - -# Grayscale methods -mapinfo(::Type{N0f8}, img::GrayArray{Bool}) = MapNone{N0f8}() -mapinfo(::Type{N0f8}, img::GrayArray{N0f8}) = MapNone{N0f8}() -mapinfo(::Type{Gray{N0f8}}, img::GrayArray{N0f8}) = MapNone{Gray{N0f8}}() -mapinfo(::Type{GrayA{N0f8}}, img::AbstractArray{GrayA{N0f8}}) = MapNone{GrayA{N0f8}}() -for (T,n) in bitshiftto8 - @eval mapinfo(::Type{N0f8}, img::GrayArray{$T}) = BitShift{N0f8,$n}() - @eval mapinfo(::Type{Gray{N0f8}}, img::GrayArray{$T}) = BitShift{Gray{N0f8},$n}() - @eval mapinfo(::Type{GrayA{N0f8}}, img::AbstractArray{GrayA{$T}}) = BitShift{GrayA{N0f8},$n}() -end -mapinfo{T<:Normed,F<:AbstractFloat}(::Type{T}, img::GrayArray{F}) = ClampMinMax(T, zero(F), one(F)) -mapinfo{T<:Normed,F<:AbstractFloat}(::Type{Gray{T}}, img::GrayArray{F}) = ClampMinMax(Gray{T}, zero(F), one(F)) -mapinfo{T<:AbstractFloat, R<:Real}(::Type{T}, img::AbstractArray{R}) = MapNone(T) - -mapinfo(::Type{RGB24}, img::Union{AbstractArray{Bool}, BitArray}) = MapNone{RGB24}() -mapinfo(::Type{ARGB32}, img::Union{AbstractArray{Bool}, BitArray}) = MapNone{ARGB32}() -mapinfo{F<:Fractional}(::Type{RGB24}, img::GrayArray{F}) = ClampMinMax(RGB24, zero(F), one(F)) -mapinfo{F<:Fractional}(::Type{ARGB32}, img::AbstractArray{F}) = ClampMinMax(ARGB32, zero(F), one(F)) - -# Color->Color methods -mapinfo(::Type{RGB{N0f8}}, img) = MapNone{RGB{N0f8}}() -mapinfo(::Type{RGBA{N0f8}}, img) = MapNone{RGBA{N0f8}}() -for (T,n) in bitshiftto8 - @eval mapinfo(::Type{RGB{N0f8}}, img::AbstractArray{RGB{$T}}) = BitShift{RGB{N0f8},$n}() - @eval mapinfo(::Type{RGBA{N0f8}}, img::AbstractArray{RGBA{$T}}) = BitShift{RGBA{N0f8},$n}() -end -mapinfo{F<:Fractional}(::Type{RGB{N0f8}}, img::AbstractArray{RGB{F}}) = Clamp(RGB{N0f8}) -mapinfo{F<:Fractional}(::Type{RGBA{N0f8}}, img::AbstractArray{RGBA{F}}) = Clamp(RGBA{N0f8}) - - - -# Color->RGB24/ARGB32 -mapinfo(::Type{RGB24}, img::AbstractArray{RGB24}) = MapNone{RGB24}() -mapinfo(::Type{ARGB32}, img::AbstractArray{ARGB32}) = MapNone{ARGB32}() -for C in tuple(subtypes(AbstractRGB)..., Gray) - C == RGB24 && continue - @eval mapinfo(::Type{RGB24}, img::AbstractArray{$C{N0f8}}) = MapNone{RGB24}() - @eval mapinfo(::Type{ARGB32}, img::AbstractArray{$C{N0f8}}) = MapNone{ARGB32}() - for (T, n) in bitshiftto8 - @eval mapinfo(::Type{RGB24}, img::AbstractArray{$C{$T}}) = BitShift{RGB24, $n}() - @eval mapinfo(::Type{ARGB32}, img::AbstractArray{$C{$T}}) = BitShift{ARGB32, $n}() - end - @eval mapinfo{F<:AbstractFloat}(::Type{RGB24}, img::AbstractArray{$C{F}}) = ClampMinMax(RGB24, zero(F), one(F)) - @eval mapinfo{F<:AbstractFloat}(::Type{ARGB32}, img::AbstractArray{$C{F}}) = ClampMinMax(ARGB32, zero(F), one(F)) - for AC in subtypes(TransparentColor) - hasparameters(AC, 2) || continue - @eval mapinfo(::Type{ARGB32}, img::AbstractArray{$AC{$C{N0f8},N0f8}}) = MapNone{ARGB32}() - @eval mapinfo(::Type{RGB24}, img::AbstractArray{$AC{$C{N0f8},N0f8}}) = MapNone{RGB24}() - for (T, n) in bitshiftto8 - @eval mapinfo(::Type{ARGB32}, img::AbstractArray{$AC{$C{$T},$T}}) = BitShift{ARGB32, $n}() - @eval mapinfo(::Type{RGB24}, img::AbstractArray{$AC{$C{$T},$T}}) = BitShift{RGB24, $n}() - end - @eval mapinfo{F<:AbstractFloat}(::Type{ARGB32}, img::AbstractArray{$AC{$C{F},F}}) = ClampMinMax(ARGB32, zero(F), one(F)) - @eval mapinfo{F<:AbstractFloat}(::Type{RGB24}, img::AbstractArray{$AC{$C{F},F}}) = ClampMinMax(RGB24, zero(F), one(F)) - end -end - -mapinfo{CT<:Colorant}(::Type{RGB24}, img::AbstractArray{CT}) = MapNone{RGB24}() -mapinfo{CT<:Colorant}(::Type{ARGB32}, img::AbstractArray{CT}) = MapNone{ARGB32}() - - -# UInt32 conversions will use ARGB32 for images that have an alpha channel, -# and RGB24 when not -mapinfo{CV<:Union{Fractional,Color,AbstractGray}}(::Type{UInt32}, img::AbstractArray{CV}) = mapinfo(RGB24, img) -mapinfo{CV<:TransparentColor}(::Type{UInt32}, img::AbstractArray{CV}) = mapinfo(ARGB32, img) -mapinfo(::Type{UInt32}, img::Union{AbstractArray{Bool},BitArray}) = mapinfo(RGB24, img) -mapinfo(::Type{UInt32}, img::AbstractArray{UInt32}) = MapNone{UInt32}() - - -# Clamping mapinfo client. Converts to RGB and uses Normed, clamping -# floating-point values to [0,1]. -mapinfo{T<:Normed}(::Type{Clamp}, img::AbstractArray{T}) = MapNone{T}() -mapinfo{T<:AbstractFloat}(::Type{Clamp}, img::AbstractArray{T}) = ClampMinMax(N0f8, zero(T), one(T)) -let handled = Set() -for ACV in (Color, AbstractRGB) - for CV in subtypes(ACV) - hasparameters(CV, 1) || continue - CVnew = CV<:AbstractGray ? Gray : RGB - @eval mapinfo{T<:Normed}(::Type{Clamp}, img::AbstractArray{$CV{T}}) = MapNone{$CVnew{T}}() - @eval mapinfo{CV<:$CV}(::Type{Clamp}, img::AbstractArray{CV}) = Clamp{$CVnew{N0f8}}() - CVnew = CV<:AbstractGray ? Gray : BGR - AC, CA = alphacolor(CV), coloralpha(CV) - if AC in handled - continue - end - push!(handled, AC) - ACnew, CAnew = alphacolor(CVnew), coloralpha(CVnew) - @eval begin - mapinfo{T<:Normed}(::Type{Clamp}, img::AbstractArray{$AC{T}}) = MapNone{$ACnew{T}}() - mapinfo{P<:$AC}(::Type{Clamp}, img::AbstractArray{P}) = Clamp{$ACnew{N0f8}}() - mapinfo{T<:Normed}(::Type{Clamp}, img::AbstractArray{$CA{T}}) = MapNone{$CAnew{T}}() - mapinfo{P<:$CA}(::Type{Clamp}, img::AbstractArray{P}) = Clamp{$CAnew{N0f8}}() - end - end -end -end -mapinfo(::Type{Clamp}, img::AbstractArray{RGB24}) = MapNone{RGB{N0f8}}() -mapinfo(::Type{Clamp}, img::AbstractArray{ARGB32}) = MapNone{BGRA{N0f8}}() - - -""" -``` -imgsc = sc(img) -imgsc = sc(img, min, max) -``` - -Applies default or specified `ScaleMinMax` mapping to the image. -""" -sc(img::AbstractArray) = immap(ScaleMinMax(N0f8, img), img) -sc(img::AbstractArray, mn::Real, mx::Real) = immap(ScaleMinMax(N0f8, img, mn, mx), img) - -ufixedsc{T<:Normed}(::Type{T}, img::AbstractArray) = immap(mapinfo(T, img), img) -ufixed8sc(img::AbstractArray) = ufixedsc(N0f8, img) diff --git a/src/overlays-deprecated.jl b/src/overlays-deprecated.jl deleted file mode 100644 index ce8b36ef..00000000 --- a/src/overlays-deprecated.jl +++ /dev/null @@ -1,56 +0,0 @@ -function Overlay(channels::Tuple{Vararg{AbstractArray}}, colors, mapi::Tuple{Vararg{MapInfo}}) - _overlay(channels, colors, map(m->(x->immap(m, x)), mapi)) -end - -function Overlay(channels::Tuple{Vararg{AbstractArray}}, - colors, - clim = ntuple(i->(zero(eltype(channels[i])), one(eltype(channels[i]))), length(channels))) - n = length(channels) - for i = 1:n - if length(clim[i]) != 2 - error("clim must be a 2-vector") - end - end - fs = ntuple(i->scaleminmax(Float32, clim[i][1], clim[i][2]), n) - _overlay(channels, colors, fs) -end - -function _overlay(channels, colors, fs) - NC = length(colors) - length(channels) == NC || error("Number of channels must match number of colors") - length(fs) == NC || error("Number of MapInfo objects must match number of colors") - channelidx = channelassign(colors) - syms = [:zeroarray, :A, :B, :C][channelidx+1] - depwarn("Overlay(channels, colors, ...) is deprecated, please use colorview(RGB, StackedView($(syms...))), possibly in conjunction with mappedarray", :Overlay) - mc = [mappedarray(fs[i], channels[i]) for i = 1:NC] - zchannels = (zeroarray, mc...) - T = promote_type((eltype(c) for c in colors)...) - chan = zchannels[channelidx+1] - colorview(RGB, StackedView{T}(chan...)) -end - -function channelassign(colors) - n = length(colors) - channelidx = zeros(Int, 3) - for i = 1:n - col = convert(RGB, colors[i]) - setchannelidx!(channelidx, i, red(col), 1) - setchannelidx!(channelidx, i, green(col), 2) - setchannelidx!(channelidx, i, blue(col), 3) - end - channelidx -end - -function setchannelidx!(channelidx, i, val, colorindex) - if val != 0 - if channelidx[colorindex] != 0 - error("in the deprecated version, mixing in color channels is not supported, please see ??") - end - channelidx[colorindex] = i - end - channelidx -end - -nchannels{C,N,A<:StackedView}(ovr::ColorView{C,N,A}) = sum(!isa(A, ImageCore.ZeroArray) for A in ovr.parent.parents) - -OverlayImage(args...) = ImageMeta(Overlay(args...)) diff --git a/test/old/algorithms.jl b/test/old/algorithms.jl deleted file mode 100644 index 77f48ff3..00000000 --- a/test/old/algorithms.jl +++ /dev/null @@ -1,477 +0,0 @@ -using FactCheck, Base.Test, Images, Colors, FixedPointNumbers, Compat, OffsetArrays -using Compat.view - -srand(1234) - -facts("Algorithms") do - # Comparison of each element in arrays with a scalar - approx_equal(ar, v) = @compat all(abs.(ar.-v) .< sqrt(eps(v))) - approx_equal(ar::Images.AbstractImage, v) = approx_equal(Images.data(ar), v) - - context("Flip dimensions") do - A = grayim(UInt8[200 150; 50 1]) - @fact raw(flipy(A)) --> raw(flipdim(A, 1)) "test vRs7Gx" - @fact raw(flipx(A)) --> raw(flipdim(A, 2)) "test omDVHe" - end - - context("Arithmetic") do - img = convert(Images.Image, zeros(3,3)) - img2 = (img .+ 3)/2 - @fact all(img2 .== 1.5) --> true "test mzgz4D" - img3 = 2img2 - @fact all(img3 .== 3) --> true "test ECrt7w" - img3 = copy(img2) - img3[img2 .< 4] = -1 - @fact all(img3 .== -1) --> true "test 5OclVr" - img = convert(Images.Image, rand(3,4)) - A = rand(3,4) - img2 = img .* A - @fact all(Images.data(img2) == Images.data(img).*A) --> true "test Txfm6a" - img2 = convert(Images.Image, A) - img2 = img2 .- 0.5 - img3 = 2img .* data(img2) - img2 = img ./ A - img2 = (2img).^2 - # Same operations with Color images - img = Images.colorim(zeros(Float32,3,4,5)) - img2 = (img .+ RGB{Float32}(1,1,1))/2 - @fact all(img2 .== RGB{Float32}(1,1,1)/2) --> true "test yBGjhP" - img3 = 2img2 - @fact all(img3 .== RGB{Float32}(1,1,1)) --> true "test ZaNzgJ" - A = fill(2, 4, 5) - @fact all(A.*img2 .== fill(RGB{Float32}(1,1,1), 4, 5)) --> true "test OT1P7V" - img2 = img2 .- RGB{Float32}(1,1,1)/2 - A = rand(UInt8,3,4) - img = reinterpret(Gray{N0f8}, Images.grayim(A)) - imgm = mean(img) - imgn = img/imgm - @fact reinterpret(Float64, Images.data(imgn)) --> roughly(convert(Array{Float64}, A/mean(A))) "test NTAvmj" - @fact imcomplement([Gray(0.2)]) --> [Gray(0.8)] "test Gu9b6h" - @fact imcomplement([Gray{N0f8}(0.2)]) --> [Gray{N0f8}(0.8)] "test Kle9oP" - @fact imcomplement([RGB(0,0.3,1)]) --> [RGB(1,0.7,0)] "test jgxQxd" - @fact imcomplement([RGBA(0,0.3,1,0.7)]) --> [RGBA(1.0,0.7,0.0,0.7)] "test tEAo1x" - @fact imcomplement([RGBA{N0f8}(0,0.6,1,0.7)]) --> [RGBA{N0f8}(1.0,0.4,0.0,0.7)] "test MGiodE" - - img = rand(1:10,10,10) - img2 = rand(1:2,10,10) - img3 = reinterpret(Gray{N0f8}, grayim(rand(UInt8,10,10))) - @fact all([entropy(img, kind=kind) for kind in [:shannon,:nat,:hartley]] .≥ 0) --> true "test lwgD8l" - @fact all([entropy(img2, kind=kind) for kind in [:shannon,:nat,:hartley]] .≥ 0) --> true "test L7wFfa" - @fact all([entropy(img3, kind=kind) for kind in [:shannon,:nat,:hartley]] .≥ 0) --> true "test OHwUzO" - end - - context("Reductions") do - A = rand(5,5,3) - img = Images.colorim(A, "RGB") - s12 = sum(img, (1,2)) - @fact Images.colorspace(s12) --> "RGB" "test gjp91q" - A = [NaN, 1, 2, 3] - @fact Images.meanfinite(A, 1) --> roughly([2]) "test jy9vvu" - A = [NaN 1 2 3; - NaN 6 5 4] - mf = Images.meanfinite(A, 1) - @fact isnan(mf[1]) --> true "test meanfiniteNaN" - @test_approx_eq mf[1,2:end] [3.5 3.5 3.5] - @test_approx_eq Images.meanfinite(A, 2) [2, 5]' - @test_approx_eq Images.meanfinite(A, (1,2)) [3.5] - @fact Images.minfinite(A) --> 1 "test ctthKJ" - @fact Images.maxfinite(A) --> 6 "test 1TSlCM" - @fact Images.maxabsfinite(A) --> 6 "test w7j5sr" - A = rand(10:20, 5, 5) - @fact minfinite(A) --> minimum(A) "test k5GtIe" - @fact maxfinite(A) --> maximum(A) "test 8qaTAa" - A = reinterpret(N0f8, rand(0x00:0xff, 5, 5)) - @fact minfinite(A) --> minimum(A) "test RCl2VS" - @fact maxfinite(A) --> maximum(A) "test eKwX2u" - A = rand(Float32,3,5,5) - img = Images.colorim(A, "RGB") - dc = Images.data(Images.meanfinite(img, 1))-reinterpret(RGB{Float32}, mean(A, 2), (1,5)) - @fact maximum(map(abs, dc)) --> less_than(1e-6) "test e62u7Q" - dc = Images.minfinite(img)-RGB{Float32}(minimum(A, (2,3))...) - @fact abs(dc) --> less_than(1e-6) "test ynXLYd" - dc = Images.maxfinite(img)-RGB{Float32}(maximum(A, (2,3))...) - @fact abs(dc) --> less_than(1e-6) "test Nu5oAt" - - a = convert(Array{UInt8}, [1, 1, 1]) - b = convert(Array{UInt8}, [134, 252, 4]) - @fact Images.sad(a, b) --> 387 "test sx70B8" - @fact Images.ssd(a, b) --> 80699 "test aFz7hO" - af = reinterpret(N0f8, a) - bf = reinterpret(N0f8, b) - @fact Images.sad(af, bf) --> roughly(387f0/255) "test R3U9a6" - @fact Images.ssd(af, bf) --> roughly(80699f0/255^2) "test WtPNxa" - ac = reinterpret(RGB{N0f8}, a) - bc = reinterpret(RGB{N0f8}, b) - @fact Images.sad(ac, bc) --> roughly(387f0/255) "test wtRHsd" - @fact Images.ssd(ac, bc) --> roughly(80699f0/255^2) "test Ti1QN0" - ag = reinterpret(RGB{N0f8}, a) - bg = reinterpret(RGB{N0f8}, b) - @fact Images.sad(ag, bg) --> roughly(387f0/255) "test jaMtWn" - @fact Images.ssd(ag, bg) --> roughly(80699f0/255^2) "test Gc9gbr" - - a = rand(15,15) - @fact_throws ErrorException (Images.@test_approx_eq_sigma_eps a rand(13,15) [1,1] 0.01) "test Pkx94Y" - @fact_throws ErrorException (Images.@test_approx_eq_sigma_eps a rand(15,15) [1,1] 0.01) "test xrZo3m" - @fact (Images.@test_approx_eq_sigma_eps a a [1,1] 0.01) --> nothing "test ccbApu" - @fact (Images.@test_approx_eq_sigma_eps a a+0.01*rand(size(a)) [1,1] 0.01) --> nothing "test JhUXjB" - @fact_throws ErrorException (Images.@test_approx_eq_sigma_eps a a+0.5*rand(size(a)) [1,1] 0.01) "test a1yPd4" - a = colorim(rand(3,15,15)) - @fact (Images.@test_approx_eq_sigma_eps a a [1,1] 0.01) --> nothing "test 9DBljW" - @fact_throws ErrorException (Images.@test_approx_eq_sigma_eps a colorim(rand(3,15,15)) [1,1] 0.01) "test 4LhXLK" - - a = rand(15,15) - @fact_throws ErrorException Images.test_approx_eq_sigma_eps(a, rand(13,15), [1,1], 0.01) "test vMzGQH" - @fact_throws ErrorException Images.test_approx_eq_sigma_eps(a, rand(15,15), [1,1], 0.01) "test w51zmO" - @fact Images.test_approx_eq_sigma_eps(a, a, [1,1], 0.01) --> 0.0 "test 8NfaXn" - @fact Images.test_approx_eq_sigma_eps(a, a+0.01*rand(size(a)), [1,1], 0.01) --> greater_than(0.0) "test S9POMO" - @fact_throws ErrorException Images.test_approx_eq_sigma_eps(a, a+0.5*rand(size(a)), [1,1], 0.01) "test SaFtHr" - a = colorim(rand(3,15,15)) - @fact Images.test_approx_eq_sigma_eps(a, a, [1,1], 0.01) --> 0.0 "test wtlfUO" - @fact_throws ErrorException Images.test_approx_eq_sigma_eps(a, colorim(rand(3,15,15)), [1,1], 0.01) "test bccntj" - - @fact Images.test_approx_eq_sigma_eps(a[:,1:end-1], a[1:end-1,:], [3,3], 0.1) --> less_than(0.1) "test j0aGQD" - @fact_throws Images.test_approx_eq_sigma_eps(a[:,1:end-1], a[1:end-1,:], [3,3], 0.01) "test qJcPdD" - - a = zeros(10, 10) - int_img = integral_image(a) - @fact all(int_img == a) --> true "test UjtTze" - - a = ones(10,10) - int_img = integral_image(a) - chk = Array(1:10) - @fact all([vec(int_img[i, :]) == chk * i for i in 1:10]) --> true "test TWnkpp" - - int_sum = boxdiff(int_img, 1, 1, 5, 2) - @fact int_sum --> 10.0 "test CNwchG" - int_sum = boxdiff(int_img, 1:5, 1:2) - @fact int_sum --> 10.0 "test sbCuZQ" - int_sum = boxdiff(int_img, CartesianIndex((1, 1)), CartesianIndex((5, 2))) - @fact int_sum --> 10.0 "test UWb90L" - int_sum = boxdiff(int_img, 1, 1, 2, 5) - @fact int_sum --> 10.0 "test C4yK8H" - int_sum = boxdiff(int_img, 1:2, 1:5) - @fact int_sum --> 10.0 "test 9mTOGN" - int_sum = boxdiff(int_img, CartesianIndex((1, 1)), CartesianIndex((2, 5))) - @fact int_sum --> 10.0 "test 6B1IU2" - int_sum = boxdiff(int_img, 4, 4, 8, 8) - @fact int_sum --> 25.0 "test 4BiU7v" - int_sum = boxdiff(int_img, 4:8, 4:8) - @fact int_sum --> 25.0 "test GGj1cU" - int_sum = boxdiff(int_img, CartesianIndex((4, 4)), CartesianIndex((8, 8))) - @fact int_sum --> 25.0 "test vM8fF1" - - a = reshape(1:100, 10, 10) - int_img = integral_image(a) - @fact int_img[diagind(int_img)] == Array([1, 26, 108, 280, 575, 1026, 1666, 2528, 3645, 5050]) --> true "test oPHNmm" - - int_sum = boxdiff(int_img, 1, 1, 3, 3) - @fact int_sum --> 108 "test eGx0PK" - int_sum = boxdiff(int_img, 1:3, 1:3) - @fact int_sum --> 108 "test KKhF8q" - int_sum = boxdiff(int_img, CartesianIndex((1, 1)), CartesianIndex((3, 3))) - @fact int_sum --> 108 "test K5Rnhs" - int_sum = boxdiff(int_img, 1, 1, 5, 2) - @fact int_sum --> 80 "test HM7SD3" - int_sum = boxdiff(int_img, 1:5, 1:2) - @fact int_sum --> 80 "test fBsFaz" - int_sum = boxdiff(int_img, CartesianIndex((1, 1)), CartesianIndex((5, 2))) - @fact int_sum --> 80 "test MhkNgv" - int_sum = boxdiff(int_img, 4, 4, 8, 8) - @fact int_sum --> 1400 "test 3s3WYt" - int_sum = boxdiff(int_img, 4:8, 4:8) - @fact int_sum --> 1400 "test uYHL4A" - int_sum = boxdiff(int_img, CartesianIndex((4, 4)), CartesianIndex((8, 8))) - @fact int_sum --> 1400 "test V3Bw7v" - - img = zeros(40, 40) - img[10:30, 10:30] = 1 - pyramid = gaussian_pyramid(img, 3, 2, 1.0) - @fact size(pyramid[1]) == (40, 40) --> true "test 7PkJim" - @fact size(pyramid[2]) == (20, 20) --> true "test sFshCA" - @fact size(pyramid[3]) == (10, 10) --> true "test GoaiPs" - @fact size(pyramid[4]) == (5, 5) --> true "test 7x7aQ3" - @fact isapprox(pyramid[1][20, 20], 1.0, atol = 0.01) --> true "test 87udZ1" - @fact isapprox(pyramid[2][10, 10], 1.0, atol = 0.01) --> true "test HgqMZk" - @fact isapprox(pyramid[3][5, 5], 1.0, atol = 0.05) --> true "test 98smZ2" - @fact isapprox(pyramid[4][3, 3], 0.9, atol = 0.025) --> true "test NXNu7G" - end - - context("fft and ifft") do - A = rand(Float32, 3, 5, 6) - img = Images.colorim(A) - imgfft = fft(channelview(img), 2:3) - @fact Images.data(imgfft) --> roughly(fft(A, 2:3)) "test LlCbyo" - img2 = ifft(imgfft, 2:3) - @fact img2 --> roughly(A) "test D74cjO" - end - - context("Restriction") do - imgcol = Images.colorim(rand(3,5,6)) - A = reshape([convert(UInt16, i) for i = 1:60], 4, 5, 3) - B = Images.restrict(A, (1,2)) - Btarget = cat(3, [ 0.96875 4.625 5.96875; - 2.875 10.5 12.875; - 1.90625 5.875 6.90625], - [ 8.46875 14.625 13.46875; - 17.875 30.5 27.875; - 9.40625 15.875 14.40625], - [15.96875 24.625 20.96875; - 32.875 50.5 42.875; - 16.90625 25.875 21.90625]) - @fact B --> roughly(Btarget) "test g0lXjp" - Argb = reinterpret(RGB, reinterpret(N0f16, permutedims(A, (3,1,2)))) - B = Images.restrict(Argb) - Bf = permutedims(reinterpret(eltype(eltype(B)), B), (2,3,1)) - @fact Bf --> roughly(Btarget/reinterpret(one(N0f16)), 1e-12) "test IVByaq" - Argba = reinterpret(RGBA{N0f16}, reinterpret(N0f16, A)) - B = Images.restrict(Argba) - @fact reinterpret(eltype(eltype(B)), B) --> roughly(Images.restrict(A, (2,3))/reinterpret(one(N0f16)), 1e-12) "test z8K24e" - A = reshape(1:60, 5, 4, 3) - B = Images.restrict(A, (1,2,3)) - @fact cat(3, [ 2.6015625 8.71875 6.1171875; - 4.09375 12.875 8.78125; - 3.5390625 10.59375 7.0546875], - [10.1015625 23.71875 13.6171875; - 14.09375 32.875 18.78125; - 11.0390625 25.59375 14.5546875]) --> roughly(B) "test ClRQpv" - imgcolax = AxisArray(imgcol, :y, :x) - imgr = Images.restrict(imgcolax, (1,2)) - @fact pixelspacing(imgr) --> (2,2) "test tu0DXK" - @fact pixelspacing(imgcolax) --> (1,1) # issue #347 "test JR7awG" - # Issue #395 - img1 = colorim(fill(0.9, 3, 5, 5)) - img2 = colorim(fill(N0f8(0.9), 3, 5, 5)) - @fact separate(restrict(img1)) --> roughly(separate(restrict(img2)), 0.01) "test TH8OoL" - end - - context("Erode/ dilate") do - A = zeros(4,4,3) - A[2,2,1] = 0.8 - A[4,4,2] = 0.6 - Ae = Images.erode(A) - @fact Ae --> zeros(size(A)) "test kT2gnC" - Ad = Images.dilate(A, 1:2) - Ar = [0.8 0.8 0.8 0; - 0.8 0.8 0.8 0; - 0.8 0.8 0.8 0; - 0 0 0 0] - Ag = [0 0 0 0; - 0 0 0 0; - 0 0 0.6 0.6; - 0 0 0.6 0.6] - @fact Ad --> cat(3, Ar, Ag, zeros(4,4)) "test AnS1W2" - Ae = Images.erode(Ad, 1:2) - Ar = [0.8 0.8 0 0; - 0.8 0.8 0 0; - 0 0 0 0; - 0 0 0 0] - Ag = [0 0 0 0; - 0 0 0 0; - 0 0 0 0; - 0 0 0 0.6] - @fact Ae --> cat(3, Ar, Ag, zeros(4,4)) "test vs0TRg" - # issue #311 - @fact Images.dilate(trues(3)) --> trues(3) "test Eykrqy" - end - - context("Extrema_filter") do - # 2d case - A = zeros(5,5) - A[2,2] = 0.8 - A[4,4] = 0.6 - minval, maxval = extrema_filter(A, 2) - matching = [vec(A[2:end]) .!= vec(maxval); false] - @fact A[reshape(matching, size(A))] --> [0.8, 0.6] "test nQ22cy" - # 3d case - A = zeros(5,5,5) - A[2,2,2] = 0.7 - A[4,4,3] = 0.5 - minval, maxval = extrema_filter(A, 2) - matching = [vec(A[2:end]) .!= vec(maxval); false] - @fact A[reshape(matching, size(A))] --> [0.7, 0.5] "test NXCGwQ" - # 4d case - A = zeros(5,5,5,5) - A[2,2,2,2] = 0.7 - A[4,4,3,1] = 0.4 - A[3,4,3,2] = 0.5 - minval, maxval = extrema_filter(A, 2) - matching = [vec(A[2:end]) .!= vec(maxval); false] - @fact A[reshape(matching, size(A))] --> [0.4,0.7,0.5] "test Cw5Mbc" - x, y, z, t = ind2sub(size(A), find(A .== 0.4)) - @fact x[1] --> 4 "test ptjTjw" - @fact y[1] --> 4 "test KKwmrK" - @fact z[1] --> 3 "test Pz5dnk" - @fact t[1] --> 1 "test GFMLRG" - # 2d case - A = rand(5,5)/10 - A[2,2] = 0.8 - A[4,4] = 0.6 - minval, maxval = extrema_filter(A, [2, 2]) - matching = falses(A) - matching[2:end, 2:end] = maxval .== A[2:end, 2:end] - @fact sort(A[matching])[end-1:end] --> [0.6, 0.8] "test 1SqoTD" - # 3d case - A = rand(5,5,5)/10 - A[2,2,2] = 0.7 - A[4,4,2] = 0.4 - A[2,2,4] = 0.5 - minval, maxval = extrema_filter(A, [2, 2, 2]) - matching = falses(A) - matching[2:end, 2:end, 2:end] = maxval .== A[2:end, 2:end, 2:end] - @fact sort(A[matching])[end-2:end] --> [0.4, 0.5, 0.7] "test XJKNe1" - # 4d case - A = rand(5,5,5,5)/10 - A[2,2,2,2] = 0.7 - A[4,4,2,3] = 0.4 - A[2,2,4,3] = 0.5 - minval, maxval = extrema_filter(A, [2, 2, 2, 2]) - matching = falses(A) - matching[2:end, 2:end, 2:end, 2:end] = maxval .== A[2:end, 2:end, 2:end, 2:end] - @fact sort(A[matching])[end-2:end] --> [0.4, 0.5, 0.7] "test TqtAKq" - end - - context("Opening / closing") do - A = zeros(4,4,3) - A[2,2,1] = 0.8 - A[4,4,2] = 0.6 - Ao = Images.opening(A) - @fact Ao --> zeros(size(A)) "test dRBjeP" - A = zeros(10,10) - A[4:7,4:7] = 1 - B = copy(A) - A[5,5] = 0 - Ac = Images.closing(A) - @fact Ac --> B "test NFEnY3" - end - - context("Morphological Top-hat") do - A = zeros(13, 13) - A[2:3, 2:3] = 1 - Ae = copy(A) - A[5:9, 5:9] = 1 - Ao = Images.tophat(A) - @fact Ao --> Ae "test VxhCpF" - Aoo = Images.tophat(Ae) - @fact Aoo --> Ae "test xA9B1t" - end - - context("Morphological Bottom-hat") do - A = ones(13, 13) - A[2:3, 2:3] = 0 - Ae = 1 - copy(A) - A[5:9, 5:9] = 0 - Ao = Images.bothat(A) - @fact Ao --> Ae "test olSLjv" - end - - context("Morphological Gradient") do - A = zeros(13, 13) - A[5:9, 5:9] = 1 - Ao = Images.morphogradient(A) - Ae = zeros(13, 13) - Ae[4:10, 4:10] = 1 - Ae[6:8, 6:8] = 0 - @fact Ao --> Ae "test FjldLK" - Aee = Images.dilate(A) - Images.erode(A) - @fact Aee --> Ae "test PMRzxP" - end - - context("Morphological Laplacian") do - A = zeros(13, 13) - A[5:9, 5:9] = 1 - Ao = Images.morpholaplace(A) - Ae = zeros(13, 13) - Ae[4:10, 4:10] = 1 - Ae[5:9, 5:9] = -1 - Ae[6:8, 6:8] = 0 - @fact Ao --> Ae "test 52XRJX" - Aee = Images.dilate(A) + Images.erode(A) - 2A - @fact Aee --> Ae "test J1QcHc" - end - - context("Label components") do - A = [true true false true; - true false true true] - lbltarget = [1 1 0 2; - 1 0 2 2] - lbltarget1 = [1 2 0 4; - 1 0 3 4] - @fact Images.label_components(A) --> lbltarget "test JroBn0" - @fact Images.label_components(A, [1]) --> lbltarget1 "test QJVu6m" - connectivity = [false true false; - true false true; - false true false] - @fact Images.label_components(A, connectivity) --> lbltarget "test vz5uon" - connectivity = trues(3,3) - lbltarget2 = [1 1 0 1; - 1 0 1 1] - @fact Images.label_components(A, connectivity) --> lbltarget2 "test CFEvKh" - @fact component_boxes(lbltarget) --> Vector{Tuple}[[(1,2),(2,3)],[(1,1),(2,2)],[(1,3),(2,4)]] "test X6qLkS" - @fact component_lengths(lbltarget) --> [2,3,3] "test BoBrn8" - @fact component_indices(lbltarget) --> Array{Int64}[[4,5],[1,2,3],[6,7,8]] "test iHJcSR" - @fact component_subscripts(lbltarget) --> Array{Tuple}[[(2,2),(1,3)],[(1,1),(2,1),(1,2)],[(2,3),(1,4),(2,4)]] "test gyzoNi" - @fact component_centroids(lbltarget) --> Tuple[(1.5,2.5),(4/3,4/3),(5/3,11/3)] "test RMvhLP" - end - - context("Phantoms") do - P = [ 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0; - 0.0 0.0 1.0 0.2 0.2 1.0 0.0 0.0; - 0.0 0.0 0.2 0.3 0.3 0.2 0.0 0.0; - 0.0 0.0 0.2 0.0 0.2 0.2 0.0 0.0; - 0.0 0.0 0.2 0.0 0.0 0.2 0.0 0.0; - 0.0 0.0 0.2 0.2 0.2 0.2 0.0 0.0; - 0.0 0.0 1.0 0.2 0.2 1.0 0.0 0.0; - 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ] - Q = Images.shepp_logan(8) - @fact norm((P-Q)[:]) --> less_than(1e-10) "test Xl6BcQ" - P = [ 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0; - 0.0 0.0 2.0 1.02 1.02 2.0 0.0 0.0; - 0.0 0.0 1.02 1.03 1.03 1.02 0.0 0.0; - 0.0 0.0 1.02 1.0 1.02 1.02 0.0 0.0; - 0.0 0.0 1.02 1.0 1.0 1.02 0.0 0.0; - 0.0 0.0 1.02 1.02 1.02 1.02 0.0 0.0; - 0.0 0.0 2.0 1.02 1.02 2.0 0.0 0.0; - 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ] - Q = Images.shepp_logan(8, highContrast=false) - @fact norm((P-Q)[:]) --> less_than(1e-10) "test MFwM6o" - end - - context("Image resize") do - img = convert(Images.Image, zeros(10,10)) - img2 = Images.imresize(img, (5,5)) - @fact length(img2) --> 25 "test l5xQhW" - end - - context("Interpolations") do - - img = zeros(Float64, 5, 5) - @fact bilinear_interpolation(img, 4.5, 5.5) --> 0.0 "test bhkr9P" - @fact bilinear_interpolation(img, 4.5, 3.5) --> 0.0 "test In1KLU" - - for i in [1.0, 2.0, 5.0, 7.0, 9.0] - img = ones(Float64, 5, 5) * i - @fact (bilinear_interpolation(img, 3.5, 4.5) == i) --> true "test YiwKrn" - @fact (bilinear_interpolation(img, 3.2, 4) == i) --> true # X_MAX == X_MIN "test zzKRPq" - @fact (bilinear_interpolation(img, 3.2, 4) == i) --> true # Y_MAX == Y_MIN "test RbjV3L" - @fact (bilinear_interpolation(img, 3.2, 4) == i) --> true # BOTH EQUAL "test WVPgJQ" - @fact (bilinear_interpolation(img, 2.8, 1.9) == i) --> true "test S4fl6z" - # One dim out of bounds - @fact isapprox(bilinear_interpolation(img, 0.5, 1.5), 0.5 * i) --> true "test 5vocwI" - @fact isapprox(bilinear_interpolation(img, 0.5, 1.6), 0.5 * i) --> true "test ssXoVz" - @fact isapprox(bilinear_interpolation(img, 0.5, 1.8), 0.5 * i) --> true "test Mg0DVi" - # Both out of bounds (corner) - @fact isapprox(bilinear_interpolation(img, 0.5, 0.5), 0.25 * i) --> true "test CtbuP5" - end - - img = reshape(1.0:1.0:25.0, 5, 5) - @fact bilinear_interpolation(img, 1.5, 2) --> 6.5 "test J81zIL" - @fact bilinear_interpolation(img, 2, 1.5) --> 4.5 "test fqXV9r" - @fact bilinear_interpolation(img, 2, 1) --> 2.0 "test 4T1SSb" - @fact bilinear_interpolation(img, 1.5, 2.5) --> 9.0 "test mBjvW9" - @fact bilinear_interpolation(img, 1.5, 3.5) --> 14.0 "test EHqnCK" - @fact bilinear_interpolation(img, 1.5, 4.5) --> 19.0 "test FGWq37" - @fact bilinear_interpolation(img, 1.5, 5.5) --> 10.75 "test z2ejkZ" - - end - -end diff --git a/test/old/core.jl b/test/old/core.jl deleted file mode 100644 index c982b429..00000000 --- a/test/old/core.jl +++ /dev/null @@ -1,377 +0,0 @@ -using FactCheck, Images, Colors, FixedPointNumbers, IndirectArrays, AxisArrays -using Compat -using Compat.view - -testing_units = Int == Int64 -if testing_units - using SIUnits, SIUnits.ShortUnits -end - -const scalar_getindex_new = VERSION >= v"0.5.0-dev+1195" - -facts("Core") do - a = rand(3,3) - @inferred(Image(a)) - # support integer-valued types, but these are NOT recommended (use Normed) - B = rand(UInt16(1):UInt16(20), 3, 5) - # img, imgd, and imgds will be used in many more tests - # Thus, these must be defined as local if reassigned in any context() blocks - cmap = reinterpret(RGB, repmat(reinterpret(N0f8, round(UInt8, linspace(12, 255, 20)))', 3, 1)) - imgi = IndirectArray(copy(B), cmap) - img = AxisArray(imgi, Axis{:y}(2*(1:size(imgi,1))), Axis{:x}(3*(1:size(imgi,2)))) - imgd0 = convert(Array, imgi) - if testing_units - imgd = AxisArray(imgd0, - Axis{:y}(2mm:2mm:2*size(imgi,1)*mm), - Axis{:x}(3mm:3mm:3*size(imgi,2)*mm)) - else - imgd = AxisArray(imgd0, axes(img)...) - end - imgds = separate(imgd) - - context("Constructors of Image types") do - @fact colorspace(B) --> "Gray" "test h42DSP" - @fact colordim(B) --> 0 "test 4ZQwBT" - let img = colorview(RGB, normedview(Normed{UInt16,8}, B)) - @fact colorspace(img) --> "RGB" "test THoeTd" - @fact colordim(img) --> 0 "test Zm2gDZ" - img = grayim(B) - @fact colorspace(img) --> "Gray" "test SIFbZo" - @fact colordim(B) --> 0 "test HAdcG0" - @fact grayim(img) --> img "test mJppbD" - Bf = grayim(round(UInt8, B)) - @fact eltype(Bf) --> Gray{N0f8} "test luvkCN" - @fact colorspace(Bf) --> "Gray" "test JwE99B" - @fact colordim(Bf) --> 0 "test DNzikz" - Bf = grayim(B) - @fact eltype(Bf) --> Gray{N0f16} "test CPd4Fa" - # colorspace encoded as a Color (enables multiple dispatch) - BfCV = reinterpret(Gray{N0f8}, round(UInt8, B)) - @fact colorspace(BfCV) --> "Gray" "test Tp3xdg" - @fact colordim(BfCV) --> 0 "test aALUCW" - Bf3 = grayim(reshape(collect(convert(UInt8,1):convert(UInt8,36)), 3,4,3)) - @fact eltype(Bf3) --> Gray{N0f8} "test k8hBgR" - Bf3 = grayim(reshape(collect(convert(UInt16,1):convert(UInt16,36)), 3,4,3)) - @fact eltype(Bf3) --> Gray{N0f16} "test KASRod" - Bf3 = grayim(reshape(collect(1.0f0:36.0f0), 3,4,3)) - @fact eltype(Bf3) --> Gray{Float32} "test Vr9iDW" - end - end - - context("Colorim") do - C = colorim(rand(UInt8, 3, 5, 5)) - @fact eltype(C) --> RGB{N0f8} "test N0iGXo" - @fact colordim(C) --> 0 "test 6COaeI" - @fact colorim(C) --> C "test hPgSHp" - C = colorim(rand(UInt16, 4, 5, 5), "ARGB") - @fact eltype(C) --> ARGB{N0f16} "test PZ5Ld5" - C = colorim(rand(UInt8(1):UInt8(20), 3, 5, 5)) - @fact eltype(C) --> RGB{N0f8} "test MyDpnz" - @fact colordim(C) --> 0 "test vu1pXs" - @fact colorspace(C) --> "RGB" "test moBy0x" - @fact eltype(colorim(rand(UInt16, 3, 5, 5))) --> RGB{N0f16} "test pzSy1a" - @fact eltype(colorim(rand(3, 5, 5))) --> RGB{Float64} "test F3ex39" - @fact colordim(colorim(rand(UInt8, 5, 5, 3))) --> 0 "test kElkKH" - @fact spatialorder(colorim(rand(UInt8, 3, 5, 5))) --> (:y, :x) "test auwSni" - @fact spatialorder(colorim(rand(UInt8, 5, 5, 3))) --> (:y, :x) "test g307S1" - @fact eltype(colorim(rand(UInt8, 4, 5, 5), "RGBA")) --> RGBA{N0f8} "test RcSRnh" - @fact eltype(colorim(rand(UInt8, 4, 5, 5), "ARGB")) --> ARGB{N0f8} "test 9hscsz" - @fact colordim(colorim(rand(UInt8, 5, 5, 4), "RGBA")) --> 0 "test SJTuxu" - @fact colordim(colorim(rand(UInt8, 5, 5, 4), "ARGB")) --> 0 "test lIpIVN" - @fact spatialorder(colorim(rand(UInt8, 5, 5, 4), "ARGB")) --> (:y, :x) "test y0Vpv4" - @fact_throws ErrorException colorim(rand(UInt8, 3, 5, 3)) "test zCDA2C" - @fact_throws ErrorException colorim(rand(UInt8, 4, 5, 5)) "test evgCjW" - @fact_throws ErrorException colorim(rand(UInt8, 5, 5, 4)) "test ByYXn6" - @fact_throws ErrorException colorim(rand(UInt8, 4, 5, 4), "ARGB") "test E8cclV" - @fact_throws ErrorException colorim(rand(UInt8, 5, 5, 5), "foo") "test JHb2sd" - @fact_throws ErrorException colorim(rand(UInt8, 2, 2, 2), "bar") "test eVybiQ" - end - - context("Indexed color") do - let cmap = linspace(RGB(0x0cuf8, 0x00uf8, 0x00uf8), RGB(0xffuf8, 0x00uf8, 0x00uf8), 20) - img_ = ImageCmap(copy(B), cmap) - @fact colorspace(img_) --> "RGB" "test ekvCpM" - img_ = ImageCmap(copy(B), cmap) - @fact colorspace(img_) --> "RGB" "test F3LOhS" - # Note: img from opening of facts() block - # TODO: refactor whole block - @fact eltype(img) --> RGB{N0f8} "test 8aSK8W" - @fact eltype(imgd) --> RGB{N0f8} "test IhyuSH" - end - end - - - context("Basic information") do - @fact size(img) --> (3,5) "test SVoECb" - @fact size(imgd) --> (3,5) "test GEziWW" - @fact ndims(img) --> 2 "test uD5ST6" - @fact ndims(imgd) --> 2 "test Gfuga9" - @fact size(img,"y") --> 3 "test 6tVTzS" - @fact size(img,"x") --> 5 "test WYg5qs" - @fact strides(img) --> (1,3) "test lH4UyT" - @fact strides(imgd) --> (1,3) "test Rvvapy" - @fact strides(imgds) --> (1,3,15) "test dYffuB" - @fact nimages(img) --> 1 "test jE9DjL" - @fact ncolorelem(img) --> 1 "test W1Jzs4" - @fact ncolorelem(imgd) --> 1 "test 76okNe" - @fact ncolorelem(imgds) --> 1 "test xtbHDi" - vimg = vec(img) - @fact haskey(vimg, "spatialorder") --> false "test Jvo4UH" - @fact haskey(vimg, "pixelspacing") --> false "test D37jeN" - vimgds = vec(imgds) - @fact haskey(vimg, "colordim") --> false "test nYSqMQ" - @fact haskey(vimg, "colorspace") --> false "test OLYptD" - @fact sort(vimgds)[1] --> minimum(imgds) "test gTnGfY" - end - - context("1-dimensional images") do - @fact colordim(1:5) --> 0 "test ZzuntI" - @fact nimages(1:5) --> 1 "test qATU2x" - @fact colorspace(1:5) --> "Gray" "test urhFyz" - img1 = AxisArray(map(Gray, 0.1:0.1:0.5), :z) - @fact colordim(img1) --> 0 "test w9LJFP" - @fact colorspace(img1) --> "Gray" "test bTdx4f" - @fact sdims(img1) --> 1 "test fImXGd" - @fact convert(Vector{Gray{Float64}}, img1) --> map(Gray, 0.1:0.1:0.5) "test sx0MrI" - @fact size(img1, "z") --> 5 "test UVd1Qc" - @fact_throws ErrorException size(img1, "x") "test w99nLd" - end - - context("Printing") do - iob = IOBuffer() - show(iob, img) - show(iob, imgd) - end - - context("Copy / similar") do - A = randn(3,5,3) - imgc = @inferred(copy(img)) - @fact imgc.data --> img.data "test bmmvpl" - imgc = copyproperties(imgd, A) - @fact imgc --> A "test FtSoza" - img2 = @inferred(similar(img)) - @fact isa(img2, AxisArray) --> true "test ZQlGw2" - @fact (img2.data == img.data) --> false "test Fis1BF" - img2 = @inferred(similar(imgd)) - @fact isa(img2, typeof(imgd)) --> true "test kWPhBO" - img2 = similar(img, (4,4)) - @fact size(img2) --> (4,4) "test XM2fWe" - img2 = similar(imgd, (3,4,4)) - @fact size(img2) --> (3,4,4) "test CDWvHz" - @fact copyproperties(B, A) --> A "test JQUH5M" - @fact shareproperties(A, B) --> B "test xfed58" - @fact shareproperties(img, B) --> B "test gvgFZu" - end - - context("Properties") do - @fact colorspace(img) --> "RGB" "test r4GQh5" - @fact colordim(img) --> 0 "test P9R46B" - @fact colordim(imgds) --> 3 "test 7Cmhyv" - @fact timedim(img) --> 0 "test UxEzff" - @fact pixelspacing(img) --> (2, 3) "test xxx4JY" - @fact spacedirections(img) --> ((2, 0), (0, 3)) "test BMHiEE" - if testing_units - @fact pixelspacing(imgd) --> (2mm, 3mm) "test Io4D8M" - @fact spacedirections(imgd) --> ((2mm, 0mm), (0mm, 3mm)) "test 1yJxFQ" - end - end - - context("Dims and ordering") do - @fact sdims(img) --> sdims(imgd) "test qbjpWy" - @fact coords_spatial(img) --> coords_spatial(imgd) "test UBaUrc" - @fact size_spatial(img) --> size_spatial(imgd) "test Z6fpfp" - A = randn(3,5,3) - - @fact storageorder(img) --> (Symbol.(Images.yx)...,) "test FbZZeV" - @fact storageorder(imgds) --> (Symbol.(Images.yx)..., :color) "test PthQLh" - end - - context("Sub / slice") do - s = view(img, 2:2, 1:4) - @fact ndims(s) --> 2 "test zKaJui" - @fact sdims(s) --> 2 "test UZP9Ss" - @fact size(s) --> (1,4) "test Fj3Elk" - @fact data(s) --> cmap[view(B, 2:2, 1:4)] "test MEE0Kf" - if scalar_getindex_new - s = getindexim(img, 2, 1:4) - @fact ndims(s) --> 1 "test oUbfko" - @fact sdims(s) --> 1 "test gGEDEE" - @fact size(s) --> (4,) "test iiUIN1" - @fact data(s) --> cmap[B[2, 1:4]] "test J3Eh9N" - s = getindexim(img, 2:2, 1:4) - @fact ndims(s) --> 2 "test TqlvGx" - @fact sdims(s) --> 2 "test m1UOXa" - @fact size(s) --> (1,4) "test Y28Rxj" - @fact data(s) --> cmap[B[2:2, 1:4]] "test w2w6dq" - else - s = getindexim(img, 2, 1:4) - @fact ndims(s) --> 2 "test HucgqQ" - @fact sdims(s) --> 2 "test OPRJZ2" - @fact size(s) --> (1,4) "test rKuBuM" - @fact data(s) --> B[2, 1:4] "test CBcZSh" - end - s = subim(img, 2, 1:4) - @fact ndims(s) --> 2 "test u6Ga7f" - @fact sdims(s) --> 2 "test RDsYNq" - @fact size(s) --> (1,4) "test L390gv" - s = subim(img, 2, [1,2,4]) - @fact ndims(s) --> 2 "test qvMWQI" - @fact sdims(s) --> 2 "test sEei68" - @fact size(s) --> (1,3) "test pRQ45S" - s = sliceim(img, 2, 1:4) - @fact ndims(s) --> 1 "test fAmwu6" - @fact sdims(s) --> 1 "test hfxc7J" - @fact size(s) --> (4,) "test 6xHsFS" - s = sliceim(img, 2, [1,2,4]) - @fact ndims(s) --> 1 "test td0QjR" - @fact sdims(s) --> 1 "test akcJpS" - @fact size(s) --> (3,) "test AUktx0" - s = sliceim(imgds, 2, 1:4, 1:3) - @fact ndims(s) --> 2 "test 2tJFtL" - @fact sdims(s) --> 1 "test SYKGkr" - @fact colordim(s) --> 2 "test lPN4QA" - @fact spatialorder(s) --> (:x,) "test 2OoCHQ" - s = sliceim(imgds, 2, :, 1:3) - @fact ndims(s) --> 2 "test rfr9cD" - @fact sdims(s) --> 1 "test IH9aUL" - @fact colordim(s) --> 2 "test wamZwZ" - @fact spatialorder(s) --> (:x,) "test 6gJq01" - s = sliceim(imgds, 2:2, 1:4, 1:3) - @fact ndims(s) --> 3 "test Kxj25e" - @fact sdims(s) --> 2 "test L1qDs3" - @fact colordim(s) --> 3 "test BGZevb" - @fact colorspace(s) --> "Gray" "test N0f8NVOG" - s = getindexim(imgds, 2:2, 1:4, 2) - @fact ndims(s) --> 2 "test nKN91R" - @fact sdims(s) --> 2 "test SFKKhD" - @fact colordim(s) --> 0 "test pu5AHT" - @fact colorspace(s) --> "Gray" "test YUBU3N" - s = sliceim(imgds, 2:2, 1:4, 2) - @fact ndims(s) --> 2 "test 9jeHx1" - @fact sdims(s) --> 2 "test uDCJHl" - @fact colordim(s) --> 0 "test 30wLdG" - @fact colorspace(s) --> "Gray" "test KTknYZ" - s = sliceim(imgds, 2:2, 1:4, 1:2) - @fact ndims(s) --> 3 "test LxgrvE" - @fact sdims(s) --> 2 "test Wbsn5j" - @fact colordim(s) --> 3 "test 0R4CXY" - @fact colorspace(s) --> "Gray" "test 3o1uhP" - @fact spatialorder(s) --> (:y,:x) "test 9NoVQt" - s = view(img, "y", 2:2) - @fact ndims(s) --> 2 - @fact sdims(s) --> 2 - @fact size(s) --> (1,5) - s = view(img, "y", 2) - @fact ndims(s) --> 1 - @fact size(s) --> (5,) - @fact size(getindexim(imgds, :, 1:2, :)) --> (size(imgds,1), 2, 3) "test Rfvge1" - - s = permutedims(imgds, (3,1,2)) - @fact colordim(s) --> 1 "test 8Jv9n7" - ss = getindexim(s, 2:2, :, :) - @fact colorspace(ss) --> "Gray" "test BEPoQi" - @fact colordim(ss) --> 1 "test hlloiv" - sss = squeeze(ss, 1) - @fact colorspace(ss) --> "Gray" "test 6NNgi9" - @fact colordim(sss) --> 0 "test pwQRnh" - ss = getindexim(imgds, 2:2, :, :) - @fact colordim(ss) --> 3 "test jx31ut" - @fact spatialorder(ss) --> (:y, :x) "test u11jIc" - sss = squeeze(ss, 1) - @fact colordim(sss) --> 2 "test 4X0Hjv" - @fact spatialorder(sss) --> (:x,) "test d5hRJs" - end - - context("Named indexing") do - @fact dimindex(imgds, "color") --> 3 "test EINbuA" - @fact dimindex(imgds, "y") --> 1 "test F4E3tQ" - @fact dimindex(imgds, "z") --> 0 "test 6u1u4T" - imgdp = permutedims(imgds, [3,1,2]) - @fact dimindex(imgdp, "y") --> 2 "test U3pebL" - @fact img["y", 2, "x", 4] --> imgi[2,4] "test oJ519u" - @fact img["x", 4, "y", 2] --> imgi[2,4] "test oCsNbf" - chan = imgds["color", 2] - Blookup = reshape(green(cmap[B[:]]), size(B)) - @fact chan --> Blookup "test 2cKtWB" - end - - context("Spatial order, width/ height, and permutations") do - @fact widthheight(imgds) --> (5,3) "test tgY2FG" - imgp = permutedims(imgds, ["x", "y", "color"]) - @fact imgp.data --> permutedims(imgds.data, [2,1,3]) "test MobXxa" - imgp = permutedims(imgds, ("color", "x", "y")) - @fact imgp.data --> permutedims(imgds.data, [3,2,1]) "test 1XMuxB" - if testing_units - @fact pixelspacing(imgp) --> (3mm, 2mm) "test 2XyBNB" - end - imgc = ImageMeta(copy(imgds)) - imgc["spacedirections"] = spacedirections(imgc) - imgp = permutedims(imgc, ["x", "y", "color"]) - if testing_units - @fact spacedirections(imgp) --> ((0mm, 3mm),(2mm, 0mm)) "test NUTHJC" - @fact pixelspacing(imgp) --> (3mm, 2mm) "test 5RGPJ0" - end - end - - context("Reinterpret, separate, more convert") do - a = RGB{Float64}[RGB(1,1,0)] - af = reinterpret(Float64, a) - @fact vec(af) --> [1.0,1.0,0.0] "test M3uyLv" - anew = reinterpret(RGB, af) - @fact anew --> a "test ekkFD4" - anew = reinterpret(RGB, vec(af)) - @fact anew[1] --> a[1] "test FLyINs" - anew = reinterpret(RGB{Float64}, af) - @fact anew --> a "test VU6f3n" - Au8 = rand(0x00:0xff, 3, 5, 4) - A8 = reinterpret(N0f8, Au8) - rawrgb8 = reinterpret(RGB, A8) - @fact eltype(rawrgb8) --> RGB{N0f8} "test U5YnpG" - @fact reinterpret(N0f8, rawrgb8) --> A8 "test VIsSBT" - @fact reinterpret(UInt8, rawrgb8) --> Au8 "test cWVSZ5" - rawrgb32 = convert(Array{RGB{Float32}}, rawrgb8) - @fact eltype(rawrgb32) --> RGB{Float32} "test BPX0oN" - @fact ufixed8(rawrgb32) --> rawrgb8 "test 10hrUB" - @fact reinterpret(N0f8, rawrgb8) --> A8 "test xz6V7Y" - imrgb8 = convert(Image, rawrgb8) - @fact spatialorder(imrgb8) --> (Symbol.(Images.yx)...,) "test up03c2" - @fact convert(Image, imrgb8) --> exactly(imrgb8) "test CaRwd8" - @fact convert(Image{RGB{N0f8}}, imrgb8) --> exactly(imrgb8) "test 39AZU3" - im8 = reinterpret(N0f8, imrgb8) - @fact data(im8) --> A8 "test lZSAH9" - @fact permutedims(normedview(N0f8, separate(imrgb8)), (3, 1, 2)) --> im8 "test zDOWZM" - @fact reinterpret(UInt8, imrgb8) --> Au8 "test HeezpR" - @fact reinterpret(RGB, im8) --> imrgb8 "test VJUpj3" - ims8 = separate(imrgb8) - @fact colordim(ims8) --> 0 "test nGifan" - @fact colorspace(ims8) --> "Gray" "test R0VFeL" - @fact convert(Image, ims8) --> exactly(ims8) "test EGoCYN" - @fact convert(Image{N0f8}, ims8) --> exactly(ims8) "test Qly190" - @fact separate(ims8) --> exactly(ims8) "test hAxqus" - A = reinterpret(N0f8, UInt8[1 2; 3 4]) - imgray = convert(Image{Gray{N0f8}}, A) - @fact spatialorder(imgray) --> (Symbol.(Images.yx)...,) "test gLMUOh" - @fact data(imgray) --> reinterpret(Gray{N0f8}, [0x01 0x02; 0x03 0x04]) "test UC9NtZ" - @fact eltype(convert(Image{HSV{Float32}}, imrgb8)) --> HSV{Float32} "test cwCaVn" - @fact eltype(convert(Image{HSV}, float32(imrgb8))) --> HSV{Float32} "test VB4EU3" - - @fact eltype(convert(Array{Gray}, imrgb8)) --> Gray{N0f8} "test 4UOxZh" - @fact eltype(convert(Image{Gray}, imrgb8)) --> Gray{N0f8} "test 2hhcQd" - @fact eltype(convert(Array{Gray}, data(imrgb8))) --> Gray{N0f8} "test SdEY95" - @fact eltype(convert(Image{Gray}, data(imrgb8))) --> Gray{N0f8} "test lzipLL" - # Issue 232 - let img = Image(reinterpret(Gray{N0f16}, rand(UInt16, 5, 5))) - imgs = subim(img, :, :) - @fact isa(minfinite(imgs), Gray{N0f16}) --> true "test PlxHep" - # Raw - imgdata = rand(UInt16, 5, 5) - img = Image(reinterpret(Gray{N0f16}, imgdata)) - @fact all(raw(img) .== imgdata) --> true "test EvOATF" - @fact typeof(raw(img).data) --> Array{UInt16,2} "test YlySCh" - @fact typeof(raw(Image(rawrgb8)).data) --> Array{UInt8,3} "test uOxsmv" # check color images - @fact size(raw(Image(rawrgb8))) --> (3,5,4) "test bM2K4C" - @fact typeof(raw(imgdata)) --> typeof(imgdata) "test 1Bf874" # check array fallback - @fact all(raw(imgdata) .== imgdata) --> true "test LJLDPq" - end - end -end diff --git a/test/old/corner.jl b/test/old/corner.jl deleted file mode 100644 index 5671c472..00000000 --- a/test/old/corner.jl +++ /dev/null @@ -1,188 +0,0 @@ -using FactCheck, Base.Test, Images, Colors, FixedPointNumbers - -facts("Corner") do - A = zeros(41,41) - A[16:26,16:26] = 1 - - context("Corners API") do - img = zeros(20, 20) - img[4:17, 4:17] = 1 - img[8:13, 8:13] = 0 - - expected_corners = zeros(20, 20) - ids = map(CartesianIndex{2}, [(4, 4), (4, 17), (17, 4), (17, 17), (8, 8), (8, 13), (13, 8), (13, 13)]) - for id in ids expected_corners[id] = 1 end - corners = imcorner(img, method = harris) - for id in ids @fact corners[id] --> true end - @fact sum(corners .!= expected_corners) < 3 --> true - corners = imcorner(img, method = shi_tomasi) - for id in ids @fact corners[id] --> true end - @fact sum(corners .!= expected_corners) < 3 --> true - - ids = map(CartesianIndex{2}, [(4, 4), (4, 17), (17, 4), (17, 17)]) - corners = imcorner(img, method = kitchen_rosenfeld) - for id in ids @fact corners[id] --> true end - ids = map(CartesianIndex{2}, [(8, 8), (8, 13), (13, 8), (13, 13)]) - for id in ids expected_corners[id] = 0 end - @fact sum(corners .!= expected_corners) < 3 --> true - end - - context("Harris") do - Ac = imcorner(A, 0.99, true, method = harris) - # check corners - @fact Ac[16,16] --> true - @fact Ac[16,26] --> true - @fact Ac[26,16] --> true - @fact Ac[26,26] --> true - - @fact all(Ac[1:14, :]) --> false - @fact all(Ac[:, 1:14]) --> false - @fact all(Ac[28:end, :]) --> false - @fact all(Ac[:, 28:end]) --> false - @fact all(Ac[18:24, 18:24]) --> false - - Ac = harris(A) - - @fact Ac[16,16] --> roughly(maximum(Ac)) - @fact Ac[16,26] --> roughly(Ac[16,16]) - @fact Ac[26,16] --> roughly(Ac[16,16]) - @fact Ac[26,26] --> roughly(Ac[16,16]) - - # check edge intensity - @fact Ac[16,21] --> roughly(minimum(Ac)) - @fact Ac[21,16] --> roughly(Ac[16,21]) - @fact Ac[21,26] --> roughly(Ac[16,21]) - @fact Ac[26,21] --> roughly(Ac[16,21]) - - # check background intensity - @fact Ac[5,5] --> roughly(0) - @fact Ac[5,36] --> roughly(0) - @fact Ac[36,5] --> roughly(0) - @fact Ac[36,36] --> roughly(0) - - end - - context("Shi-Tomasi") do - Ac = imcorner(A, 0.99, true, method = shi_tomasi) - # check corners - @fact Ac[16,16] --> true - @fact Ac[16,26] --> true - @fact Ac[26,16] --> true - @fact Ac[26,26] --> true - - @fact all(Ac[1:14, :]) --> false - @fact all(Ac[:, 1:14]) --> false - @fact all(Ac[28:end, :]) --> false - @fact all(Ac[:, 28:end]) --> false - @fact all(Ac[18:24, 18:24]) --> false - - Ac = shi_tomasi(A) - # check corner intensity - @fact Ac[16,16] --> roughly(maximum(Ac)) - @fact Ac[16,26] --> roughly(Ac[16,16]) - @fact Ac[26,16] --> roughly(Ac[16,16]) - @fact Ac[26,26] --> roughly(Ac[16,16]) - - # check edge intensity - @fact Ac[16,21] --> roughly(0) - @fact Ac[21,16] --> roughly(0) - @fact Ac[21,26] --> roughly(0) - @fact Ac[26,21] --> roughly(0) - - # check background intensity - @fact Ac[5,5] --> roughly(0) - @fact Ac[5,36] --> roughly(0) - @fact Ac[36,5] --> roughly(0) - @fact Ac[36,36] --> roughly(0) - - end - - context("Kitchen-Rosenfeld") do - A[10:30, 10:30] = 1 - A[15:25, 15:25] = 0 - Ac = imcorner(A, 0.99, true, method = kitchen_rosenfeld) - @fact Ac[10, 10] --> true - @fact Ac[10, 30] --> true - @fact Ac[30, 10] --> true - @fact Ac[30, 30] --> true - - @fact all(Ac[1:9, :]) --> false - @fact all(Ac[:, 1:9]) --> false - @fact all(Ac[31:end, :]) --> false - @fact all(Ac[:, 31:end]) --> false - @fact all(Ac[12:28, 12:28]) --> false - end - - context("Fast Corners") do - - img = reshape(1:1:49, 7, 7) - - for i in 1:8 - corners = fastcorners(img, i) - @fact all(corners) --> true - end - - corners = fastcorners(img, 9) - @fact all(corners[4, 1:end - 1]) --> false - corners[4, 1:end - 1] = true - @fact all(corners) --> true - - corners = fastcorners(img, 10) - @fact all(corners[3:4, 1:end - 2]) --> false - @fact corners[4, end - 1] --> false - corners[3:4, 1:end - 2] = true - corners[4, end - 1] = true - @fact all(corners) --> true - - corners = fastcorners(img, 11) - @fact all(corners[2:5, 1:end - 3]) --> false - @fact all(corners[3:5, end - 2]) --> false - @fact corners[4, end - 1] --> false - corners[2:5, 1:end - 3] = true - corners[3:5, 1:end - 2] = true - corners[4, end - 1] = true - @fact all(corners) --> true - - corners = fastcorners(img, 12) - @fact all(corners[1:6, 1:end - 3]) --> false - @fact all(corners[3:5, end - 2]) --> false - @fact corners[4, end - 1] --> false - corners[1:6, 1:end - 3] = true - corners[3:5, 1:end - 2] = true - corners[4, end - 1] = true - @fact all(corners) --> true - - img = parent(gaussian2d(1.4)) - img = vcat(img, img) - img = hcat(img, img) - corners = fastcorners(img, 12, 0.05) - - @fact corners[5, 5] --> true - @fact corners[5, 14] --> true - @fact corners[14, 5] --> true - @fact corners[14, 14] --> true - - @fact all(corners[:, 1:3] .== false) --> true - @fact all(corners[1:3, :] .== false) --> true - @fact all(corners[:, 16:end] .== false) --> true - @fact all(corners[16:end, :] .== false) --> true - @fact all(corners[6:12, 6:12] .== false) --> true - - img = 1 - img - - corners = fastcorners(img, 12, 0.05) - - @fact corners[5, 5] --> true - @fact corners[5, 14] --> true - @fact corners[14, 5] --> true - @fact corners[14, 14] --> true - - @fact all(corners[:, 1:3] .== false) --> true - @fact all(corners[1:3, :] .== false) --> true - @fact all(corners[:, 16:end] .== false) --> true - @fact all(corners[16:end, :] .== false) --> true - @fact all(corners[6:12, 6:12] .== false) --> true - - end - -end diff --git a/test/old/edge.jl b/test/old/edge.jl deleted file mode 100644 index 6269ccf3..00000000 --- a/test/old/edge.jl +++ /dev/null @@ -1,405 +0,0 @@ -using Images, FactCheck, Base.Test, Colors, Compat - -global checkboard - -if VERSION < v"0.5.0" - # Overwrite `Base.all` to work around poor inference on 0.4 - function all(ary) - Base.all(convert(Array{Bool}, ary)) - end -end - -facts("Edge") do - - EPS = 1e-14 - - ## Checkerboard array, used to test image gradients - white{T}(::Type{T}) = one(T) - black{T}(::Type{T}) = zero(T) - white{T<:Unsigned}(::Type{T}) = typemax(T) - black{T<:Unsigned}(::Type{T}) = typemin(T) - - function checkerboard{T}(::Type{T}, sq_width::Integer, count::Integer) - wh = fill(white(T), (sq_width,sq_width)) - bk = fill(black(T), (sq_width,sq_width)) - bw = [wh bk; bk wh] - vert = repmat(bw, (count>>1), 1) - isodd(count) && (vert = vcat(vert, [wh bk])) - cb = repmat(vert, 1, (count>>1)) - isodd(count) && (cb = hcat(cb, vert[:,1:sq_width])) - cb - end - - checkerboard(sq_width::Integer, count::Integer) = checkerboard(UInt8, sq_width, count) - - #Canny Edge Detection - context("Canny Edge Detection") do - #General Checks - img = zeros(10, 10) - edges = canny(img) - @fact all(edges .== 0.0) --> true "test XPvVle" - - #Box Edges - - img[2:end-1, 2:end-1] = 1 - edges = canny(img) - @fact all(edges[2:end-1, 2] .== 1.0) --> true "test XaR3zT" - @fact all(edges[2:end-1, end-1] .== 1.0) --> true "test hYEggy" - @fact all(edges[2, 2:end-1] .== 1.0) --> true "test SGpiuC" - @fact all(edges[end-1, 2:end-1] .== 1.0) --> true "test O1jzIi" - @fact all(edges[3:end-2, 3:end-2] .== 0.0) --> true "test mnlN9g" - - edges = canny(img, 1.4, 0.9/8, 0.2/8, percentile = false) - @fact all(edges[2:end-1, 2] .== 1.0) --> true "test 8vqfWg" - @fact all(edges[2:end-1, end-1] .== 1.0) --> true "test shxyUG" - @fact all(edges[2, 2:end-1] .== 1.0) --> true "test HcRl6t" - @fact all(edges[end-1, 2:end-1] .== 1.0) --> true "test gdzLcr" - @fact all(edges[3:end-2, 3:end-2] .== 0.0) --> true "test U3xnBr" - - #Checkerboard - Corners are not detected as Edges! - img = checkerboard(Gray, 5, 3) - edges = canny(img, 1.4, 0.8, 0.2) - id = [1,2,3,4,6,7,8,9,10,12,13,14,15] - @fact all(edges[id, id] .== zero(Gray)) --> true "test iXLmrb" - id = [5, 11] - id2 = [1,2,3,4,7,8,9,12,13,14,15] - id3 = [5,6,10,11] - @fact all(edges[id, id2] .== one(Gray)) --> true "test sdlPvR" - @fact all(edges[id2, id] .== one(Gray)) --> true "test sMVseP" - @fact all(edges[id, id3] .== zero(Gray)) --> true "test jDMJux" - @fact all(edges[id3, id] .== zero(Gray)) --> true "test sAPU9M" - - #Diagonal Edge - img = zeros(10,10) - img[diagind(img)] = 1 - img[diagind(img, 1)] = 1 - img[diagind(img, -1)] = 1 - edges = canny(img) - @fact all(edges[diagind(edges, 2)] .== 1.0) --> true "test ZnFAXW" - @fact all(edges[diagind(edges, -2)] .== 1.0) --> true "test S0bdlI" - nondiags = setdiff(1:1:100, union(diagind(edges, 2), diagind(edges, -2))) - @fact all(edges[nondiags] .== 0.0) --> true "test WDQfYZ" - - #Checks Hysteresis Thresholding - img = ones(Gray{N0f8}, (10, 10)) - img[3:7, 3:7] = 0.0 - img[4:6, 4:6] = 0.7 - thresholded = Images.hysteresis_thresholding(img, 0.9, 0.8) - @fact all(thresholded[3:7, 3:7] .== 0.0) --> true "test 3XLFf1" - @fact all(thresholded[1:2, :] .== 0.9) --> true "test x3Gdlv" - @fact all(thresholded[:, 1:2] .== 0.9) --> true "test 15gDt3" - @fact all(thresholded[8:10, :] .== 0.9) --> true "test YlZ9mL" - @fact all(thresholded[:, 8:10] .== 0.9) --> true "test a8kckT" - - thresholded = Images.hysteresis_thresholding(img, 0.9, 0.6) - @fact all(thresholded[4:6, 4:6] .== 0.5) --> true "test mvXBYG" - @fact all(thresholded[3:7, 3:7] .< 0.9) --> true "test C424vj" - @fact all(thresholded[1:2, :] .== 0.9) --> true "test Ll7Ks2" - @fact all(thresholded[:, 1:2] .== 0.9) --> true "test DL17A5" - @fact all(thresholded[8:10, :] .== 0.9) --> true "test p6iPF2" - @fact all(thresholded[:, 8:10] .== 0.9) --> true "test U1rPYX" - - img[3, 5] = 0.7 - thresholded = Images.hysteresis_thresholding(img, 0.9, 0.6) - @fact all(thresholded[4:6, 4:6] .== 0.9) --> true "test sAo0s9" - @fact all(thresholded[3:7, 3] .== 0.0) --> true "test FL5swa" - @fact all(thresholded[3:7, 7] .== 0.0) --> true "test H1IfJw" - @fact all(thresholded[7, 3:7] .== 0.0) --> true "test SC1yNK" - @fact all(vec(thresholded[3, 3:7]) .== [0.0, 0.0, 0.9, 0.0, 0.0]) --> true "test 0YsjuY" - @fact all(thresholded[1:2, :] .== 0.9) --> true "test 9nWiWC" - @fact all(thresholded[:, 1:2] .== 0.9) --> true "test VhcOoO" - @fact all(thresholded[8:10, :] .== 0.9) --> true "test qjmIqQ" - @fact all(thresholded[:, 8:10] .== 0.9) --> true "test MWZ3sx" - end - - SZ=5 - cb_array = checkerboard(SZ,3) - - cb_gray = grayim(cb_array) - cb_rgb = convert(Array{RGB}, cb_gray) - cb_rgbf64 = convert(Array{RGB{Float64}}, cb_gray) - - # TODO: now that all of these behave nearly the same, put in a - # loop over the array type (only have to adjust tests for `red`) - @compat context("Checkerboard") do - for method in ["sobel", "prewitt", "ando3", "ando4", "ando5"] - ## Checkerboard array - - (agy, agx) = imgradients(cb_array, method) - amag = magnitude(agx, agy) - agphase = phase(agx, agy) - @fact (amag, agphase) --> magnitude_phase(agx, agy) "test 80oF4m" - - @fact agx[1,SZ] --> less_than(0.0) "test 4N2OkG" # white to black transition - @fact agx[1,2*SZ] --> greater_than(0.0) "test QF4xEq" # black to white transition - @fact agy[SZ,1] --> less_than(0.0) "test Lcw3dQ" # white to black transition - @fact agy[2*SZ,1] --> greater_than(0.0) "test XIhUPC" # black to white transition - - # Test direction of increasing gradient - @fact cos(agphase[1,SZ]) - (-1.0) --> less_than(EPS) "test MDZZJR" # increasing left (= pi radians) - @fact cos(agphase[1,2*SZ]) - 1.0 --> less_than(EPS) "test UI49Lu" # increasing right (= 0 radians) - @fact sin(agphase[SZ,1]) - 1.0 --> less_than(EPS) "test 8L7FiR" # increasing up (= pi/2 radians) - @fact sin(agphase[2*SZ,1]) - (-1.0) --> less_than(EPS) "test o0CIl6" # increasing down (= -pi/2 radians) - - # Test that orientation is perpendicular to gradient - aorient = orientation(agx, agy) - @fact all((cos.(agphase) .* cos.(aorient) .+ - sin.(agphase) .* sin.(aorient) .< EPS) | - ((agphase .== 0.0) & (aorient .== 0.0))) --> true "test zPGMub" - # this part is where both are zero because there is no gradient - - ## Checkerboard with Gray pixels - - (gyg, gxg) = imgradients(cb_gray, method) - magg = magnitude(gxg, gyg) - gphaseg = phase(gxg, gyg) - @fact (magg, gphaseg) --> magnitude_phase(gxg, gyg) "test AM0uph" - - @fact gyg[SZ,1] --> less_than(0.0) "test cQKPsb" # white to black transition - @fact gyg[2*SZ,1] --> greater_than(0.0) "test 5wgkII" # black to white transition - @fact gxg[1,SZ] --> less_than(0.0) "test EeAjQ1" # white to black transition - @fact gxg[1,2*SZ] --> greater_than(0.0) "test dua7cD" # black to white transition - - @fact cos(gphaseg[1,SZ]) - (-1.0) --> less_than(EPS) "test TQ0aJN" # increasing left (= pi radians) - @fact cos(gphaseg[1,2*SZ]) - 1.0 --> less_than(EPS) "test Mf2h17" # increasing right (= 0 radians) - @fact sin(gphaseg[SZ,1]) - 1.0 --> less_than(EPS) "test fKv3Vl" # increasing up (= pi/2 radians) - @fact sin(gphaseg[2*SZ,1]) - (-1.0) --> less_than(EPS) "test CZQeGF" # increasing down (= -pi/2 radians) - - # Test that orientation is perpendicular to gradient - orientg = orientation(gxg, gyg) - @fact all((cos.(gphaseg) .* cos.(orientg) .+ - sin.(gphaseg) .* sin.(orientg) .< EPS) | - ((gphaseg .== 0.0) & (orientg .== 0.0))) --> true "test BsoAOy" - # this part is where both are zero because there is no gradient - - ## Checkerboard with RBG pixels - - (gy_rgb, gx_rgb) = imgradients(cb_rgb, method) - mag_rgb = magnitude(gx_rgb, gy_rgb) - gphase_rgb = phase(gx_rgb, gy_rgb) - @fact (mag_rgb, gphase_rgb) --> magnitude_phase(gx_rgb, gy_rgb) "test YfK3X2" - - @fact red(gy_rgb[SZ,1]) --> less_than(0.0) "test 1WYzkc" # white to black transition - @fact red(gy_rgb[2*SZ,1]) --> greater_than(0.0) "test rZ10Ar" # black to white transition - @fact red(gx_rgb[1,SZ]) --> less_than(0.0) "test aoRWZJ" # white to black transition - @fact red(gx_rgb[1,2*SZ]) --> greater_than(0.0) "test kNDrlj" # black to white transition - - @fact cos(gphase_rgb[1,SZ]) - (-1.0) --> less_than(EPS) "test qcAgh5" # increasing left (= pi radians) - @fact cos(gphase_rgb[1,2*SZ]) - 1.0 --> less_than(EPS) "test Mb9flX" # increasing right (= 0 radians) - @fact sin(gphase_rgb[SZ,1]) - 1.0 --> less_than(EPS) "test Wxzwl1" # increasing up (= pi/2 radians) - @fact sin(gphase_rgb[2*SZ,1]) - (-1.0) --> less_than(EPS) "test iCilcm" # increasing down (= -pi/2 radians) - - # Test that orientation is perpendicular to gradient - orient_rgb = orientation(gx_rgb, gy_rgb) - @fact all((cos.(gphase_rgb) .* cos.(orient_rgb) .+ - sin.(gphase_rgb) .* sin.(orient_rgb) .< EPS) | - ((gphase_rgb .== 0.0) & (orient_rgb .== 0.0))) --> true "test vrd5mw" - # this part is where both are zero because there is no gradient - - ## Checkerboard Image with RBG{Float64} pixels - - (gy_rgb, gx_rgb) = imgradients(cb_rgbf64, method) - mag_rgb = magnitude(gx_rgb, gy_rgb) - gphase_rgb = phase(gx_rgb, gy_rgb) - @fact (mag_rgb, gphase_rgb) --> magnitude_phase(gx_rgb, gy_rgb) "test Z7WRsV" - - @fact red(gy_rgb[SZ,1]) --> less_than(0.0) "test B5N6ez" # white to black transition - @fact red(gy_rgb[2*SZ,1]) --> greater_than(0.0) "test BevGJV" # black to white transition - @fact red(gx_rgb[1,SZ]) --> less_than(0.0) "test l8bc6e" # white to black transition - @fact red(gx_rgb[1,2*SZ]) --> greater_than(0.0) "test eZ6Plt" # black to white transition - - @fact cos(gphase_rgb[1,SZ]) - (-1.0) --> less_than(EPS) "test M3VjU7" # increasing left (= pi radians) - @fact cos(gphase_rgb[1,2*SZ]) - 1.0 --> less_than(EPS) "test AoPGDf" # increasing right (= 0 radians) - @fact sin(gphase_rgb[SZ,1]) - 1.0 --> less_than(EPS) "test ls8xr8" # increasing up (= pi/2 radians) - @fact sin(gphase_rgb[2*SZ,1]) - (-1.0) --> less_than(EPS) "test 49BiFi" # increasing down (= -pi/2 radians) - - # Test that orientation is perpendicular to gradient - orient_rgb = orientation(gx_rgb, gy_rgb) - @fact all((cos.(gphase_rgb) .* cos.(orient_rgb) .+ - sin.(gphase_rgb) .* sin.(orient_rgb) .< EPS) | - ((gphase_rgb .== 0.0) & (orient_rgb .== 0.0))) --> true "test EW5CFV" - # this part is where both are zero because there is no gradient - end - end - - @compat context("Diagonals") do - # Create an image with white along diagonals -2:2 and black elsewhere - m = zeros(UInt8, 20,20) - for i = -2:2; m[diagind(m,i)] = 0xff; end - - for method in ["sobel", "prewitt", "ando3", "ando4", "ando5"] - ## Diagonal array - - (agy, agx) = imgradients(m, method) - amag = magnitude(agx, agy) - agphase = phase(agx, agy) - @fact magnitude_phase(agx, agy) --> (amag, agphase) "test magphase" - - @fact agx[7,9] --> less_than(0.0) "test 3cHL0U" # white to black transition - @fact agx[10,8] --> greater_than(0.0) "test ZnqMYL" # black to white transition - @fact agy[10,8] --> less_than(0.0) "test iIZNpr" # white to black transition - @fact agy[7,9] --> greater_than(0.0) "test olF7SY" # black to white transition - - # Test direction of increasing gradient - @fact abs(agphase[10,8] - pi/4 ) --> less_than(EPS) "test 2to4XR" # lower edge (increasing up-right = pi/4 radians) - @fact abs(agphase[7,9] - (-3pi/4)) --> less_than(EPS) "test 4n7Fd5" # upper edge (increasing down-left = -3pi/4 radians) - - # Test that orientation is perpendicular to gradient - aorient = orientation(agx, agy) - @fact all((cos.(agphase) .* cos.(aorient) .+ - sin.(agphase) .* sin.(aorient) .< EPS) | - ((agphase .== 0.0) & (aorient .== 0.0))) --> true "test cYbfiH" - # this part is where both are zero because there is no gradient - end - end - - # Nonmaximal suppression - - function thin_edges(img) - # Get orientation - gy,gx = imgradients(img) - orient = phase(gx,gy) - - # Do NMS thinning - thin_edges_nonmaxsup_subpix(img, orient, radius=1.35) - end - - function nms_test_horiz_vert(img, which) - ## which = :horizontal or :vertical - - # Do NMS thinning - t,s = thin_edges(img) - - # Calc peak location by hand - - # Interpolate values 1.35 pixels left and right - # Orientation is zero radians -> to the right - v1 = 6 - 0.35 # slope on right is 1 - v2 = 5 - 0.35*2 # slope on left is 2 - c = 7.0 # peak value - - # solve v = a*r^2 + b*r + c - a = (v1 + v2)/2 - c - b = a + c - v2 - r = -b/2a - - @fact abs(r - 1/6) --> less_than(EPS) "test fmHvvQ" - - # Location and value at peak - peakloc = r*1.35 + 3 - peakval = a*r^2 + b*r + c - - transposed = spatialorder(img)[1] == "x" - horizontal = which == :horizontal - - test_axis1 = transposed ⊻ !horizontal - - if test_axis1 - @fact all(t[:,[1,2,4,5]] .== 0) --> true "test 4HIP6f" - @fact all(t[:,3] .== peakval) --> true "test ZITaq0" - @fact all(s[:,[1,2,4,5]] .== zero(Graphics.Point)) --> true "test 0JGsoU" - else - @fact all(t[[1,2,4,5],:] .== 0) --> true "test OZUJOS" - @fact all(t[3,:] .== peakval) --> true "test IEOYk3" - @fact all(s[[1,2,4,5],:] .== zero(Graphics.Point)) --> true "test pnnCRT" - end - - if transposed - if which == :horizontal - @fact [pt.x for pt in s[:,3]] --> [1:5;] "test 7uIThT" - @fact all([pt.y for pt in s[:,3]] .== peakloc) --> true "test OTE4OQ" - else - @fact all([pt.x for pt in s[3,:]] .== peakloc) --> true "test HZSUky" - @fact [pt.y for pt in s[3,:]] --> [1:5;] "test 3PyK02" - end - else - if which == :horizontal - @fact [pt.x for pt in s[3,:]] --> [1:5;] "test oydYR7" - @fact all([pt.y for pt in s[3,:]] .== peakloc) --> true "test pwrLbc" - else - @fact all([pt.x for pt in s[:,3]] .== peakloc) --> true "test 035uAN" - @fact [pt.y for pt in s[:,3]] --> [1:5;] "test A7DGMj" - end - end - end - - context("Nonmax suppression vertical edge") do - # Test image: vertical edge - m = [3.0 5.0 7.0 6.0 5.0 - 3.0 5.0 7.0 6.0 5.0 - 3.0 5.0 7.0 6.0 5.0 - 3.0 5.0 7.0 6.0 5.0 - 3.0 5.0 7.0 6.0 5.0] - - nms_test_horiz_vert(m, :vertical) - end - - context("Nonmax suppression horizontal edge") do - # Test image: horizontal edge - m = [3.0 5.0 7.0 6.0 5.0 - 3.0 5.0 7.0 6.0 5.0 - 3.0 5.0 7.0 6.0 5.0 - 3.0 5.0 7.0 6.0 5.0 - 3.0 5.0 7.0 6.0 5.0] - m = m' - - nms_test_horiz_vert(m, :horizontal) - end - -function nms_test_diagonal(img) - # Do NMS thinning - t,s = thin_edges(img) - - # Calc peak location by hand - - # Interpolate values 1.35 pixels up and left, down and right - # using bilinear interpolation - # Orientation is π/4 radians -> 45 degrees up - fr = 1.35*cos(π/4) - lower = (7 + fr*(6-7)) - upper = (6 + fr*(5-6)) - v1 = lower + fr*(upper-lower) - - lower = (7 + fr*(5-7)) - upper = (5 + fr*(3-5)) - v2 = lower + fr*(upper-lower) - - c = 7.0 # peak value - - # solve v = a*r^2 + b*r + c - a = (v1 + v2)/2 - c - b = a + c - v2 - r = -b/2a - - @fact (r - 1/6) --> less_than(EPS) "test xuJ9PL" - - transposed = false - - # Location and value at peak - - x_peak_offset, y_peak_offset = r*fr, -r*fr - peakval = a*r^2 + b*r + c - - @fact all(diag(data(t))[2:4] .== peakval) --> true "test UpmYpg" # Edge pixels aren't interpolated here - @fact all(t - diagm(diag(data(t))) .== 0) --> true "test sK2s90" - - diag_s = copyproperties(s, diagm(diag(data(s)))) - @fact s --> diag_s "test 4xwjQB" - - @fact all([pt.x for pt in diag(data(s))[2:4]] - ((2:4) + x_peak_offset) .< EPS) --> true "test luz17v" - @fact all([pt.y for pt in diag(data(s))[2:4]] - ((2:4) + y_peak_offset) .< EPS) --> true "test RYzBTz" - -end - - context("Nonmax suppression diagonal") do - # Test image: diagonal edge - m = [7.0 6.0 5.0 0.0 0.0 - 5.0 7.0 6.0 5.0 0.0 - 3.0 5.0 7.0 6.0 5.0 - 0.0 3.0 5.0 7.0 6.0 - 0.0 0.0 3.0 5.0 7.0] - - nms_test_diagonal(m) - end - -end diff --git a/test/old/exposure.jl b/test/old/exposure.jl deleted file mode 100644 index 46a8ff9f..00000000 --- a/test/old/exposure.jl +++ /dev/null @@ -1,274 +0,0 @@ -using FactCheck, Base.Test, Images, Colors, FixedPointNumbers - -facts("Exposure") do - - context("Histogram") do - - # Many of these test integer values, but of course most images - # should have pixel values between 0 and 1. Still, it doesn't - # hurt to get the integer case right too. - img = 1:10 - bins, hist = imhist(img, 10) - @fact length(hist) --> length(bins)+1 - @fact bins --> 1.0:1.0:11.0 - @fact hist --> [0,1, 1, 1, 1, 1, 1, 1, 1, 1, 1,0] - bins, hist = imhist(img, 5, 2, 6) - @fact length(hist) --> length(bins)+1 - @fact bins --> 2.0:1.0:7.0 - @fact hist --> [1, 1, 1, 1, 1, 1, 4] - - img = reshape(0:99, 10, 10) - bins, hist = imhist(img, 10) - @fact length(hist) --> length(bins)+1 - @fact bins --> 0.0:10.0:100.0 - @fact hist --> [0, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 0] - bins, hist = imhist(img, 7, 25, 59) - @fact length(hist) --> length(bins)+1 - @fact bins --> 25.0:5.0:60.0 - @fact hist --> [25, 5, 5, 5, 5, 5, 5, 5, 40] - - # Test the more typical case - img = reinterpret(Gray{N0f8}, [0x20,0x40,0x80,0xd0]) - @fact imhist(img, 5) --> (0.0:0.2:1.0,[0,1,1,1,0,1,0]) - img = reinterpret(Gray{N0f8}, [0x00,0x40,0x80,0xd0]) - @fact imhist(img, 5) --> (0.0:0.2:1.0,[0,1,1,1,0,1,0]) - img = reinterpret(Gray{N0f8}, [0x00,0x40,0x80,0xff]) - @fact imhist(img, 6) --> (0.0:0.2:1.2,[0,1,1,1,0,0,1,0]) - - end - - context("Histogram Equalisation") do - - #DataTypes - img = ones(Images.Gray{Float64}, 10, 10) - ret = histeq(img, 100) - @fact img == ret --> true - @fact eltype(ret) == eltype(img) --> true - - img = ones(Images.Gray{Images.N0f8}, 10, 10) - ret = histeq(img, 100) - @fact img == ret --> true - @fact eltype(ret) == eltype(img) --> true - - img = ones(Images.Gray{Images.N0f16}, 10, 10) - ret = histeq(img, 100) - @fact eltype(ret) == eltype(img) --> true - - img = ones(Images.AGray{Images.N0f8}, 10, 10) - ret = histeq(img, 100) - @fact img == ret --> true - @fact eltype(ret) == eltype(img) --> true - - img = ones(Images.RGB{Images.N0f8}, 10, 10) - ret = histeq(img, 100) - @fact img == ret --> true - @fact eltype(ret) == eltype(img) --> true - - img = ones(Images.RGB{Images.N0f16}, 10, 10) - ret = histeq(img, 100) - @fact img == ret --> true - @fact eltype(ret) == eltype(img) --> true - - img = ones(Images.RGB{Float64}, 10, 10) - ret = histeq(img, 100) - @fact all(map((i, r) -> isapprox(i, r), img, ret)) --> true - @fact eltype(ret) == eltype(img) --> true - - img = ones(Images.ARGB{Images.N0f8}, 10, 10) - ret = histeq(img, 100) - @fact img == ret --> true - @fact eltype(ret) == eltype(img) --> true - - #Working - - img = zeros(10, 10) - for i in 1:10 - img[i, :] = 10 * (i - 1) - end - @fact img == Images.histeq(img, 10, 0, 90) --> true - - ret = Images.histeq(img, 2, 0, 90) - @fact all(ret[1:5, :] .== 0) --> true - @fact all(ret[6:10, :] .== 90) --> true - - ret = Images.histeq(img, 5, 0, 90) - for i in 1:2:10 - @fact all(ret[i:i+1, :] .== 22.5 * floor(i / 2)) --> true - end - - img = [0.0, 21.0, 29.0, 38.0, 38.0, 51.0, 66.0, 79.0, 79.0, 91.0, - 1.0, 21.0, 28.0, 39.0, 39.0, 52.0, 63.0, 77.0, 77.0, 91.0, - 2.0, 22.0, 21.0, 35.0, 35.0, 56.0, 64.0, 73.0, 73.0, 94.0, - 3.0, 21.0, 22.0, 33.0, 33.0, 53.0, 63.0, 72.0, 72.0, 93.0, - 4.0, 22.0, 27.0, 32.0, 32.0, 52.0, 64.0, 78.0, 78.0, 92.0, - 11.0, 21.0, 31.0, 31.0, 42.0, 66.0, 71.0, 71.0, 88.0, 91.0, - 12.0, 22.0, 32.0, 32.0, 44.0, 62.0, 75.0, 75.0, 88.0, 91.0, - 13.0, 23.0, 34.0, 34.0, 49.0, 67.0, 74.0, 74.0, 82.0, 94.0, - 14.0, 26.0, 35.0, 35.0, 43.0, 68.0, 74.0, 74.0, 83.0, 93.0, - 15.0, 27.0, 36.0, 36.0, 44.0, 69.0, 74.0, 74.0, 86.0, 92.0] - img = reshape(img, 10, 10)' - - ret = Images.histeq(img, 10, 0, 99) - cdf = cumsum(imhist(img, 10)[2][2:end-1]) - @fact all(ret[1:cdf[1]] .== 0.0) --> true - for i in 1:(size(cdf)[1]-1) - @fact all(ret[cdf[i] + 1 : cdf[i + 1]] .== (cdf[i + 1] - cdf[1]) * 99.0 / (cdf[end] - cdf[1])) --> true - end - - end - - context("Gamma Correction") do - - img = ones(Images.Gray{Float64}, 10, 10) - ret = adjust_gamma(img, 1) - @fact img == ret --> true - @fact eltype(ret) == eltype(img) --> true - - img = ones(Images.Gray{Images.N0f8}, 10, 10) - ret = adjust_gamma(img, 1) - @fact img == ret --> true - @fact eltype(ret) == eltype(img) --> true - - img = ones(Images.Gray{Images.N0f16}, 10, 10) - ret = adjust_gamma(img, 1) - @fact eltype(ret) == eltype(img) --> true - - img = ones(Images.AGray{Images.N0f8}, 10, 10) - ret = adjust_gamma(img, 1) - @fact img == ret --> true - @fact eltype(ret) == eltype(img) --> true - - img = ones(Images.RGB{Images.N0f8}, 10, 10) - ret = adjust_gamma(img, 1) - @fact img == ret --> true - @fact eltype(ret) == eltype(img) --> true - - img = ones(Images.RGB{Images.N0f16}, 10, 10) - ret = adjust_gamma(img, 1) - @fact img == ret --> true - @fact eltype(ret) == eltype(img) --> true - - img = ones(Images.RGB{Float64}, 10, 10) - ret = adjust_gamma(img, 1) - @fact all(map((i, r) -> isapprox(i, r), img, ret)) --> true - @fact eltype(ret) == eltype(img) --> true - - img = ones(Images.ARGB{Images.N0f8}, 10, 10) - ret = adjust_gamma(img, 1) - @fact img == ret --> true - - #Working - - img = reshape(1:1:100, 10, 10) - ret = Images.adjust_gamma(img, 2) - @fact ret == img .^ 2 --> true - ret = Images.adjust_gamma(img, 0.3) - @fact ret == img .^ 0.3 --> true - ret = Images.adjust_gamma(img, 1, 1, 100) - @fact ret == img --> true - - img = zeros(10, 10) - ret = Images.adjust_gamma(img, 2) - @fact all(ret .== 0) --> true - - a = ARGB(0.2, 0.3, 0.4, 0.5) - r = Images._gamma_pixel_rescale(a, 1) - @fact isapprox(a, r, rtol = 0.0001) --> true - r = Images._gamma_pixel_rescale(a, 2) - @fact alpha(r) --> alpha(a) - - b = AGray(0.2, 0.6) - r = Images._gamma_pixel_rescale(b, 1) - @fact b --> r - r = Images._gamma_pixel_rescale(b, 2) - @fact alpha(r) --> alpha(b) - @fact isapprox(r.val, b.val ^ 2) --> true - - end - - context("Histogram Matching") do - - #DataTypes - img = ones(Images.Gray{Float64}, 10, 10) - ret = histmatch(img, img) - @fact all(ret .== zero(eltype(img))) --> true - @fact eltype(ret) == eltype(img) --> true - - img = ones(Images.Gray{Images.N0f8}, 10, 10) - ret = histmatch(img, img) - @fact all(ret .== zero(eltype(img))) --> true - @fact eltype(ret) == eltype(img) --> true - - img = ones(Images.Gray{Images.N0f16}, 10, 10) - ret = histmatch(img, img) - @fact eltype(ret) == eltype(img) --> true - - img = ones(Images.AGray{Images.N0f8}, 10, 10) - ret = histmatch(img, img) - @fact eltype(ret) == eltype(img) --> true - - img = ones(Images.RGB{Images.N0f8}, 10, 10) - ret = histmatch(img, img) - @fact eltype(ret) == eltype(img) --> true - - img = ones(Images.RGB{Images.N0f16}, 10, 10) - ret = histmatch(img, img) - @fact eltype(ret) == eltype(img) --> true - - img = ones(Images.RGB{Float64}, 10, 10) - ret = histmatch(img, img) - @fact all(map((i, r) -> isapprox(zero(RGB), r, atol = 0.001), img, ret)) --> true - @fact eltype(ret) == eltype(img) --> true - - img = ones(Images.ARGB{Images.N0f8}, 10, 10) - ret = histmatch(img, img) - @fact eltype(ret) == eltype(img) --> true - - img = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] - edges, hist = imhist(img, 2) - himg = Images._histmatch(img, edges, hist) - @fact himg == [0, 0, 0, 0, 0, 5, 5, 5, 5, 5] --> true - edges, hist = imhist(img, 5) - himg = Images._histmatch(img, edges, hist) - @fact himg == [0, 0, 2, 2, 4, 4, 6, 6, 8, 8] --> true - end - - context("Other") do - - # Issue #282 - img = convert(Images.Image{Gray{N0f8}}, eye(2,2)) - imgs = Images.imstretch(img, 0.3, 0.4) - @fact data(imgs) --> roughly(1./(1 + (0.3./(eye(2,2) + eps())).^0.4)) - - img = convert(Images.Image{Gray{N0f16}}, [0.01164 0.01118; 0.01036 0.01187]) - @fact data(imadjustintensity(img,[0.0103761, 0.0252166]))[2,1] --> 0.0 - @fact eltype(imadjustintensity(img)) --> Gray{N0f16} - - img = convert(Images.Image{Gray{N0f16}}, [0.01164 0.01118; 0.01036 0.01187]) - @fact Images.complement(Gray(0.5)) == Gray(0.5) --> true - @fact Images.complement(Gray(0.2)) == Gray(0.8) --> true - @fact all(imcomplement(img) .== 1 - img) --> true - - hist = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] - - clipped_hist = cliphist(hist, 2) - @fact all(clipped_hist .== 2.0) --> true - clipped_hist = cliphist(hist, 3) - @fact all(clipped_hist .== 3.0) --> true - clipped_hist = cliphist(hist, 4) - @fact all(clipped_hist .== 4.0) --> true - clipped_hist = cliphist(hist, 5) - @fact all(clipped_hist .== 5.0) --> true - clipped_hist = cliphist(hist, 6) - @fact clipped_hist == vec([3, 4, 6, 6, 6, 6, 6, 6, 6, 6]) --> true - clipped_hist = cliphist(hist, 7) - @fact clipped_hist == vec([2.6, 3.6, 3.6, 4.6, 5.6, 7, 7, 7, 7, 7]) --> true - clipped_hist = cliphist(hist, 8) - @fact clipped_hist == vec([2.3, 2.3, 3.3, 4.3, 5.3, 6.3, 7.3, 8, 8, 8]) --> true - clipped_hist = cliphist(hist, 9) - @fact clipped_hist == vec([2.1, 2.1, 3.1, 4.1, 5.1, 6.1, 7.1, 8.1, 9, 9]) --> true - clipped_hist = cliphist(hist, 10) - @fact clipped_hist == hist --> true - end - -end diff --git a/test/old/map.jl b/test/old/map.jl deleted file mode 100644 index 319883e8..00000000 --- a/test/old/map.jl +++ /dev/null @@ -1,309 +0,0 @@ -using FactCheck, Images, Colors, FixedPointNumbers -using Compat - -macro chk(a, b) - quote - a = $(esc(a)) - b = $(esc(b)) - @fact (a == b && typeof(a) == typeof(b)) --> true - end -end - -macro chk_approx(a, b) - quote - a = $(esc(a)) - b = $(esc(b)) - @fact (abs(a - b) < 2*(eps(a)+eps(b)) && typeof(a) == typeof(b)) --> true - end -end - -facts("Map") do - context("MapNone") do - mapi = MapNone{Int}() - @chk map(mapi, 7) 7 - @chk map(mapi, 0x07) 7 - a7 = Int[7] - @chk map(mapi, [0x07]) a7 - @fact map(mapi, a7) --> exactly(a7) - mapi = MapNone{RGB24}() - g = N0f8(0.1) - @chk Images.map1(mapi, 0.1) g - @chk map(mapi, 0.1) RGB24(g,g,g) - @chk map(mapi, Gray(0.1)) RGB24(g,g,g) - @chk map(mapi, g) RGB24(g,g,g) - @chk map(mapi, true) RGB24(1,1,1) - @chk map(mapi, false) RGB24(0x00,0x00,0x00) - mapi = MapNone{RGB{Float32}}() - g = 0.1f0 - @chk Images.map1(mapi, 0.1) g - @chk map(mapi, 0.1) RGB(g,g,g) - - c = RGB(0.1,0.2,0.3) - mapi = MapNone{HSV{Float64}}() - @chk map(mapi, c) convert(HSV, c) - - # issue #200 - c = RGBA{N0f8}(1,0.5,0.25,0.8) - mapi = MapNone{Images.ColorTypes.BGRA{N0f8}}() - @chk map(mapi, c) convert(Images.ColorTypes.BGRA{N0f8}, c) - end - - context("BitShift") do - mapi = BitShift{UInt8,7}() - @chk map(mapi, 0xff) 0x01 - @chk map(mapi, 0xf0ff) 0xff - @chk map(mapi, [0xff]) UInt8[0x01] - mapi = BitShift{N0f8,7}() - @chk map(mapi, 0xffuf8) 0x01uf8 - @chk map(mapi, 0xf0ffuf16) 0xffuf8 - mapi = BitShift{ARGB32,4}() - @chk map(mapi, 0xffuf8) reinterpret(ARGB32, 0xff0f0f0f) - mapi = BitShift{RGB24,2}() - @chk map(mapi, Gray(0xffuf8)) reinterpret(RGB24, 0x003f3f3f) - mapi = BitShift{ARGB32,2}() - @chk map(mapi, Gray(0xffuf8)) reinterpret(ARGB32, 0xff3f3f3f) - @chk map(mapi, GrayA{N0f8}(Gray(0xffuf8),0x3fuf8)) reinterpret(ARGB32, 0x0f3f3f3f) - mapi = BitShift{RGB{N0f8},2}() - @chk map(mapi, Gray(0xffuf8)) RGB(0x3fuf8, 0x3fuf8, 0x3fuf8) - mapi = BitShift{ARGB{N0f8},2}() - @chk map(mapi, Gray(0xffuf8)) ARGB{N0f8}(0x3fuf8, 0x3fuf8, 0x3fuf8, 0xffuf8) - @chk map(mapi, GrayA{N0f8}(Gray(0xffuf8),0x3fuf8)) ARGB{N0f8}(0x3fuf8, 0x3fuf8, 0x3fuf8, 0x0fuf8) - mapi = BitShift{RGBA{N0f8},2}() - @chk map(mapi, Gray(0xffuf8)) RGBA{N0f8}(0x3fuf8, 0x3fuf8, 0x3fuf8, 0xffuf8) - @chk map(mapi, GrayA{N0f8}(Gray(0xffuf8),0x3fuf8)) RGBA{N0f8}(0x3fuf8, 0x3fuf8, 0x3fuf8, 0x0fuf8) - mapi = BitShift(ARGB{N0f8}, 8) - @chk map(mapi, RGB{N0f16}(1.0,0.8,0.6)) ARGB{N0f8}(1.0,0.8,0.6,1.0) - mapi = BitShift(RGBA{N0f8}, 8) - @chk map(mapi, RGB{N0f16}(1.0,0.8,0.6)) RGBA{N0f8}(1.0,0.8,0.6,1.0) - # Issue, #269, IJulia issue #294 - bs = BitShift(Gray{N0f8}, 8) - v = Gray(ufixed16(0.8)) - @chk map(bs, v) Gray{N0f8}(0.8) - end - - context("Clamp") do - mapi = ClampMin(Float32, 0.0) - @chk map(mapi, 1.2) 1.2f0 - @chk map(mapi, -1.2) 0.0f0 - mapi = ClampMin(RGB24, 0.0f0) - @chk map(mapi, RGB{Float32}(-5.3,0.4,0.8)) reinterpret(RGB24, 0x000066cc) - mapi = ClampMax(Float32, 1.0) - @chk map(mapi, 1.2) 1.0f0 - @chk map(mapi, -1.2) -1.2f0 - mapi = ClampMax(RGB24, 1.0f0) - @chk map(mapi, RGB{Float32}(0.2,1.3,0.8)) reinterpret(RGB24, 0x0033ffcc) - mapi = ClampMinMax(Float32, 0.0, 1.0) - @chk map(mapi, 1.2) 1.0f0 - @chk map(mapi, -1.2) 0.0f0 - mapi = ClampMinMax(ARGB32, 0.0f0, 1.0f0) - @chk map(mapi, RGB{Float32}(-0.2,1.3,0.8)) reinterpret(ARGB32, 0xff00ffcc) - @chk map(mapi, ARGB{Float32}(-0.2,1.3,0.8,0.6)) reinterpret(ARGB32, 0x9900ffcc) - mapi = Clamp(Float32) - @chk map(mapi, 1.2) 1.0f0 - @chk map(mapi, -1.2) 0.0f0 - mapi = Clamp(N4f12) - @chk map(mapi, N4f12(1.2)) one(N4f12) - mapi = Clamp(Gray{N4f12}) - @chk map(mapi, Gray(N4f12(1.2))) Gray(one(N4f12)) - mapi = ClampMinMax(RGB24, 0.0, 1.0) - @chk map(mapi, 1.2) reinterpret(RGB24, 0x00ffffff) - @chk map(mapi, 0.5) reinterpret(RGB24, 0x00808080) - @chk map(mapi, -.3) reinterpret(RGB24, 0x00000000) - mapi = ClampMinMax(RGB{N0f8}, 0.0, 1.0) - @chk map(mapi, 1.2) RGB{N0f8}(1,1,1) - @chk map(mapi, 0.5) RGB{N0f8}(0.5,0.5,0.5) - @chk map(mapi, -.3) RGB{N0f8}(0,0,0) - mapi = Clamp(RGB{N0f8}) - @chk map(mapi, RGB(1.2,0.5,-.3)) RGB{N0f8}(1,0.5,0) - mapi = Clamp(ARGB{N0f8}) - @chk map(mapi, ARGB{Float64}(1.2,0.5,-.3,0.2)) ARGB{N0f8}(1.0,0.5,0.0,0.2) - @chk map(mapi, RGBA{Float64}(1.2,0.5,-.3,0.2)) ARGB{N0f8}(1.0,0.5,0.0,0.2) - @chk map(mapi, 0.2) ARGB{N0f8}(0.2,0.2,0.2,1.0) - @chk map(mapi, GrayA{Float32}(Gray(0.2),1.2)) ARGB{N0f8}(0.2,0.2,0.2,1.0) - @chk map(mapi, GrayA{Float32}(Gray(-.4),0.8)) ARGB{N0f8}(0.0,0.0,0.0,0.8) - mapi = Clamp(RGBA{N0f8}) - @chk map(mapi, ARGB{Float64}(1.2,0.5,-.3,0.2)) RGBA{N0f8}(1.0,0.5,0.0,0.2) - @chk map(mapi, RGBA{Float64}(1.2,0.5,-.3,0.2)) RGBA{N0f8}(1.0,0.5,0.0,0.2) - @chk map(mapi, 0.2) RGBA{N0f8}(0.2,0.2,0.2,1.0) - @chk map(mapi, GrayA{Float32}(Gray(0.2),1.2)) RGBA{N0f8}(0.2,0.2,0.2,1.0) - @chk map(mapi, GrayA{Float32}(Gray(-.4),0.8)) RGBA{N0f8}(0.0,0.0,0.0,0.8) - # Issue #253 - mapi = Clamp(BGRA{N0f8}) - @chk map(mapi, RGBA{Float32}(1.2,0.5,-.3,0.2)) BGRA{N0f8}(1.0,0.5,0.0,0.2) - - @chk clamp(RGB{Float32}(-0.2,0.5,1.8)) RGB{Float32}(0.0,0.5,1.0) - @chk clamp(ARGB{Float64}(1.2,0.5,-.3,0.2)) ARGB{Float64}(1.0,0.5,0.0,0.2) - @chk clamp(RGBA{Float64}(1.2,0.5,-.3,0.2)) RGBA{Float64}(1.0,0.5,0.0,0.2) - end - - context("Issue #285") do - a = [Gray(0xd0uf8)] - a1 = 10*a - mapi = mapinfo(Gray{N0f8}, a1) - @chk map(mapi, a1[1]) Gray(0xffuf8) - end - - context("ScaleMinMax") do - mapi = ScaleMinMax(N0f8, 100, 1000) - @chk map(mapi, 100) N0f8(0.0) - @chk map(mapi, 1000) N0f8(1.0) - @chk map(mapi, 10) N0f8(0.0) - @chk map(mapi, 2000) N0f8(1.0) - @chk map(mapi, 550) N0f8(0.5) - mapinew = ScaleMinMax(N0f8, [100,500,1000]) - @fact mapinew --> mapi - mapinew = ScaleMinMax(N0f8, [0,500,2000], convert(UInt16, 100), convert(UInt16, 1000)) - @fact mapinew --> mapi - mapi = ScaleMinMax(ARGB32, 100, 1000) - @chk map(mapi, 100) ARGB32(0,0,0,1) - @chk map(mapi, 550) ARGB32(0x80uf8,0x80uf8,0x80uf8,0xffuf8) - @chk map(mapi,2000) ARGB32(1,1,1,1) - mapi = ScaleMinMax(RGB{Float32}, 100, 1000) - @chk map(mapi, 50) RGB(0.0f0, 0.0f0, 0.0f0) - @chk map(mapi, 550) RGB{Float32}(0.5, 0.5, 0.5) - @chk map(mapi,2000) RGB(1.0f0, 1.0f0, 1.0f0) - A = Gray{N0f8}[N0f8(0.1), N0f8(0.9)] - @fact mapinfo(RGB24, A) --> MapNone{RGB24}() - mapi = ScaleMinMax(RGB24, A, zero(Gray{N0f8}), one(Gray{N0f8})) - @fact map(mapi, A) --> map(mapinfo(RGB24, A), A) - mapi = ScaleMinMax(Float32, [Gray(one(N0f8))], 0, 1) # issue #180 - @chk map(mapi, Gray(N0f8(0.6))) 0.6f0 - @fact_throws ErrorException ScaleMinMax(Float32, 0, 0, 1.0) # issue #245 - A = [Gray{Float64}(0.2)] - mapi = ScaleMinMax(RGB{N0f8}, A, 0.0, 0.2) - @fact map(mapi, A) --> [RGB{N0f8}(1,1,1)] - mapi = ScaleMinMax(Gray{N0f8}, Gray{N0f8}(0.2), Gray{N0f8}(0.4)) - @fact Gray{N0f8}(0.49) <= map(mapi, Gray{N0f8}(0.3)) <= Gray{N0f8}(0.5) --> true - @fact Gray{N0f8}(0.49) <= map(mapi, 0.3) <= Gray{N0f8}(0.5) --> true - mapi = ScaleMinMax(Gray{N0f8}, 0.2, 0.4) - @fact Gray{N0f8}(0.49) <= map(mapi, Gray{N0f8}(0.3)) <= Gray{N0f8}(0.5) --> true - @fact Gray{N0f8}(0.49) <= map(mapi, 0.3) <= Gray{N0f8}(0.5) --> true - - A = [-0.5 0.5; Inf NaN] - @fact map(Clamp01NaN(A), A) --> [0.0 0.5; 1.0 0.0] - B = colorim(repeat(reshape(A, (1,2,2)), outer=[3,1,1])) - @fact map(Clamp01NaN(B), B) --> [RGB(0.0,0,0) RGB(0.5,0.5,0.5); RGB(1.0,1,1) RGB(0.0,0,0)] - # Integer-valued images are not recommended, but let's at - # least make sure they work - smm = ScaleMinMax(UInt8, 0.0, 1.0, 255) - @fact map(smm, 0.0) --> exactly(0x00) - @fact map(smm, 1.0) --> exactly(0xff) - @fact map(smm, 0.1) --> exactly(round(UInt8, 0.1*255.0f0)) - smm = ScaleMinMax(Gray{N0f8}, typemin(Int8), typemax(Int8)) - @fact map(smm, 2) --> Gray{N0f8}(0.51) - smm = ScaleMinMax(RGB24, typemin(Int8), typemax(Int8)) - @fact map(smm, 2) --> reinterpret(RGB24, 0x828282) - end - - context("ScaleSigned") do - mapi = ScaleSigned(Float32, 1/5) - @chk map(mapi, 7) 1.0f0 - @chk map(mapi, 5) 1.0f0 - @chk map(mapi, 3) convert(Float32, 3/5) - @chk map(mapi, -3) convert(Float32, -3/5) - @chk map(mapi, -6) -1.0f0 - mapi = ScaleSigned(RGB24, 1.0f0/10) - @chk map(mapi, 12) reinterpret(RGB24, 0x00ff00ff) - @chk map(mapi, -10.0) reinterpret(RGB24, 0x0000ff00) - @chk map(mapi, 0) reinterpret(RGB24, 0x00000000) - end - - @compat context("ScaleAutoMinMax") do - mapi = ScaleAutoMinMax() - A = [100,550,1000] - @chk map(mapi, A) N0f8.([0.0,0.5,1.0]) - mapi = ScaleAutoMinMax(RGB24) - @chk map(mapi, A) reinterpret(RGB24, [0x00000000, 0x00808080, 0x00ffffff]) - - # Issue #304 - A = rand(UInt16, 3, 2, 2) - imgr = colorim(A) - mi1 = ScaleAutoMinMax(RGB{N0f16}) - res1 = raw(map(mi1, imgr)) - mi2 = ScaleAutoMinMax(N0f16) - res2 = raw(map(mi2, raw(imgr))) - # @fact res1 --> res2 - # Note: this fails occassionally. Reproduce it with - # s = 1.1269798f0 - # val = 0xdeb5 - # N0f16(s*N0f16(val,0)) == N0f16((s/typemax(UInt16))*val) - @fact maxabs(convert(Array{Int32}, res1) - convert(Array{Int32}, res2)) --> less_than_or_equal(1) - end - - context("Scaling and ssd") do - img = Images.grayim(fill(typemax(UInt16), 3, 3)) - mapi = Images.mapinfo(N0f8, img) - img8 = map(mapi, img) - @fact all(img8 .== typemax(N0f8)) --> true - A = 0 - mnA, mxA = 1.0, -1.0 - while mnA > 0 || mxA < 0 - A = randn(3,3) - mnA, mxA = extrema(A) - end - offset = 30.0 - img = convert(Images.Image, A .+ offset) - mapi = Images.ScaleMinMax(N0f8, offset, offset+mxA, 1/mxA) - imgs = map(mapi, img) - @fact minimum(imgs) --> 0 - @fact maximum(imgs) --> 1 - @fact eltype(imgs) --> N0f8 - imgs = Images.imadjustintensity(img) - @fact_throws MethodError Images.imadjustintensity(img, [1]) - mnA = minimum(A) - @fact Images.ssd(imgs, (A.-mnA)/(mxA-mnA)) --> less_than(eps(N0f16)) - A = reshape(1:9, 3, 3) - B = map(Images.ClampMin(Float32, 3), A) - @fact (eltype(B) == Float32 && B == [3 4 7; 3 5 8; 3 6 9]) --> true - B = map(Images.ClampMax(UInt8, 7), A) - @fact (eltype(B) == UInt8 && B == [1 4 7; 2 5 7; 3 6 7]) --> true - - A = reinterpret(N0f8, [convert(UInt8,1):convert(UInt8,24);], (3, 2, 4)) - img = reinterpret(RGB{N0f8}, A, (2,4)) - @fact separate(img) --> permutedims(A, (2,3,1)) - end - - context("sc") do - arr = zeros(4,4) - arr[2,2] = 0.5 - @fact sc(arr)[2,2] --> 0xffuf8 - @fact sc(arr, 0.0, 0.75)[2,2] --> 0xaauf8 - end - - context("Color conversion") do - gray = collect(linspace(0.0,1.0,5)) # a 1-dimensional image - gray8 = [round(UInt8, 255 * x) for x in gray] - gray32 = UInt32[convert(UInt32, g)<<16 | convert(UInt32, g)<<8 | convert(UInt32, g) for g in gray8] - imgray = Images.Image(gray) - buf = map(Images.mapinfo(UInt32, imgray), imgray) # Images.uint32color(imgray) - @fact buf --> reinterpret(RGB24, gray32) - rgb = RGB{Float64}[RGB(g, g, g) for g in gray] - buf = map(Images.mapinfo(UInt32, rgb), rgb) # Images.uint32color(rgb) - @fact buf --> reinterpret(RGB24, gray32) - r = red(rgb) - @fact r --> gray - img = Images.Image(reinterpret(RGB24, gray32)) # , ["colordim"-->0, "colorspace"=>"RGB24"]) - buf = map(Images.mapinfo(UInt32, img), img) # Images.uint32color(img) - @fact buf --> reinterpret(RGB24, gray32) - rgb = repeat(gray, outer=[1,3]) - img = colorview(RGB, permuteddimsview(rgb, (2,1))) - buf = map(Images.mapinfo(UInt32, img), img) # Images.uint32color(img) - @fact buf --> reinterpret(RGB24, gray32) - g = green(img) - @fact g --> gray - rgb = repeat(gray', outer=[3,1]) - img = Images.Image(colorview(RGB, rgb)) - buf = map(Images.mapinfo(UInt32, img), img) # Images.uint32color(img) - @fact buf --> reinterpret(RGB24, gray32) - b = blue(img) - @fact b --> gray - end - - context("Map and indexed images") do - img = Images.ImageCmap([1 2 3; 3 2 1], [RGB{N0f16}(1.0,0.6,0.4), RGB{N0f16}(0.2, 0.4, 0.6), RGB{N0f16}(0.5,0.5,0.5)]) - mapi = MapNone(RGB{N0f8}) - imgd = map(mapi, img) - cmap = [RGB{N0f8}(1.0,0.6,0.4), RGB{N0f8}(0.2, 0.4, 0.6), RGB{N0f8}(0.5,0.5,0.5)] - @fact imgd --> reshape(cmap[[1,3,2,2,3,1]], (2,3)) - end -end diff --git a/test/old/overlays.jl b/test/old/overlays.jl deleted file mode 100644 index 8af9f225..00000000 --- a/test/old/overlays.jl +++ /dev/null @@ -1,78 +0,0 @@ -using FactCheck, Images, Colors, FixedPointNumbers -using Compat - -facts("Overlay") do - gray = linspace(0.0, 1.0, 5) - context("One") do - ovr = Images.Overlay((2gray, 2gray), (RGB(1, 0, 0), RGB(0, 0, 1)), (Clamp{Float64}(), Clamp{Float64}())) - @fact ovr[1] --> RGB(0, 0, 0) "test XcqmPT" - @fact ovr[2] --> RGB{N0f8}(0.5, 0, 0.5) "test yAFSVQ" - @fact ovr[3] --> ovr[4] "test dyKCV9" - @fact ovr[4] --> ovr[5] "test d4aUI1" - @fact ovr[5] --> exactly(RGB(1, 0, 1)) "test UF1jSj" - @fact eltype(ovr) --> RGB{N0f8} "test Es9OnV" - @fact length(ovr) --> 5 "test 04ptpL" - @fact size(ovr) --> (5,) "test iE5wc4" - @fact size(ovr, 1) --> 5 "test OvtQ4m" - @fact size(ovr, 2) --> 1 "test O1oIKi" - @fact nchannels(ovr) --> 2 "test vhNvBL" - @fact raw(ovr) --> [0x00 0x80 0xff 0xff 0xff; - 0x00 0x00 0x00 0x00 0x00; - 0x00 0x80 0xff 0xff 0xff] "test vLlExB" - @fact separate(ovr) --> N0f8[0 0 0; - 0.5 0 0.5; - 1 0 1; - 1 0 1; - 1 0 1] "test XrmTTp" - iob = IOBuffer() - show(iob, ovr) # exercise only - end - - context("Two") do - ovr = Images.Overlay((gray, 0*gray), (RGB{N0f8}(1, 0, 1), RGB{N0f8}(0, 1, 0)), ((0, 1), (0, 1))) - @fact eltype(ovr) --> RGB{N0f8} "test u7gavU" - ovr = collect(ovr) - s = similar(ovr) - @fact typeof(s) --> Vector{RGB{N0f8}} "test qOV0Iu" - @fact length(s) --> 5 "test HxDDe4" - s = similar(ovr, RGB{Float32}) - @fact isa(s, Vector{RGB{Float32}}) --> true "test tPX9bh" - @fact length(s) --> 5 "test CEJl6T" - s = similar(ovr, RGB{Float32}, (3, 2)) - @fact isa(s, Matrix{RGB{Float32}}) --> true "test qQvSYP" - @fact size(s) --> (3, 2) "test uoSePw" - buf = Images.uint32color(ovr) - gray8 = round(UInt8, 255*gray) - nogreen = [convert(UInt32, g)<<16 | convert(UInt32, g) for g in gray8] - @fact reinterpret(UInt32, buf) --> nogreen "test XOvI8c" - end - - context("Three") do - ovr = Images.Overlay((gray, 0*gray), [RGB(1, 0, 1), RGB(0, 1, 0)], ([0, 1], [0, 1])) - @fact_throws ErrorException Images.Overlay((gray, 0*gray), (RGB(1, 0, 1), RGB(0, 1, 0)), ((0,), (0, 1))) "test AKzBSc" - @fact_throws ErrorException ovr[1] = RGB(0.2, 0.4, 0.6) "test uxe7aR" - end - - context("Four") do - img1 = Images.Image(gray) - ovr = Images.OverlayImage((2gray, img1), (RGB{Float32}(1, 0, 1), RGB{Float32}(0, 1, 0)), ((0, 1),(0, 1))) - @fact isa(ovr, Images.Image) --> true "test AcmCRK" - @fact haskey(ovr, "colorspace") --> false "test W1xBNq" - @fact Images.colorspace(ovr) --> "RGB" "test me6TWH" - @fact ovr[2] --> RGB{Float32}(0.5, 0.25, 0.5) "test lznPxT" - a = rand(Float32, 3, 2) - b = rand(Float32, 3, 2) - ovr = Images.OverlayImage((a, b), (RGB{Float32}(1, 0, 1), RGB{Float32}(0, 1, 0)), ((0, 1), (0, 1))) - @fact isa(ovr, Images.Image) --> true "test 8nGPCi" - @fact abs(ovr[1, 2] - RGB{Float32}(a[1, 2], b[1, 2], a[1, 2])) --> roughly(0, atol=1e-5) "test 5N74oJ" - end - - context("permutation") do - L1 = convert(Image{Gray}, rand(Float32, 10,10)) - L2 = convert(Image{Gray}, rand(Float32, 10,10)) - L3 = convert(Image{Gray}, rand(Float32, 10,10)) - overlay = OverlayImage((L1, L2, L3), (colorant"red", colorant"blue", colorant"green"), ((0,1),(0,1),(0,1))) - permutedims(overlay, [2,1]) - permutedims(data(overlay), [2,1]) - end -end diff --git a/test/old/parallel.jl b/test/old/parallel.jl deleted file mode 100644 index 11d5e9b4..00000000 --- a/test/old/parallel.jl +++ /dev/null @@ -1,22 +0,0 @@ -addprocs(2) -using Images, Base.Test, Colors -# Normally "using Images" would suffice, but since Images has -# already been loaded by the time this file runs, that yields -# a no-op. So we have to force the workers to load it manually. -# See https://github.com/JuliaLang/julia/issues/3674 -@sync for p in workers() - @spawnat p eval(Expr(:using, :Images)) # FIXME: on 0.4 you can say :(using Images) directly -end - -# Issue #287 -@everywhere function test287(img) - return 0; -end -Imgs = Array{Matrix{RGB{Float64}}}(2); -Imgs[1] = rand(RGB{Float64}, 100, 100) -Imgs[2] = rand(RGB{Float64}, 100, 100) - -let Imgs = Imgs; - ret = pmap(i -> test287(Imgs[i]), 1:2); - @test ret == Any[0,0] -end diff --git a/test/old/restrict.jl b/test/old/restrict.jl deleted file mode 100644 index f1da2b2e..00000000 --- a/test/old/restrict.jl +++ /dev/null @@ -1,27 +0,0 @@ -# This is for testing display in IJulia. A huge image should -# be automatically restricted before sending to IJulia for display. - -using Images - -url = "http://upload.wikimedia.org/wikipedia/commons/9/97/The_Earth_seen_from_Apollo_17.jpg" - -if !isdefined(:workdir) - const workdir = joinpath(tempdir(), "Images") -end -if !isdefined(:writedir) - const writedir = joinpath(workdir, "write") -end - -if !isdir(workdir) - mkdir(workdir) -end -if !isdir(writedir) - mkdir(writedir) -end - -const savename = joinpath(writedir, "The_Earth_seen_from_Apollo_17.jpg") -if !isfile(savename) - download(url, savename) -end - -img = imread(savename) diff --git a/test/old/runtests.jl b/test/old/runtests.jl deleted file mode 100644 index 94b87222..00000000 --- a/test/old/runtests.jl +++ /dev/null @@ -1,25 +0,0 @@ -module ImagesTests - -using FactCheck, Base.Test, Images, Colors, FixedPointNumbers -using Graphics - -testing_units = Int == Int64 -if testing_units - using SIUnits, SIUnits.ShortUnits -end - - -include("core.jl") -include("map.jl") -include("overlays.jl") -include("algorithms.jl") -include("exposure.jl") -include("edge.jl") -include("writemime.jl") -include("corner.jl") - -isinteractive() || FactCheck.exitstatus() - -end - -include("parallel.jl") diff --git a/test/old/writemime.jl b/test/old/writemime.jl deleted file mode 100644 index f47b5b8a..00000000 --- a/test/old/writemime.jl +++ /dev/null @@ -1,50 +0,0 @@ -using Images, FactCheck, Colors, FixedPointNumbers - -facts("show (MIME)") do - # Test that we remembered to turn off Colors.jl's colorswatch display - @fact mimewritable(MIME("image/svg+xml"), rand(Gray{N0f8}, 5, 5)) --> false - @fact mimewritable(MIME("image/svg+xml"), rand(RGB{N0f8}, 5, 5)) --> false - @fact mimewritable(MIME("image/png"), rand(Gray{N0f8}, 5, 5)) --> true - @fact mimewritable(MIME("image/png"), rand(RGB{N0f8}, 5, 5)) --> true - workdir = joinpath(tempdir(), "Images") - if !isdir(workdir) - mkdir(workdir) - end - context("no compression or expansion") do - A = N0f8[0.01 0.99; 0.25 0.75] - fn = joinpath(workdir, "writemime.png") - open(fn, "w") do file - show(file, MIME("image/png"), grayim(A), minpixels=0, maxpixels=typemax(Int)) - end - b = convert(Image{Gray{N0f8}}, load(fn)) - @fact data(b) --> A - end - context("small images (expansion)") do - A = N0f8[0.01 0.99; 0.25 0.75] - fn = joinpath(workdir, "writemime.png") - open(fn, "w") do file - show(file, MIME("image/png"), grayim(A), minpixels=5, maxpixels=typemax(Int)) - end - b = convert(Image{Gray{N0f8}}, load(fn)) - @fact data(b) --> A[[1,1,2,2],[1,1,2,2]] - end - context("big images (use of restrict)") do - A = N0f8[0.01 0.4 0.99; 0.25 0.8 0.75; 0.6 0.2 0.0] - Ar = restrict(A) - fn = joinpath(workdir, "writemime.png") - open(fn, "w") do file - show(file, MIME("image/png"), grayim(A), minpixels=0, maxpixels=5) - end - b = convert(Image{Gray{N0f8}}, load(fn)) - @fact data(b) --> convert(Array{N0f8}, Ar) - # a genuinely big image (tests the defaults) - abig = grayim(rand(UInt8, 1024, 1023)) - fn = joinpath(workdir, "big.png") - open(fn, "w") do file - show(file, MIME("image/png"), abig, maxpixels=10^6) - end - b = convert(Image{Gray{N0f8}}, load(fn)) - abigui = convert(Array{N0f8,2}, data(restrict(abig, (1,2)))) - @fact data(b) --> abigui - end -end diff --git a/test/runtests.jl b/test/runtests.jl index 75c2fa4b..22e1f377 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -12,6 +12,3 @@ include("distances.jl") include("writemime.jl") end - -info("\n\nBeginning of tests with deprecation warnings\n\n") -include("old/runtests.jl") From b963c45db071a774dd80fe67207839792726643e Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Thu, 13 Jul 2017 14:57:48 -0500 Subject: [PATCH 2/3] Fix a couple of new depwarns and require Julia 0.6 --- .travis.yml | 1 - REQUIRE | 4 ++-- appveyor.yml | 2 -- src/algorithms.jl | 2 +- test/edge.jl | 14 +++++++------- 5 files changed, 10 insertions(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7cbdc78a..819eaa6a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,6 @@ os: - osx dist: trusty # for a more recent ImageMagick julia: - - 0.5 - 0.6 - nightly # matrix: diff --git a/REQUIRE b/REQUIRE index e76e14e5..7afae044 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,4 +1,4 @@ -julia 0.5 +julia 0.6.0 Reexport Colors 0.7.0 ColorVectorSpace 0.2 @@ -15,5 +15,5 @@ SIUnits Graphics 0.1 FileIO Compat 0.19 -StatsBase # for histrange +StatsBase 0.14 # for histrange Requires diff --git a/appveyor.yml b/appveyor.yml index 7d27ac77..3569f63b 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,7 +1,5 @@ environment: matrix: - - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.5/julia-0.5-latest-win32.exe" - - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.5/julia-0.5-latest-win64.exe" - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe" - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe" - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe" diff --git a/src/algorithms.jl b/src/algorithms.jl index 8ebc88f0..739005ec 100644 --- a/src/algorithms.jl +++ b/src/algorithms.jl @@ -121,7 +121,7 @@ The base β of the logarithm (a.k.a. entropy unit) is one of the following: """ entropy(img::AbstractArray; kind=:shannon) = entropy(_log(kind), img) function entropy{Log<:Function}(logᵦ::Log, img) - hist = StatsBase.fit(Histogram, vec(img), nbins=256) + hist = StatsBase.fit(Histogram, vec(img), nbins=256, closed=:right) counts = hist.weights p = counts / length(img) logp = logᵦ.(p) diff --git a/test/edge.jl b/test/edge.jl index 96f0044d..5b516a60 100644 --- a/test/edge.jl +++ b/test/edge.jl @@ -46,7 +46,7 @@ global checkboard img = zeros(10, 10) edges = canny(img, (0.8, 0.2)) @test eltype(edges) == Bool - @test all(! edges) + @test all(.!edges) #Box Edges @@ -56,28 +56,28 @@ global checkboard @test all(edges[2:end-1, end-1]) @test all(edges[2, 2:end-1]) @test all(edges[end-1, 2:end-1]) - @test all(! edges[3:end-2, 3:end-2]) + @test all(.!edges[3:end-2, 3:end-2]) edges = canny(img, (0.9/8, 0.2/8), 1.4) @test all(edges[2:end-1, 2]) @test all(edges[2:end-1, end-1]) @test all(edges[2, 2:end-1]) @test all(edges[end-1, 2:end-1]) - @test all(! edges[3:end-2, 3:end-2]) + @test all(.!edges[3:end-2, 3:end-2]) #Checkerboard - Corners are not detected as Edges! img = checkerboard(Gray, 5, 3) edges = canny(img, (Percentile(80), Percentile(20)), 1.4) @test eltype(edges) == Bool id = [1,2,3,4,6,7,8,9,10,12,13,14,15] - @test all(! edges[id, id]) + @test all(.!edges[id, id]) id = [5, 11] id2 = [1,2,3,4,7,8,9,12,13,14,15] id3 = [5,6,10,11] @test all(edges[id, id2]) @test all(edges[id2, id]) - @test all(! edges[id, id3]) - @test all(! edges[id3, id]) + @test all(.!edges[id, id3]) + @test all(.!edges[id3, id]) #Diagonal Edge img = zeros(10,10) @@ -89,7 +89,7 @@ global checkboard @test all(edges[diagind(edges, 2)]) @test all(edges[diagind(edges, -2)]) nondiags = setdiff(1:1:100, union(diagind(edges, 2), diagind(edges, -2))) - @test all(! edges[nondiags]) + @test all(.!edges[nondiags]) #Checks Hysteresis Thresholding img = ones(Gray{N0f8}, (10, 10)) From e8f6b47b27bb32beb9b5c961fc9525b5e79b2a02 Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Thu, 13 Jul 2017 15:15:57 -0500 Subject: [PATCH 3/3] Allow failures on nightly --- .travis.yml | 6 +++--- appveyor.yml | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 819eaa6a..a37bf83b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,9 +6,9 @@ dist: trusty # for a more recent ImageMagick julia: - 0.6 - nightly -# matrix: -# allow_failures: -# - julia: nightly +matrix: + allow_failures: + - julia: nightly notifications: email: false # script: diff --git a/appveyor.yml b/appveyor.yml index 3569f63b..c7ba0168 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -5,6 +5,13 @@ environment: - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe" - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe" +## uncomment the following lines to allow failures on nightly julia +## (tests will run but not make your overall status red) +matrix: + allow_failures: + - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe" + - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe" + branches: only: - master