Skip to content

Commit

Permalink
feat: add rgb2gray function to convert RGB channels to grayscale
Browse files Browse the repository at this point in the history
  • Loading branch information
cpaniaguam committed Nov 19, 2024
1 parent 34f75c6 commit 727b154
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/histogram_equalization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,18 @@ function get_rgb_channels(img)
return cat(redc, greenc, bluec; dims=3)
end

"""
rgb2gray(rgbchannels::Array{Float64, 3})
Convert an array of RGB channel data to grayscale in the range [0, 255].
"""
function rgb2gray(rgbchannels::Array{Float64,3})
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

function _process_image_tiles(
true_color_image,
clouds_red,
Expand Down Expand Up @@ -287,7 +299,7 @@ end
Histogram equalization of `img` using `nbins` bins.
"""
function histeq(img::S; nbins=64)::S where {S<:AbstractArray{<:Integer}}
return to_uint8(sk_exposure.equalize_hist(img, nbins=nbins) * 255)
return to_uint8(sk_exposure.equalize_hist(img; nbins=nbins) * 255)
end

function _imhist(img, rng)
Expand Down

0 comments on commit 727b154

Please sign in to comment.