From 77c3b48b6686c78b51132d3f7225f554513c786c Mon Sep 17 00:00:00 2001 From: Zygmunt Szpak Date: Sun, 12 Sep 2021 09:52:18 +0930 Subject: [PATCH] Adds deprecations for adjust_histogram(img, LinearStretching()) variants --- src/ImageContrastAdjustment.jl | 1 + src/algorithms/linear_stretching.jl | 12 +++---- src/deprecations.jl | 51 +++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 6 deletions(-) create mode 100644 src/deprecations.jl diff --git a/src/ImageContrastAdjustment.jl b/src/ImageContrastAdjustment.jl index cecf6a8..6182a7f 100644 --- a/src/ImageContrastAdjustment.jl +++ b/src/ImageContrastAdjustment.jl @@ -27,6 +27,7 @@ include("algorithms/gamma_correction.jl") include("algorithms/matching.jl") include("algorithms/midway_equalization.jl") include("compat.jl") +include("deprecations.jl") export # main types and functions diff --git a/src/algorithms/linear_stretching.jl b/src/algorithms/linear_stretching.jl index dc482b0..096d3ad 100644 --- a/src/algorithms/linear_stretching.jl +++ b/src/algorithms/linear_stretching.jl @@ -1,7 +1,7 @@ """ ``` - LinearStretching <: AbstractHistogramAdjustmentAlgorithm + LinearStretching <: AbstractIntensityAdjustmentAlgorithm LinearStretching(; [src_minval], [src_maxval], dst_minval=0, dst_maxval=1, no_clamp=false) @@ -10,8 +10,8 @@ LinearStretching((src_minval, src_maxval) => nothing) LinearStretching(nothing => (dst_minval, dst_maxval)) - adjust_histogram([T,] img, f::LinearStretching) - adjust_histogram!([out,] img, f::LinearStretching) + adjust_intensity([T,] img, f::LinearStretching) + adjust_intensity!([out,] img, f::LinearStretching) ``` Returns an image where the range of the intensities spans the interval [`dst_minval`, `dst_maxval`]. @@ -31,7 +31,7 @@ f(x) = (x-A) \\frac{b-a}{B-A} + a. # Options -Various options for the parameters of the `adjust_histogram` and +Various options for the parameters of the `adjust_intensity` and `LinearStretching` type are described in more detail below. ## Choices for `img` @@ -70,7 +70,7 @@ using ImageContrastAdjustment, TestImages img = testimage("mandril_gray") # Stretches the contrast in `img` so that it spans the unit interval. -imgo = adjust_histogram(img, LinearStretching(dst_minval = 0, dst_maxval = 1)) +imgo = adjust_intensity(img, LinearStretching(dst_minval = 0, dst_maxval = 1)) ``` For convenience, Constructing a `LinearStretching` object using `Pair` is also supported @@ -91,7 +91,7 @@ LinearStretching((0.1, 0.9) => nothing) 1. W. Burger and M. J. Burge. *Digital Image Processing*. Texts in Computer Science, 2016. [doi:10.1007/978-1-4471-6684-9](https://doi.org/10.1007/978-1-4471-6684-9) """ -@with_kw struct LinearStretching{T} <: AbstractHistogramAdjustmentAlgorithm +@with_kw struct LinearStretching{T} <: AbstractIntensityAdjustmentAlgorithm src_minval::T = nothing src_maxval::T = nothing dst_minval::T = 0.0f0 diff --git a/src/deprecations.jl b/src/deprecations.jl new file mode 100644 index 0000000..d56ec84 --- /dev/null +++ b/src/deprecations.jl @@ -0,0 +1,51 @@ +using Base: depwarn + +function adjust_histogram(img::Union{GenericGrayImage, AbstractArray{<:Color3}}, + f::LinearStretching, + args...; kwargs...) + + depwarn("adjust_histogram(img, LinearStretching()) is deprecated, use adjust_intensity(img, LinearStretching()) instead", :adjust_histogram) + return adjust_intensity(img, f, args...;kwargs...) +end + +function adjust_histogram(type::Type{T}, + img, + f::LinearStretching, + args...; kwargs...) where T + + depwarn("adjust_histogram(::Type{T}, img, LinearStretching()) is deprecated, use adjust_intensity(::Type{T}, img, LinearStretching()) instead", :adjust_histogram) + return adjust_intensity(type, img, f, args...;kwargs...) +end + +function adjust_histogram(img::AbstractArray{T}, + f::LinearStretching, + args...; kwargs...) where T <: Colorant + depwarn("adjust_histogram!(img, LinearStretching()) is deprecated, use adjust_intensity(img, LinearStretching()) instead", :adjust_histogram) + return adjust_intensity(img, f, args...; kwargs...) +end + +function adjust_histogram(type::Type{T}, + img_sequence::Vector{<:AbstractArray}, + f::LinearStretching, + args...; kwargs...) where T + + depwarn("adjust_histogram!(::Type{T}, img_sequence, LinearStretching()) is deprecated, use adjust_intensity(::Type{T}, img_sequence, LinearStretching()) instead", :adjust_histogram) + return adjust_histogram!(type, img_sequence, f, args...; kwargs...) +end + +function adjust_histogram!(img::Union{GenericGrayImage, AbstractArray{<:Color3}}, + f::LinearStretching, + args...; kwargs...) + + depwarn("adjust_histogram!(img, LinearStretching()) is deprecated, use adjust_intensity!(img, LinearStretching()) instead", :adjust_histogram!) + return adjust_intensity!(img, f, args...; kwargs...) +end + +function adjust_histogram!(out_sequence::Vector{T}, + img_sequence, + f::LinearStretching, + args...; kwargs...) where T <: Union{GenericGrayImage, AbstractArray{<:Color3}} + + depwarn("adjust_histogram!(out_sequence, img_sequence, LinearStretching()) is deprecated, use adjust_intensity!(out_sequence, img_sequence, LinearStretching()) instead", :adjust_histogram!) + return adjust_intensity(out_sequence, img_sequence, f, args...; kwargs...) +end \ No newline at end of file