Skip to content

Commit c765f90

Browse files
committed
add Zoom affine transformation
1 parent cb34b5e commit c765f90

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

src/DataAugmentation.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export Item,
6666
Buffered,
6767
BufferedThreadsafe,
6868
OneHot,
69+
Zoom,
6970
apply,
7071
Reflect,
7172
FlipX,

src/projective/affine.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,26 @@ function getprojection(scale::ScaleFixed{N}, bounds; randstate = nothing) where
6363
end
6464

6565

66+
"""
67+
Zoom(scales = (1, 1.2)) <: ProjectiveTransform
68+
Zoom(distribution)
69+
70+
Zoom into an item by a factor chosen from the interval `scales`
71+
or `distribution`.
72+
"""
73+
struct Zoom{D<:Sampleable} <: ProjectiveTransform
74+
dist::D
75+
end
76+
77+
Zoom(scales::NTuple{2, T} = (1., 1.2)) where T = Zoom(Uniform(scales[1], scales[2]))
78+
79+
getrandstate(tfm::Zoom) = rand(tfm.dist)
80+
81+
function getprojection(tfm::Zoom, bounds::AbstractArray{<:SVector{N}}; randstate = getrandstate(tfm)) where N
82+
ratio = randstate
83+
return scaleprojection(ntuple(_ -> ratio, N))
84+
end
85+
6686
"""
6787
Rotate(γ)
6888
Rotate(γs)

src/projective/crop.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ end
9191

9292

9393
compose(tfm::ProjectiveTransform, crop::AbstractCrop) = CroppedProjectiveTransform(tfm, crop)
94+
compose(tfm::ProjectiveTransform, crop::CroppedProjectiveTransform) =
95+
CroppedProjectiveTransform(tfm |> crop.tfm, crop.crop)
9496

9597

9698

src/sequence.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,20 @@ after each other.
1111
1212
You should not use this explicitly. Instead use [`compose`](#).
1313
"""
14-
struct Sequence{T<:Tuple where N} <: Transform
14+
struct Sequence{T<:Tuple} <: Transform
1515
transforms::T
1616
end
1717

1818
Sequence(tfms...) = Sequence{typeof(tfms)}(tfms)
19+
Sequence(tfm::Transform) = tfm
1920

2021
getrandstate(seq::Sequence) = getrandstate.(seq.transforms)
2122

2223

2324
compose(tfm1::Transform, tfm2::Transform) = Sequence(tfm1, tfm2)
2425
compose(seq::Sequence, tfm::Transform) = Sequence(seq.transforms..., tfm)
2526
compose(seq::Sequence, ::Identity) = seq
27+
compose(tfm::Transform, seq::Sequence) = compose(tfm, seq.transforms...)
2628

2729

2830
function apply(seq::Sequence, items::Tuple; randstate = getrandstate(seq))

0 commit comments

Comments
 (0)