|
1 |
| -@testset "restrict" begin |
2 |
| - A = reshape([UInt16(i) for i = 1:60], 4, 5, 3) |
3 |
| - B = restrict(A, (1,2)) |
4 |
| - Btarget = cat( [ 0.96875 4.625 5.96875; |
5 |
| - 2.875 10.5 12.875; |
6 |
| - 1.90625 5.875 6.90625], |
7 |
| - [ 8.46875 14.625 13.46875; |
| 1 | +@testset "restrict" begin |
| 2 | + @testset "numerical test" begin |
| 3 | + A = reshape([UInt16(i) for i = 1:60], 4, 5, 3) |
| 4 | + B = restrict(A, (1,2)) |
| 5 | + Btarget = cat([0.96875 4.625 5.96875; |
| 6 | + 2.875 10.5 12.875; |
| 7 | + 1.90625 5.875 6.90625], |
| 8 | + [8.46875 14.625 13.46875; |
8 | 9 | 17.875 30.5 27.875;
|
9 |
| - 9.40625 15.875 14.40625], |
10 |
| - [ 15.96875 24.625 20.96875; |
| 10 | + 9.40625 15.875 14.40625], |
| 11 | + [15.96875 24.625 20.96875; |
11 | 12 | 32.875 50.5 42.875;
|
12 | 13 | 16.90625 25.875 21.90625], dims=3)
|
13 |
| - @test B ≈ Btarget |
14 |
| - Argb = reinterpretc(RGB, reinterpret(N0f16, permutedims(A, (3,1,2)))) |
15 |
| - B = restrict(Argb) |
16 |
| - Bf = permutedims(reinterpretc(eltype(eltype(B)), B), (2,3,1)) |
17 |
| - # isapprox no longer lies, so atol is now serious |
18 |
| - @test isapprox(Bf, Btarget/reinterpret(one(N0f16)), atol=1e-10) |
19 |
| - Argba = reinterpretc(RGBA{N0f16}, reinterpret(N0f16, A)) |
20 |
| - B = restrict(Argba) |
21 |
| - @test isapprox(reinterpretc(eltype(eltype(B)), B), restrict(A, (2,3))/reinterpret(one(N0f16)), atol=1e-10) |
22 |
| - A = reshape(1:60, 5, 4, 3) |
23 |
| - B = restrict(A, (1,2,3)) |
24 |
| - @test cat( [ 2.6015625 8.71875 6.1171875; |
25 |
| - 4.09375 12.875 8.78125; |
26 |
| - 3.5390625 10.59375 7.0546875], |
27 |
| - [ 10.1015625 23.71875 13.6171875; |
| 14 | + @test B ≈ Btarget |
| 15 | + |
| 16 | + Argb = reinterpretc(RGB, reinterpret(N0f16, permutedims(A, (3,1,2)))) |
| 17 | + B = restrict(Argb) |
| 18 | + Bf = permutedims(reinterpretc(eltype(eltype(B)), B), (2,3,1)) |
| 19 | + # isapprox no longer lies, so atol is now serious |
| 20 | + @test isapprox(Bf, Btarget/reinterpret(one(N0f16)), atol=1e-10) |
| 21 | + |
| 22 | + Argba = reinterpretc(RGBA{N0f16}, reinterpret(N0f16, A)) |
| 23 | + B = restrict(Argba) |
| 24 | + @test isapprox(reinterpretc(eltype(eltype(B)), B), restrict(A, (2,3))/reinterpret(one(N0f16)), atol=1e-10) |
| 25 | + |
| 26 | + A = reshape(1:60, 5, 4, 3) |
| 27 | + B = restrict(A, (1,2,3)) |
| 28 | + @test cat([2.6015625 8.71875 6.1171875; |
| 29 | + 4.09375 12.875 8.78125; |
| 30 | + 3.5390625 10.59375 7.0546875], |
| 31 | + [10.1015625 23.71875 13.6171875; |
28 | 32 | 14.09375 32.875 18.78125;
|
29 | 33 | 11.0390625 25.59375 14.5546875], dims=3) ≈ B
|
30 |
| - # Issue #395 |
31 |
| - img1 = colorview(RGB, fill(0.9, 3, 5, 5)) |
32 |
| - img2 = colorview(RGB, fill(N0f8(0.9), 3, 5, 5)) |
33 |
| - @test isapprox(channelview(restrict(img1)), channelview(restrict(img2)), rtol=0.01) |
34 |
| - # Non-1 indices |
35 |
| - Ao = OffsetArray(A, (-2,1,0)) |
36 |
| - @test parent(@inferred(restrict(Ao, 1))) == restrict(A, 1) |
37 |
| - @test parent(@inferred(restrict(Ao, 2))) == restrict(A, 2) |
38 |
| - @test parent(@inferred(restrict(Ao, (1,2)))) == restrict(A, (1,2)) |
39 |
| - # Arrays-of-arrays |
40 |
| - a = Vector{Int}[[3,3,3], [2,1,7],[-11,4,2]] |
41 |
| - @test restrict(a) == Vector{Float64}[[2,3.5/2,6.5/2], [-5,4.5/2,5.5/2]] |
42 |
| - # Images issue #652 |
43 |
| - img = testimage("cameraman") |
44 |
| - @test eltype(@inferred(restrict(img))) == Gray{Float32} |
45 |
| - img = testimage("mandrill") |
46 |
| - @test eltype(@inferred(restrict(img))) == RGB{Float32} |
47 |
| - @test eltype(@inferred(restrict(Lab.(img)))) == RGB{Float32} |
48 |
| - img = rand(RGBA{N0f8}, 11, 11) |
49 |
| - @test eltype(@inferred(restrict(img))) == RGBA{Float32} |
50 |
| - @test eltype(@inferred(restrict(LabA.(img)))) == ARGB{Float32} |
| 34 | + end |
| 35 | + |
| 36 | + @testset "OffsetArray" begin |
| 37 | + A = rand(5, 4, 3) |
| 38 | + Ao = OffsetArray(A, (-2,1,0)) |
| 39 | + @test parent(@inferred(restrict(Ao, 1))) == restrict(A, 1) |
| 40 | + @test parent(@inferred(restrict(Ao, 2))) == restrict(A, 2) |
| 41 | + @test parent(@inferred(restrict(Ao, (1,2)))) == restrict(A, (1,2)) |
| 42 | + end |
| 43 | + |
| 44 | + @testset "FixedPoint overflow" begin |
| 45 | + # issue https://github.com/JuliaImages/Images.jl/issues/395 |
| 46 | + img1 = colorview(RGB, fill(0.9, 3, 5, 5)) |
| 47 | + img2 = colorview(RGB, fill(N0f8(0.9), 3, 5, 5)) |
| 48 | + @test isapprox(channelview(restrict(img1)), channelview(restrict(img2)), rtol=0.01) |
| 49 | + end |
| 50 | + |
| 51 | + @testset "Array of arrays" begin |
| 52 | + a = Vector{Int}[[3,3,3], [2,1,7],[-11,4,2]] |
| 53 | + @test restrict(a) == Vector{Float64}[[2,3.5/2,6.5/2], [-5,4.5/2,5.5/2]] |
| 54 | + end |
| 55 | + |
| 56 | + @testset "various colorant" begin |
| 57 | + # issue https://github.com/JuliaImages/Images.jl/issues/652 |
| 58 | + img = testimage("cameraman") |
| 59 | + @test eltype(@inferred(restrict(img))) == Gray{Float32} |
| 60 | + img = testimage("mandrill") |
| 61 | + @test eltype(@inferred(restrict(img))) == RGB{Float32} |
| 62 | + @test eltype(@inferred(restrict(Lab.(img)))) == RGB{Float32} |
| 63 | + img = rand(RGBA{N0f8}, 11, 11) |
| 64 | + @test eltype(@inferred(restrict(img))) == RGBA{Float32} |
| 65 | + @test eltype(@inferred(restrict(LabA.(img)))) == ARGB{Float32} |
| 66 | + |
| 67 | + ori = repeat(distinguishable_colors(10), inner=(1, 10)) |
| 68 | + for T in ( |
| 69 | + RGB, BGR, RGBX, XRGB, |
| 70 | + ARGB, RGBA, |
| 71 | + RGB24, ARGB32, |
| 72 | + ) |
| 73 | + img = T.(ori) |
| 74 | + out = @inferred restrict(img) |
| 75 | + if T == RGB24 |
| 76 | + @test eltype(out) == RGB{Float32} |
| 77 | + elseif T == ARGB32 |
| 78 | + @test eltype(out) == ARGB{Float32} |
| 79 | + else |
| 80 | + @test eltype(out) <: T |
| 81 | + end |
| 82 | + ref = restrict(ori) |
| 83 | + @test ref ≈ RGB.(out) |
| 84 | + end |
| 85 | + for T in (Gray, AGray, GrayA, Gray24) |
| 86 | + img = T.(ori) |
| 87 | + out = @inferred restrict(img) |
| 88 | + if T == Gray24 |
| 89 | + @test eltype(out) == Gray{Float32} |
| 90 | + else |
| 91 | + @test eltype(out) <: T |
| 92 | + end |
| 93 | + ref = restrict(Gray.(ori)) |
| 94 | + @test ref ≈ Gray.(out) |
| 95 | + end |
| 96 | + end |
51 | 97 | end
|
0 commit comments