|
40 | 40 |
|
41 | 41 |
|
42 | 42 | function getprojection(scale::ScaleKeepAspect{N}, bounds; randstate = nothing) where N |
43 | | - ratio = maximum(scale.minlengths ./ length.(bounds.rs)) |
| 43 | + # Offset `minlengths` by 1 to avoid black border on one side |
| 44 | + ratio = maximum((scale.minlengths .+ 1) ./ length.(bounds.rs)) |
44 | 45 | upperleft = SVector{N, Float32}(minimum.(bounds.rs)) .- 1 |
45 | 46 | P = scaleprojection(Tuple(ratio for _ in 1:N)) |
46 | 47 | if upperleft != SVector(0, 0) |
47 | | - P = P ∘ Translation(-upperleft) |
| 48 | + P = P ∘ Translation(-upperleft) |
48 | 49 | end |
49 | 50 | return P |
50 | 51 | end |
51 | 52 |
|
52 | 53 | function projectionbounds(tfm::ScaleKeepAspect{N}, P, bounds::Bounds{N}; randstate = nothing) where N |
53 | 54 | origsz = length.(bounds.rs) |
54 | | - ratio = maximum(tfm.minlengths ./ origsz) |
55 | | - sz = round.(Int, ratio .* origsz) |
| 55 | + ratio = maximum((tfm.minlengths) ./ origsz) |
| 56 | + sz = floor.(Int,ratio .* origsz) |
56 | 57 | bounds_ = transformbounds(bounds, P) |
57 | | - return offsetcropbounds(sz, bounds_, ntuple(_ -> 1., N)) |
| 58 | + bs_ = offsetcropbounds(sz, bounds_, ntuple(_ -> 1., N)) |
| 59 | + return bs_ |
58 | 60 | end |
59 | 61 |
|
60 | 62 | """ |
|
71 | 73 |
|
72 | 74 |
|
73 | 75 | function getprojection(scale::ScaleFixed, bounds; randstate = nothing) |
74 | | - ratios = scale.sizes ./ length.(bounds.rs) |
| 76 | + ratios = (scale.sizes .+ 1) ./ length.(bounds.rs) |
75 | 77 | upperleft = SVector{2, Float32}(minimum.(bounds.rs)) .- 1 |
76 | 78 | P = scaleprojection(ratios) |
77 | 79 | if upperleft != SVector(0, 0) |
@@ -209,11 +211,12 @@ at one. |
209 | 211 | struct PinOrigin <: ProjectiveTransform end |
210 | 212 |
|
211 | 213 | function getprojection(::PinOrigin, bounds; randstate = nothing) |
212 | | - # TODO: translate by actual minimum x and y coordinates |
213 | | - return Translation((-SVector{2, Float32}(minimum.(bounds.rs))) .+ 1) |
| 214 | + p = (-SVector{2, Float32}(minimum.(bounds.rs))) .+ 1 |
| 215 | + P = Translation(p) |
| 216 | + return P |
214 | 217 | end |
215 | 218 |
|
216 | | -function apply(::PinOrigin, item::Union{Image, MaskMulti, MaskBinary}; randstate = nothing) |
| 219 | +function apply(::PinOrigin, item::Union{<:Image, <:MaskMulti, <:MaskBinary}; randstate = nothing) |
217 | 220 | item = @set item.data = parent(itemdata(item)) |
218 | 221 | item = @set item.bounds = Bounds(size(itemdata(item))) |
219 | 222 | return item |
|
229 | 232 | # This overwrites the default composition. |
230 | 233 |
|
231 | 234 | compose(cropped::CroppedProjectiveTransform, pin::PinOrigin) = Sequence(cropped, pin) |
| 235 | +compose(cropped::ComposedProjectiveTransform, pin::PinOrigin) = Sequence(cropped, pin) |
| 236 | +compose(cropped::ProjectiveTransform, pin::PinOrigin) = Sequence(cropped, pin) |
232 | 237 |
|
233 | 238 | # ## Resize crops |
234 | 239 |
|
|
0 commit comments