Skip to content

Commit

Permalink
Merge pull request #573 from timholy/yyc/0.6
Browse files Browse the repository at this point in the history
Fix 0.6 depwarns
  • Loading branch information
yuyichao authored Jan 15, 2017
2 parents 4b675ce + 271cc34 commit 518d168
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 65 deletions.
6 changes: 5 additions & 1 deletion src/Images.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 13 additions & 3 deletions src/algorithms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
Expand All @@ -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

Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/connected.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
42 changes: 21 additions & 21 deletions test/algorithms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
8 changes: 5 additions & 3 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand Down
67 changes: 38 additions & 29 deletions test/edge.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -514,3 +522,4 @@ end
end

end
end
20 changes: 14 additions & 6 deletions test/map.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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])

Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion test/overlays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module ImagesTests

using FactCheck, Base.Test, Images, Colors, FixedPointNumbers
using Graphics
using Compat

testing_units = Int == Int64
if testing_units
Expand Down

0 comments on commit 518d168

Please sign in to comment.