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

479 imbrighten #480

Merged
merged 9 commits into from
Nov 11, 2024
Merged
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
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")
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the CI fails because of this deletion. Maybe keep the include("imadjust.jl") and add include("brighten.jl")? It looks like there is still an imadjust.jl script, suggesting that maybe we need both?

Copy link
Member Author

Choose a reason for hiding this comment

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

Must have done that trying to resolve merge conflicts. I think it's fixed now. Thanks.

include("brighten.jl")
include("morph_fill.jl")
include("imcomplement.jl")
include("imadjust.jl")

const sk_measure = PyNULL()
const sk_exposure = PyNULL()
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
Loading