Skip to content

Commit

Permalink
Merge pull request #480 from WilhelmusLab/479-imbrighten
Browse files Browse the repository at this point in the history
479 imbrighten
  • Loading branch information
cpaniaguam authored Nov 11, 2024
2 parents b029564 + 7de87c3 commit 1a7842c
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/IceFloeTracker.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ include("branch.jl")
include("special_strels.jl")
include("tilingutils.jl")
include("histogram_equalization.jl")
include("imadjust.jl")
include("brighten.jl")
include("morph_fill.jl")
include("imcomplement.jl")
include("imadjust.jl")

function get_version_from_toml(pth=dirname(dirname(pathof(IceFloeTracker))))::VersionNumber
toml = TOML.parsefile(joinpath(pth, "Project.toml"))
Expand Down
28 changes: 28 additions & 0 deletions src/brighten.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""
get_brighten_mask(equalized_gray_reconstructed_img, gamma_green)
# Arguments
- `equalized_gray_reconstructed_img`: The equalized gray reconstructed image (uint8 in Matlab).
- `gamma_green`: The gamma value for the green channel (also uint8).
# Returns
Difference equalized_gray_reconstructed_img - gamma_green clamped between 0 and 255.
"""
function get_brighten_mask(equalized_gray_reconstructed_img, gamma_green)
return to_uint8(equalized_gray_reconstructed_img - gamma_green)
end

"""
imbrighten(img, brighten_mask, bright_factor)
Brighten the image using a mask and a brightening factor.
# Arguments
- `img`: The input image.
- `brighten_mask`: A mask indicating the pixels to brighten.
- `bright_factor`: The factor by which to brighten the pixels.
# Returns
- The brightened image.
"""
function imbrighten(img, brighten_mask, bright_factor)
img = Float64.(img)
brighten_mask = brighten_mask .> 0
img[brighten_mask] .= img[brighten_mask] * bright_factor
return img = to_uint8(img)
end
5 changes: 5 additions & 0 deletions src/histogram_equalization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ function to_uint8(arr::AbstractMatrix{T}) where {T<:AbstractFloat}
return img
end

function to_uint8(arr::AbstractMatrix{T}) where {T<:Integer}
img = clamp.(arr, 0, 255)
return img
end

function anisotropic_diffusion_3D(I)
rgbchannels = get_rgb_channels(I)

Expand Down
22 changes: 22 additions & 0 deletions test/test-brighten.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using IceFloeTracker: get_brighten_mask, imbrighten

@testset "brighten tests" begin
@testset "get_brighten_mask" begin
img = rand(0:255, 5, 5)
bumped_img = img .+ 1
mask = get_brighten_mask(img, bumped_img)
@test all(mask .== 0)
end

@testset "imbrighten tests" begin
img = [1 2; 3 4]
brighten_mask = [1 0; 1 0]

test_cases = [(1.25, [1 2; 4 4]), (0.1, [0 2; 0 4]), (0.9, img)]

for (bright_factor, expected_result) in test_cases
result = imbrighten(img, brighten_mask, bright_factor)
@test result == expected_result
end
end
end
2 changes: 1 addition & 1 deletion test/test-imadjust.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@testset "imadjust" begin
Random.seed!(123)
img = rand(0:255, 100, 100)
sum(IceFloeTracker.imadjust(img)) == 1291155
@test sum(IceFloeTracker.imadjust(img)) == 1291155
end

0 comments on commit 1a7842c

Please sign in to comment.