Skip to content

Commit

Permalink
Merge pull request #55 from JuliaImages/teh/perf_transform
Browse files Browse the repository at this point in the history
Precompute lookup for N0f8
  • Loading branch information
zygmuntszpak authored Sep 22, 2021
2 parents d545b4e + 114d9b9 commit b3e7330
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
name = "ImageContrastAdjustment"
uuid = "f332f351-ec65-5f6a-b3d1-319c6670881a"
authors = ["Dr. Zygmunt L. Szpak <zygmunt.szpak@gmail.com>"]
version = "0.3.9"
version = "0.3.10"

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

[compat]
ImageCore = "0.9"
ImageCore = "0.9.3"
ImageTransformations = "0.8.1, 0.9"
Parameters = "0.12"
julia = "1"
Expand Down
15 changes: 15 additions & 0 deletions src/algorithms/common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@ function transform_density!(out::GenericGrayImage, img::GenericGrayImage, edges:
map!(transform, out, img)
end

function transform_density!(out::GenericGrayImage, img::GenericGrayImage{T}, edges::AbstractRange, newvals::AbstractVector) where T<:Union{N0f8,AbstractGray{N0f8}}
# When dealing with 8-bit images, we can improve computational performance by precomputing the lookup table
# for how the intensities transform (there are only 256 calculations of intensities rather than `length(img)`
# calculations of intensities).
lookup = Vector{eltype(newvals)}(undef, 256)
invoke(transform_density!, Tuple{GenericGrayImage,GenericGrayImage,AbstractRange,AbstractVector},
lookup, zero(T):eps(T):oneunit(T), edges, newvals)
map!(out, img) do val
lookup[uint8val(val)+1]
end
end

uint8val(x::N0f8) = reinterpret(x)
uint8val(x::AbstractGray) = uint8val(gray(x))

function build_lookup(cdf, minval::T, maxval::T) where T
first_cdf = first(cdf)
# Scale the new intensity value to so that it lies in the range [minval, maxval].
Expand Down

2 comments on commit b3e7330

@zygmuntszpak
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/45393

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.3.10 -m "<description of version>" b3e73305a8b236248e1acce935b8e282d9bc8762
git push origin v0.3.10

Please sign in to comment.