Skip to content

Commit 9cb3891

Browse files
committed
make MaskMulti more convenient
1 parent ae68fdc commit 9cb3891

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

src/items/mask.jl

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,22 @@ mask = MaskMulti(rand(1:3, 100, 100))
1616
showitem(mask)
1717
```
1818
"""
19-
struct MaskMulti{N, T, B} <: AbstractArrayItem{N, T}
19+
struct MaskMulti{N, T<:Integer, U, B} <: AbstractArrayItem{N, T}
2020
data::AbstractArray{T, N}
21-
classes::AbstractVector{T}
21+
classes::AbstractVector{U}
2222
bounds::AbstractArray{<:SVector{N, B}, N}
2323
end
2424

2525

26-
function MaskMulti(a::AbstractArray, classes = unique(a), bounds = makebounds(size(a)))
27-
return MaskMulti(a, classes = bounds)
26+
function MaskMulti(a::AbstractArray, classes = unique(a))
27+
bounds = makebounds(size(a))
28+
minimum(a) >= 1 || error("Class values must start at 1")
29+
return MaskMulti(a, classes, bounds)
2830
end
2931

32+
MaskMulti(a::AbstractArray{<:Gray{T}}, args...) where T = MaskMulti(reinterpret(T, a), args...)
33+
MaskMulti(a::AbstractArray{<:Normed{T}}, args...) where T = MaskMulti(reinterpret(T, a), args...)
34+
3035
Base.show(io::IO, mask::MaskMulti{N, T}) where {N, T} =
3136
print(io, "MaskMulti{$N, $T}() with size $(size(itemdata(mask))) and $(length(mask.classes)) classes")
3237

@@ -125,9 +130,10 @@ end
125130

126131
function mask_extrapolation(
127132
mask::AbstractArray{T};
133+
t = T,
128134
degree = Constant(),
129135
boundary = Flat()) where T
130-
itp = interpolate(T, T, mask, BSpline(degree))
136+
itp = interpolate(t, t, mask, BSpline(degree))
131137
etp = extrapolate(itp, Flat())
132138
return etp
133139
end

src/preprocessing.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,7 @@ end
214214
function apply!(buf, tfm::OneHot{T}, item::MaskMulti; randstate = nothing) where T
215215
mask = itemdata(item)
216216
a = itemdata(buf)
217-
@show a[1:6]
218217
fill!(a, zero(T))
219-
@show a[1:6]
220218

221219
for I in CartesianIndices(mask)
222220
a[I, mask[I]] = one(T)

src/projective/base.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function apply(tfm::ProjectiveTransform, item::Item; randstate = getrandstate(tf
6767
bounds = getbounds(item)
6868
P = getprojection(tfm, bounds; randstate = randstate)
6969
indices = cropindices(tfm, P, bounds; randstate = randstate)
70-
return project(P, item, indices)
70+
return P isa IdentityTransformation ? item : project(P, item, indices)
7171
end
7272

7373
# For the buffered version, `project!` is used. Of course the size

src/projective/crop.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ struct Crop{N, F<:CropFrom} <: AbstractCrop
1313
from::F
1414
end
1515

16+
Crop(sz) = Crop(sz, FromOrigin())
17+
1618

1719

1820
function apply(crop::Crop, item::Item; randstate = getrandstate(crop))

0 commit comments

Comments
 (0)