From 271cc3465ab3ff06ae9e4e54e6489db54aa50721 Mon Sep 17 00:00:00 2001 From: Yichao Yu Date: Tue, 10 Jan 2017 22:52:40 -0500 Subject: [PATCH] Fix 0.6 depwarns and errors --- src/Images.jl | 6 ++++- src/algorithms.jl | 16 ++++++++--- src/connected.jl | 2 +- test/algorithms.jl | 42 ++++++++++++++--------------- test/core.jl | 8 +++--- test/edge.jl | 67 ++++++++++++++++++++++++++-------------------- test/map.jl | 20 +++++++++----- test/overlays.jl | 2 +- test/runtests.jl | 1 + 9 files changed, 99 insertions(+), 65 deletions(-) diff --git a/src/Images.jl b/src/Images.jl index 919401bb..c6ce1d17 100644 --- a/src/Images.jl +++ b/src/Images.jl @@ -2,7 +2,11 @@ __precompile__(true) module Images -import Base.take +if VERSION >= v"0.6.0-dev.1024" + import Base.Iterators.take +else + import Base.take +end import Base.Order: Ordering, ForwardOrdering, ReverseOrdering import Base: ==, .==, +, -, *, /, .+, .-, .*, ./, .^, .<, .> import Base: abs, atan2, clamp, convert, copy, copy!, ctranspose, delete!, done, diff --git a/src/algorithms.jl b/src/algorithms.jl index fa8b9dcf..26879b88 100644 --- a/src/algorithms.jl +++ b/src/algorithms.jl @@ -1042,6 +1042,15 @@ function copytail!(dest, A, coloffset, strd, len) dest end +@generated function blob_LoG_helper1{T,N}(img_LoG::AbstractArray{T,N}, + radii, x) + :(img_LoG[x...], radii[x[1]], (@ntuple $(N - 1) d->x[d+1])...) +end + +function blob_LoG_helper2(img_LoG, radii, maxima) + return [blob_LoG_helper1(img_LoG, radii, x) for x in maxima] +end + """ `blob_LoG(img, sigmas) -> Vector{Tuple}` @@ -1062,7 +1071,7 @@ Note that only 2-D images are currently supported due to a limitation of `imfilt radii = sqrt(2.0)*sigmas maxima = findlocalmaxima(img_LoG, 1:ndims(img_LoG), (true, falses(N)...)) - [(img_LoG[x...], radii[x[1]], (@ntuple $N d->x[d+1])...) for x in maxima] + blob_LoG_helper2(img_LoG, radii, maxima) end end @@ -1619,8 +1628,9 @@ for N = 2:4 end # Circular shift the dimensions - maxval_temp = permutedims(maxval_temp, mod(collect(1:$N), $N)+1) - minval_temp = permutedims(minval_temp, mod(collect(1:$N), $N)+1) + perm_idx = @compat mod.(1:$N, $N) .+ 1 + maxval_temp = permutedims(maxval_temp, perm_idx) + minval_temp = permutedims(minval_temp, perm_idx) end diff --git a/src/connected.jl b/src/connected.jl index f5e8b210..1a4dc7e0 100644 --- a/src/connected.jl +++ b/src/connected.jl @@ -89,7 +89,7 @@ function label_components!(Albl::AbstractArray{Int}, A::Array, region::Union{Dim f! = _label_components_cache[key] end sets = DisjointMinSets() - f!(Albl, sets, A, bkg) + eval(:($f!($Albl, $sets, $A, $bkg))) # Now parse sets to find the labels newlabel = minlabel(sets) for i = 1:length(A) diff --git a/test/algorithms.jl b/test/algorithms.jl index 220fb77e..52261336 100644 --- a/test/algorithms.jl +++ b/test/algorithms.jl @@ -8,27 +8,27 @@ facts("Algorithms") do 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 = UInt8[200 150; 50 1] - img_x = grayim(A) - img_y = permutedims(img_x, [2, 1]) - - @fact raw(flipdim(img_x, "x")) --> raw(flipdim(img_x, 1)) - @fact raw(flipdim(img_x, "x")) --> flipdim(A, 1) - @fact raw(flipdim(img_y, "x")) --> raw(flipdim(img_y, 2)) - @fact raw(flipdim(img_y, "x")) --> flipdim(A', 2) - - @fact raw(flipdim(img_x, "y")) --> raw(flipdim(img_x, 2)) - @fact raw(flipdim(img_x, "y")) --> flipdim(A, 2) - @fact raw(flipdim(img_y, "y")) --> raw(flipdim(img_y, 1)) - @fact raw(flipdim(img_y, "y")) --> flipdim(A', 1) - - @fact raw(flipx(img_x)) --> raw(flipdim(img_x, "x")) - @fact raw(flipx(img_y)) --> raw(flipdim(img_y, "x")) - - @fact raw(flipy(img_x)) --> raw(flipdim(img_x, "y")) - @fact raw(flipy(img_y)) --> raw(flipdim(img_y, "y")) - end + context("Flip dimensions") do + A = UInt8[200 150; 50 1] + img_x = grayim(A) + img_y = permutedims(img_x, [2, 1]) + + @fact raw(flipdim(img_x, "x")) --> raw(flipdim(img_x, 1)) + @fact raw(flipdim(img_x, "x")) --> flipdim(A, 1) + @fact raw(flipdim(img_y, "x")) --> raw(flipdim(img_y, 2)) + @fact raw(flipdim(img_y, "x")) --> flipdim(A', 2) + + @fact raw(flipdim(img_x, "y")) --> raw(flipdim(img_x, 2)) + @fact raw(flipdim(img_x, "y")) --> flipdim(A, 2) + @fact raw(flipdim(img_y, "y")) --> raw(flipdim(img_y, 1)) + @fact raw(flipdim(img_y, "y")) --> flipdim(A', 1) + + @fact raw(flipx(img_x)) --> raw(flipdim(img_x, "x")) + @fact raw(flipx(img_y)) --> raw(flipdim(img_y, "x")) + + @fact raw(flipy(img_x)) --> raw(flipdim(img_x, "y")) + @fact raw(flipy(img_y)) --> raw(flipdim(img_y, "y")) + end context("Arithmetic") do img = convert(Images.Image, zeros(3,3)) diff --git a/test/core.jl b/test/core.jl index 5c5b3ce6..b0c2efce 100644 --- a/test/core.jl +++ b/test/core.jl @@ -16,7 +16,7 @@ facts("Core") do B = rand(convert(UInt16, 1):convert(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(UFixed8, round(UInt8, linspace(12, 255, 20)))', 3, 1)) + cmap = reinterpret(RGB, repmat(reinterpret(UFixed8, [round(UInt8, x) for x in linspace(12, 255, 20)])', 3, 1)) img = ImageCmap(copy(B), cmap, Dict{Compat.ASCIIString, Any}([("pixelspacing", [2.0, 3.0]), ("spatialorder", Images.yx)])) imgd = convert(Image, img) if testing_units @@ -35,14 +35,16 @@ facts("Core") do @fact colordim(B) --> 0 @fact grayim(img) --> img # this is recommended for "integer-valued" images (or even better, directly as a UFixed type) - Bf = grayim(round(UInt8, B)) + # Work around poor inference and no shape preserving comprehension + # on 0.4..... Change to `round.(UInt8, B)` on 0.6 + Bf = grayim(convert(Array{UInt8}, @compat round.([UInt8], B))) @fact eltype(Bf) --> UFixed8 @fact colorspace(Bf) --> "Gray" @fact colordim(Bf) --> 0 Bf = grayim(B) @fact eltype(Bf) --> UFixed16 # colorspace encoded as a Color (enables multiple dispatch) - BfCV = reinterpret(Gray{UFixed8}, round(UInt8, B)) + BfCV = reinterpret(Gray{UFixed8}, [round(UInt8, x) for x in B]) @fact colorspace(BfCV) --> "Gray" @fact colordim(BfCV) --> 0 Bf3 = grayim(reshape(collect(convert(UInt8,1):convert(UInt8,36)), 3,4,3)) diff --git a/test/edge.jl b/test/edge.jl index f2ccfebe..a344659b 100644 --- a/test/edge.jl +++ b/test/edge.jl @@ -1,7 +1,15 @@ -using Images, FactCheck, Base.Test, Colors +module TestImagesEdge +using Images, FactCheck, Base.Test, Colors, Compat, Graphics 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 @@ -138,9 +146,9 @@ facts("Edge") do # 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 + @fact all((|).(cos.(agphase) .* cos.(aorient) .+ + sin.(agphase) .* sin.(aorient) .< EPS, + (&).(agphase .== 0.0, aorient .== 0.0))) --> true # this part is where both are zero because there is no gradient ## Checkerboard Image with row major order @@ -162,9 +170,9 @@ facts("Edge") do # Test that orientation is perpendicular to gradient orient = orientation(gx, gy) - @fact all((cos.(gphase) .* cos.(orient) .+ - sin.(gphase) .* sin.(orient) .< EPS) | - ((gphase .== 0.0) & (orient .== 0.0))) --> true + @fact all((|).(cos.(gphase) .* cos.(orient) .+ + sin.(gphase) .* sin.(orient) .< EPS, + (&).(gphase .== 0.0, orient .== 0.0))) --> true # this part is where both are zero because there is no gradient ## Checkerboard Image with column-major order @@ -187,9 +195,9 @@ facts("Edge") do # Test that orientation is perpendicular to gradient orient = orientation(gx, gy) - @fact all((cos.(gphase) .* cos.(orient) .+ - sin.(gphase) .* sin.(orient) .< EPS) | - ((gphase .== 0.0) & (orient .== 0.0))) --> true + @fact all((|).(cos.(gphase) .* cos.(orient) .+ + sin.(gphase) .* sin.(orient) .< EPS, + (&).(gphase .== 0.0, orient .== 0.0))) --> true # this part is where both are zero because there is no gradient ## Checkerboard Image with Gray pixels @@ -211,9 +219,9 @@ facts("Edge") do # 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 + @fact all((|).(cos.(gphaseg) .* cos.(orientg) .+ + sin.(gphaseg) .* sin.(orientg) .< EPS, + (&).(gphaseg .== 0.0, orientg .== 0.0))) --> true # this part is where both are zero because there is no gradient ## Checkerboard Image with RBG pixels @@ -235,9 +243,9 @@ facts("Edge") do # 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 + @fact all((|).(cos.(gphase_rgb) .* cos.(orient_rgb) .+ + sin.(gphase_rgb) .* sin.(orient_rgb) .< EPS, + (&).(gphase_rgb .== 0.0, orient_rgb .== 0.0))) --> true # this part is where both are zero because there is no gradient ## Checkerboard Image with RBG{Float64} pixels @@ -259,9 +267,9 @@ facts("Edge") do # 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 + @fact all((|).(cos.(gphase_rgb) .* cos.(orient_rgb) .+ + sin.(gphase_rgb) .* sin.(orient_rgb) .< EPS, + (&).(gphase_rgb .== 0.0, orient_rgb .== 0.0))) --> true # this part is where both are zero because there is no gradient end end @@ -294,9 +302,9 @@ facts("Edge") do # 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 + @fact all((|).(cos.(agphase) .* cos.(aorient) .+ + sin.(agphase) .* sin.(aorient) .< EPS, + (&).(agphase .== 0.0, aorient .== 0.0))) --> true # this part is where both are zero because there is no gradient ## Diagonal Image, row-major order @@ -317,9 +325,9 @@ facts("Edge") do # Test that orientation is perpendicular to gradient orient = orientation(gx, gy) - @fact all((cos.(gphase) .* cos.(orient) .+ - sin.(gphase) .* sin.(orient) .< EPS) | - ((gphase .== 0.0) & (orient .== 0.0))) --> true + @fact all((|).(cos.(gphase) .* cos.(orient) .+ + sin.(gphase) .* sin.(orient) .< EPS, + (&).(gphase .== 0.0, orient .== 0.0))) --> true # this part is where both are zero because there is no gradient ## Diagonal Image, column-major order @@ -340,9 +348,9 @@ facts("Edge") do # Test that orientation is perpendicular to gradient orient = orientation(gx, gy) - @fact all((cos.(gphase) .* cos.(orient) .+ - sin.(gphase) .* sin.(orient) .< EPS) | - ((gphase .== 0.0) & (orient .== 0.0))) --> true + @fact all((|).(cos.(gphase) .* cos.(orient) .+ + sin.(gphase) .* sin.(orient) .< EPS, + (&).(gphase .== 0.0, orient .== 0.0))) --> true # this part is where both are zero because there is no gradient end end @@ -386,7 +394,7 @@ facts("Edge") do transposed = spatialorder(img)[1] == "x" horizontal = which == :horizontal - test_axis1 = transposed $ !horizontal + test_axis1 = transposed ⊻ !horizontal if test_axis1 @fact all(t[:,[1,2,4,5]] .== 0) --> true @@ -514,3 +522,4 @@ end end end +end diff --git a/test/map.jl b/test/map.jl index cf60b1ae..e6a902d4 100644 --- a/test/map.jl +++ b/test/map.jl @@ -2,11 +2,19 @@ using FactCheck, Images, Colors, FixedPointNumbers using Compat macro chk(a, b) - :(@fact ($a == $b && typeof($a) == typeof($b)) --> true) + quote + a = $(esc(a)) + b = $(esc(b)) + @fact (a == b && typeof(a) == typeof(b)) --> true + end end macro chk_approx(a, b) - :(@fact (abs($a - $b) < 2*(eps($a)+eps($b)) && typeof($a) == typeof($b)) --> true) + 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 @@ -200,10 +208,10 @@ facts("Map") do @chk map(mapi, 0) reinterpret(RGB24, 0x00000000) end - context("ScaleAutoMinMax") do + @compat context("ScaleAutoMinMax") do mapi = ScaleAutoMinMax() A = [100,550,1000] - @chk map(mapi, A) @compat UFixed8.([0.0,0.5,1.0]) + @chk map(mapi, A) UFixed8.([0.0,0.5,1.0]) mapi = ScaleAutoMinMax(RGB24) @chk map(mapi, A) reinterpret(RGB24, [0x00000000, 0x00808080, 0x00ffffff]) @@ -219,7 +227,7 @@ facts("Map") do # s = 1.1269798f0 # val = 0xdeb5 # UFixed16(s*UFixed16(val,0)) == UFixed16((s/typemax(UInt16))*val) - @fact maxabs(convert(Array{Int32}, res1) - convert(Array{Int32}, res2)) --> less_than_or_equal(1) + @fact maximum(abs, convert(Array{Int32}, res1) - convert(Array{Int32}, res2)) --> less_than_or_equal(1) end context("Scaling and ssd") do @@ -264,7 +272,7 @@ facts("Map") do context("Color conversion") do gray = collect(linspace(0.0,1.0,5)) # a 1-dimensional image - gray8 = round(UInt8, 255*gray) + 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, Dict{Compat.ASCIIString,Any}([("colordim",0), ("colorspace","Gray")])) buf = map(Images.mapinfo(UInt32, imgray), imgray) # Images.uint32color(imgray) diff --git a/test/overlays.jl b/test/overlays.jl index c10ef51c..d7c66062 100644 --- a/test/overlays.jl +++ b/test/overlays.jl @@ -41,7 +41,7 @@ facts("Overlay") do @fact isa(s, Matrix{RGB{Float32}}) --> true @fact size(s) --> (3, 2) buf = Images.uint32color(ovr) - gray8 = round(UInt8, 255*gray) + gray8 = [round(UInt8, 255 * x) for x in gray] nogreen = reinterpret(RGB24, [convert(UInt32, g)<<16 | convert(UInt32, g) for g in gray8]) @fact buf --> nogreen end diff --git a/test/runtests.jl b/test/runtests.jl index a0cf91bc..8b8148fe 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -2,6 +2,7 @@ module ImagesTests using FactCheck, Base.Test, Images, Colors, FixedPointNumbers using Graphics +using Compat testing_units = Int == Int64 if testing_units