Skip to content
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

Update histeq #507

Closed
wants to merge 4 commits into from
Closed
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
30 changes: 23 additions & 7 deletions src/histogram_equalization.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
function to_uint8(arr::AbstractMatrix{T}) where {T<:AbstractFloat}
img = Int.(round.(arr, RoundNearestTiesAway))
img = clamp.(img, 0, 255)
return img
function to_uint8(arr::AbstractMatrix{T}) where {T<:Union{AbstractFloat,Int,Signed}}
return to_uint8.(arr)
end

function to_uint8(num::T) where {T<:Union{AbstractFloat,Int,Signed}}
num = Int(round(num, RoundNearestTiesAway))
return clamp(num, 0, 255)
end

function anisotropic_diffusion_3D(I)
Expand Down Expand Up @@ -198,7 +201,6 @@ function conditional_histeq(
entropy_threshold,
white_fraction_threshold,
)

return rgbchannels_equalized
end

Expand Down Expand Up @@ -266,6 +268,21 @@ function _get_false_color_cloudmasked(;
return channels
end

"""
rgb2gray_uint8(rgbchannels::Array{Float64, 3})

Convert an array of RGB channel data to grayscale in the range [0, 255].

For preprocessing_tiling: (equalized_gray=rgb2gray_uint8(rgbchannels), gammagreen=rgbchannels[:, :, 2]))
"""
function rgb2gray_uint8(rgbchannels)
# Could probably use Gray if image is in right format, but that is the challenge. CP
r, g, b = [to_uint8(rgbchannels[:, :, i]) for i in 1:3]
# Reusing the r array to store the equalized gray image
r .= to_uint8(0.2989 * r .+ 0.5870 * g .+ 0.1140 * b)
return r
end

"""
rgb2gray(img::Matrix{RGB{Float64}})

Expand Down Expand Up @@ -301,10 +318,9 @@ Parsimonious version of `imhist` that uses the maximum value of the image to det
"""
function imhistp(img)
nbins = nextpow(2, maximum(img) + 1)
return _imhist(img, 0:(nbins-1))
return _imhist(img, 0:(nbins - 1))
end


"""
histeq(img)
Histogram equalization of `img` according to [1].
Expand Down
Loading