-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into 493-get_new23-final
- Loading branch information
Showing
11 changed files
with
343 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# TODO: make imadjust more general to work with Gray{Float64} and RGB{Float64} types | ||
""" | ||
imadjust(img; low, high) | ||
Adjust the contrast of an image using linear stretching. The image is normalized to [0, 1] and then stretched to the range [low, high]. | ||
# Arguments | ||
- `img`: The input image. | ||
- `low`: The lower bound of the stretched image. Default is 0.01. | ||
- `high`: The upper bound of the stretched image. Default is 0.99. | ||
# Returns | ||
The contrast-adjusted image in the range [0, 255]. | ||
""" | ||
function imadjust( | ||
img::AbstractArray{<:Integer}; low::T=0.01, high::T=0.99 | ||
)::Matrix{Int} where {T<:AbstractFloat} | ||
img = img ./ 255 | ||
imgflat = vec(img) | ||
plow = StatsBase.percentile(imgflat, low * 100) | ||
phigh = StatsBase.percentile(imgflat, high * 100) | ||
|
||
f = LinearStretching((plow, phigh) => (0.0, 1.0)) | ||
|
||
return to_uint8(adjust_histogram(img, f) * 255) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
@testset "imadjust" begin | ||
Random.seed!(123) | ||
img = rand(0:255, 100, 100) | ||
@test sum(IceFloeTracker.imadjust(img)) == 1291155 | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.