Skip to content

Adds deprecations for adjust_histogram(img, LinearStretching()) variants #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: adjust_intensity
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/ImageContrastAdjustment.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions src/algorithms/linear_stretching.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

"""
```
LinearStretching <: AbstractHistogramAdjustmentAlgorithm
LinearStretching <: AbstractIntensityAdjustmentAlgorithm
LinearStretching(; [src_minval], [src_maxval],
dst_minval=0, dst_maxval=1,
no_clamp=false)
Expand All @@ -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`].
Expand All @@ -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`
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
51 changes: 51 additions & 0 deletions src/deprecations.jl
Original file line number Diff line number Diff line change
@@ -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
Comment on lines +3 to +9
Copy link
Member

Choose a reason for hiding this comment

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

For these I think we can simplify it with

Suggested change
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
@deprecate adjust_histogram(img::AbstractArray, f::LinearStretching, args...; kwargs...) adjust_intensity(img, f, args...; kwargs...)

Copy link
Member Author

@zygmuntszpak zygmuntszpak Sep 12, 2021

Choose a reason for hiding this comment

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

It turns out that writing the longer variant is useful because I can then unify all the deprecation messages for the 3 types that need to change (LinearStretching, GammaCorrection and ContrastStretching) into one as follows:

function adjust_histogram!(img::Union{GenericGrayImage, AbstractArray{<:Color3}},
                           f::Union{LinearStretching, GammaCorrection, ContrastStretching},
                           args...; kwargs...)
    algo = typeof(f)
    depwarn("adjust_histogram!(img, $algo) is deprecated, use adjust_intensity!(img, $algo) instead", :adjust_histogram!)                       
    return adjust_intensity!(img, f, args...; kwargs...)                          
end

That should save us from a bunch of code duplication. What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

It's just that in this case we don't need to manually construct the depwarn message info:

const DeprecatedIntensityMethods = Union{LinearStretching, GammaCorrection, ContrastStretching}
@deprecate adjust_histogram(img::AbstractArray, f::DeprecatedIntensityMethods, args...; kwargs...) adjust_intensity(img, f, args...; kwargs...)


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