1
1
using Colors, Statistics
2
2
3
- luminosity (c:: RGB{T} ) where {T} = (max (c. r, c. g, c. b) + min (c. r, c. g, c. b)) / 2.0
3
+ luminosity (c:: RGB{T} ) where {T} = (max (c. r, c. g, c. b) + min (c. r, c. g, c. b)) / 2.0f0
4
4
5
5
function lum_max (rgb_m)
6
- lum_max = 0.0
6
+ lum_max = 0.0f0
7
7
for pix in rgb_m
8
8
(lum_max > luminosity (pix)) || (lum_max = luminosity (pix))
9
9
end
10
10
lum_max
11
11
end
12
12
13
- function avg_lum (rgb_m, δ:: Number = 1e -10 )
14
- cumsum = 0.0
13
+ function avg_lum (rgb_m, δ:: Number = 1f -10 )
14
+ cumsum = 0.0f0
15
15
for pix in rgb_m
16
16
cumsum += log10 (δ + luminosity (pix))
17
17
end
20
20
21
21
function normalize_image (
22
22
rgb_m,
23
- a:: Float64 = 0.18 ,
23
+ a:: Float32 = 0.18f0 ,
24
24
lum:: Union{Number,Nothing} = nothing ,
25
- δ:: Number = 1e -10
25
+ δ:: Number = 1f -10
26
26
)
27
27
28
- (isnothing (lum) || lum ≈ 0.0 ) && (lum = avg_lum (rgb_m, δ))
29
- return rgb_m .* a .* (1.0 / lum)
28
+ (isnothing (lum) || lum ≈ 0.0f0 ) && (lum = avg_lum (rgb_m, δ))
29
+ return rgb_m .* a .* (1.0f0 / lum)
30
30
end
31
31
32
32
function clamp_image (img:: AbstractMatrix{T} ) where {T}
@@ -35,7 +35,7 @@ function clamp_image(img::AbstractMatrix{T}) where {T}
35
35
end
36
36
end
37
37
38
- function γ_correction (img:: AbstractMatrix{T} , γ:: Float64 = 1.0 , k:: Float64 = 1.0 ) where T
38
+ function γ_correction (img:: AbstractMatrix{T} , γ:: Float32 = 1.0f0 , k:: Float32 = 1.0f0 ) where T
39
39
return map (img) do c
40
40
return T (
41
41
floor (255 * c. r^ (1 / γ)),
@@ -46,8 +46,8 @@ function γ_correction(img::AbstractMatrix{T}, γ::Float64=1.0, k::Float64=1.0)
46
46
end
47
47
48
48
function tone_mapping (img;
49
- a:: Float64 = 0.18 ,
50
- γ:: Float64 = 1.0 ,
49
+ a:: Float32 = 0.18f0 ,
50
+ γ:: Float32 = 1.0f0 ,
51
51
lum:: Union{Number,Nothing} = nothing
52
52
)
53
53
img = normalize_image (img, a, lum)
0 commit comments