Skip to content

Commit 3f63255

Browse files
committed
update projectionbounds to have nicer bounds and enable composing scaling transformations
1 parent 3dff4a8 commit 3f63255

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

src/projective/affine.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ end
7575
function getprojection(scale::ScaleFixed, bounds::Bounds{N}; randstate = nothing) where N
7676
# If no scaling needs to be done, return a noop transform
7777
(scale.sizes == length.(bounds.rs)) && return IdentityTransformation()
78-
78+
7979
ratios = (scale.sizes .+ 1) ./ length.(bounds.rs)
8080
upperleft = SVector{N, Float32}(minimum.(bounds.rs)) .- 1
8181
P = scaleprojection(ratios)
@@ -88,7 +88,7 @@ end
8888

8989
function projectionbounds(tfm::ScaleFixed{N}, P, bounds::Bounds{N}; randstate = nothing) where N
9090
bounds_ = transformbounds(bounds, P)
91-
return offsetcropbounds(tfm.sizes, bounds_, ntuple(_ -> 1., N))
91+
return offsetcropbounds(tfm.sizes, bounds_, ntuple(_ -> 0.5, N))
9292
end
9393

9494
"""

src/projective/compose.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,12 @@ function getprojection(
5454
end
5555

5656
function projectionbounds(composed::ComposedProjectiveTransform, P, bounds; randstate = getrandstate(composed))
57-
return transformbounds(bounds, P)
57+
@assert length(composed.tfms) == length(randstate)
58+
P = CoordinateTransformations.IdentityTransformation()
59+
for (tfm, r) in zip(composed.tfms, randstate)
60+
P_tfm = getprojection(tfm, bounds; randstate = r)
61+
bounds = projectionbounds(tfm, P_tfm, bounds; randstate = r)
62+
P = P_tfm P
63+
end
64+
return bounds
5865
end

test/projective/affine.jl

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,28 @@ include("../imports.jl")
8282
testprojective(tfm)
8383

8484
end
85+
8586
@testset ExtendedTestSet "ScaleRatio" begin
8687
tfm = ScaleRatio((1/2, 1/2))
8788
@test_nowarn apply(tfm, image)
8889
@test_nowarn apply(tfm, keypoints)
8990
timage = apply(tfm, image)
9091
tkeypoints = apply(tfm, keypoints)
9192
@test !any(isnan.(timage |> itemdata))
92-
@test getbounds(timage).rs == (2:26, 2:26)
93+
@test getbounds(timage).rs == (1:25, 1:25)
94+
@test getbounds(timage) == getbounds(tkeypoints)
95+
testprojective(tfm)
96+
end
97+
98+
@testset ExtendedTestSet "ScaleRatioTwice" begin
99+
tfm = ScaleRatio((4/5, 4/5)) |> ScaleRatio((1/2, 1/2))
100+
@show getbounds(image).rs
101+
@test_nowarn apply(tfm, image)
102+
@test_nowarn apply(tfm, keypoints)
103+
timage = apply(tfm, image)
104+
tkeypoints = apply(tfm, keypoints)
105+
@test !any(isnan.(timage |> itemdata))
106+
@test getbounds(timage).rs == (1:20, 1:20)
93107
@test getbounds(timage) == getbounds(tkeypoints)
94108
testprojective(tfm)
95109
end

0 commit comments

Comments
 (0)