Skip to content

Commit

Permalink
Remove old deprecations, add new ones (#1038)
Browse files Browse the repository at this point in the history
  • Loading branch information
timholy authored Jul 23, 2023
1 parent 4854014 commit 7bdbc2a
Show file tree
Hide file tree
Showing 10 changed files with 228 additions and 1,737 deletions.
5 changes: 3 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Graphics = "0.4, 1.0"
ImageAxes = "0.6.9"
ImageBase = "0.1.5"
ImageBinarization = "0.2, 0.3"
ImageContrastAdjustment = "0.3.3"
ImageContrastAdjustment = "0.3.12"
ImageCore = "0.9.3, 0.10"
ImageCorners = "0.1.2"
ImageDistances = "0.2.5"
Expand All @@ -61,6 +61,7 @@ TiledIteration = "0.2, 0.3, 0.4, 0.5"
julia = "1.6"

[extras]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Expand All @@ -69,4 +70,4 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
TestImages = "5e47fb64-e119-507b-a336-dd2b206d9990"

[targets]
test = ["FFTW", "LinearAlgebra", "Random", "Suppressor", "Test", "TestImages"]
test = ["Aqua", "FFTW", "LinearAlgebra", "Random", "Suppressor", "Test", "TestImages"]
20 changes: 1 addition & 19 deletions src/Images.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,33 +48,17 @@ import FileIO: metadata
import Graphics: Point

include("compat.jl")
include("labeledarrays.jl")
include("algorithms.jl")
include("deprecations.jl")
include("edge.jl")

export
# types
ColorizedArray,

# macros
@test_approx_eq_sigma_eps,

# algorithms
imedge, # TODO: deprecate?
imgaussiannoise,
otsu_threshold,
yen_threshold,

#Exposure
imhist,
histeq,
adjust_gamma,
histmatch,
clahe,
imadjustintensity,
imstretch,
cliphist,

magnitude,
magnitude_phase,
Expand All @@ -85,10 +69,8 @@ export
thin_edges_nonmaxsup,
thin_edges_nonmaxsup_subpix,
canny,
gaussian_pyramid,
gaussian_pyramid

# phantoms
shepp_logan

"""
Images.jl is an "umbrella package" that exports a set of packages which are useful for
Expand Down
82 changes: 0 additions & 82 deletions src/algorithms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -120,85 +120,3 @@ function pyramid_scale(img::OffsetArray, downsample)
off = (.-ceil.(Int,(.-iterate.(map(x->UnitRange(x).-1,axes(img)))[1])./downsample))
OffsetArray(imresize(img, sz_next), off)
end

"""
```
thres = otsu_threshold(img)
thres = otsu_threshold(img, bins)
```
Computes threshold for grayscale image using Otsu's method.
Parameters:
- img = Grayscale input image
- bins = Number of bins used to compute the histogram. Needed for floating-point images.
"""
function otsu_threshold(img::AbstractArray{T, N}, bins::Int = 256) where {T<:Union{Gray,Real}, N}

min, max = extrema(img)
edges, counts = imhist(img, range(gray(min), stop=gray(max), length=bins))
histogram = counts./sum(counts)

ω0 = 0
μ0 = 0
μt = 0
μT = sum((1:(bins+1)).*histogram)
max_σb=0.0
thres=1

for t in 1:bins
ω0 += histogram[t]
ω1 = 1 - ω0
μt += t*histogram[t]

σb = (μT*ω0-μt)^2/(ω0*ω1)

if(σb > max_σb)
max_σb = σb
thres = t
end
end

return T((edges[thres-1]+edges[thres])/2)
end

"""
```
thres = yen_threshold(img)
thres = yen_threshold(img, bins)
```
Computes threshold for grayscale image using Yen's maximum correlation criterion for bilevel thresholding
Parameters:
- img = Grayscale input image
- bins = Number of bins used to compute the histogram. Needed for floating-point images.
#Citation
Yen J.C., Chang F.J., and Chang S. (1995) “A New Criterion for Automatic Multilevel Thresholding” IEEE Trans. on Image Processing, 4(3): 370-378. DOI:10.1109/83.366472
"""
function yen_threshold(img::AbstractArray{T, N}, bins::Int = 256) where {T<:Union{Gray, Real}, N}

min, max = extrema(img)
if(min == max)
return T(min)
end

edges, counts = imhist(img, range(gray(min), stop=gray(max), length=bins))

prob_mass_function = counts./sum(counts)
clamp!(prob_mass_function,eps(),Inf)
prob_mass_function_sq = prob_mass_function.^2
cum_pmf = cumsum(prob_mass_function)
cum_pmf_sq_1 = cumsum(prob_mass_function_sq)
cum_pmf_sq_2 = reverse!(cumsum(reverse!(prob_mass_function_sq)))

#Equation (4) cited in the paper.
criterion = log.(((cum_pmf[1:end-1].*(1.0 .- cum_pmf[1:end-1])).^2) ./ (cum_pmf_sq_1[1:end-1].*cum_pmf_sq_2[2:end]))

thres = edges[findmax(criterion)[2]]
return T(thres)

end
Loading

0 comments on commit 7bdbc2a

Please sign in to comment.