Skip to content

Commit b3e7330

Browse files
authored
Merge pull request #55 from JuliaImages/teh/perf_transform
Precompute lookup for N0f8
2 parents d545b4e + 114d9b9 commit b3e7330

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
name = "ImageContrastAdjustment"
22
uuid = "f332f351-ec65-5f6a-b3d1-319c6670881a"
33
authors = ["Dr. Zygmunt L. Szpak <zygmunt.szpak@gmail.com>"]
4-
version = "0.3.9"
4+
version = "0.3.10"
55

66
[deps]
77
ImageCore = "a09fc81d-aa75-5fe9-8630-4744c3626534"
88
ImageTransformations = "02fcd773-0e25-5acc-982a-7f6622650795"
99
Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a"
1010

1111
[compat]
12-
ImageCore = "0.9"
12+
ImageCore = "0.9.3"
1313
ImageTransformations = "0.8.1, 0.9"
1414
Parameters = "0.12"
1515
julia = "1"

src/algorithms/common.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,21 @@ function transform_density!(out::GenericGrayImage, img::GenericGrayImage, edges:
1717
map!(transform, out, img)
1818
end
1919

20+
function transform_density!(out::GenericGrayImage, img::GenericGrayImage{T}, edges::AbstractRange, newvals::AbstractVector) where T<:Union{N0f8,AbstractGray{N0f8}}
21+
# When dealing with 8-bit images, we can improve computational performance by precomputing the lookup table
22+
# for how the intensities transform (there are only 256 calculations of intensities rather than `length(img)`
23+
# calculations of intensities).
24+
lookup = Vector{eltype(newvals)}(undef, 256)
25+
invoke(transform_density!, Tuple{GenericGrayImage,GenericGrayImage,AbstractRange,AbstractVector},
26+
lookup, zero(T):eps(T):oneunit(T), edges, newvals)
27+
map!(out, img) do val
28+
lookup[uint8val(val)+1]
29+
end
30+
end
31+
32+
uint8val(x::N0f8) = reinterpret(x)
33+
uint8val(x::AbstractGray) = uint8val(gray(x))
34+
2035
function build_lookup(cdf, minval::T, maxval::T) where T
2136
first_cdf = first(cdf)
2237
# Scale the new intensity value to so that it lies in the range [minval, maxval].

0 commit comments

Comments
 (0)