-
Notifications
You must be signed in to change notification settings - Fork 48
/
convert.jl
76 lines (58 loc) · 1.79 KB
/
convert.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
"""
ConvertEltype <: Augmentor.Operation
Description
--------------
Convert the element type of the given array/image into the given
`eltype`. This operation is especially useful for converting
color images to grayscale (or the other way around). That said,
the operation is not specific to color types and can also be used
for numeric arrays (e.g. with separated channels).
Note that this is an element-wise convert function. Thus it can
not be used to combine or separate color channels. Use
[`SplitChannels`](@ref) or [`CombineChannels`](@ref) for those
purposes.
Usage
--------------
ConvertEltype(eltype)
Arguments
--------------
- **`eltype`** : The eltype of the resulting array/image.
See also
--------------
[`CombineChannels`](@ref), [`SplitChannels`](@ref), [`augment`](@ref)
Examples
--------------
```julia-repl
julia> using Augmentor, Colors
julia> A = rand(RGB, 10, 10) # three color channels
10×10 Array{RGB{Float64},2}:
[...]
julia> augment(A, ConvertEltype(Gray{Float32})) # convert to grayscale
10×10 Array{Gray{Float32},2}:
[...]
```
"""
struct ConvertEltype{T} <: Operation
eltype::Type{T}
end
@inline supports_lazy(::Type{<:ConvertEltype}) = true
function applyeager(op::ConvertEltype{T}, img::AbstractArray, param) where T
maybe_copy(convert(AbstractArray{T}, img))
end
function applylazy(op::ConvertEltype{T}, img::AbstractArray, param) where T
mappedarray(c->convert(T,c), img)
end
function showconstruction(io::IO, op::ConvertEltype)
print(io, typeof(op).name.name, '(')
_showcolor(io, op.eltype)
print(io, ')')
end
function Base.show(io::IO, op::ConvertEltype)
if get(io, :compact, false)
print(io, "Convert eltype to ")
_showcolor(io, op.eltype)
else
print(io, "Augmentor.")
showconstruction(io, op)
end
end