Skip to content

Commit

Permalink
feat: get_ice_labels + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cpaniaguam committed Oct 22, 2024
1 parent 0233872 commit 743e83b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
13 changes: 10 additions & 3 deletions src/tilingutils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,6 @@ function imhist(img, imgtype="uint8")
end

function get_image_peaks(arr, imgtype="uint8")
# TODO: add validation for arr: either uint8 0:255 or grayscale 0:1

_, heights = imhist(arr, imgtype)

locs, heights, _ = Peaks.findmaxima(heights)
Expand All @@ -277,5 +275,14 @@ function get_image_peaks(arr, imgtype="uint8")
order = sortperm(heights; rev=true)
locs, heights = locs[order], heights[order]

return locs, heights
return (locs=locs, heights=heights)
end

function get_ice_labels(ref_img::Matrix{RGB{N0f8}}, tile, factor, relaxed_thresholds)
cv = channelview(ref_img)
cv = [float64.(cv[i, :, :])[tile...] .* factor for i in 1:3]
mask_ice_band_7 = cv[1] .< relaxed_thresholds[1]
mask_ice_band_2 = cv[2] .> relaxed_thresholds[2]
mask_ice_band_1 = cv[3] .> relaxed_thresholds[3]
return mask_ice_band_7 .* mask_ice_band_2 .* mask_ice_band_1
end
13 changes: 12 additions & 1 deletion test/test-tilingutils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ using IceFloeTracker:
to_uint8,
get_brighten_mask,
imbrighten,
get_image_peaks
get_image_peaks,
get_ice_labels
using Random
gots = get_optimal_tile_size

Expand Down Expand Up @@ -110,4 +111,14 @@ gots = get_optimal_tile_size
@test sum(l[1:5]) == 324
@test sum(h[1:5]) == 11
end

@testset "get_ice_labels" begin
# regular use case applies landmask
ref_img = load(falsecolor_test_image_file)
tiles = get_tiles(ref_img; rblocks=8, cblocks=6)
tile = tiles[1]
factor = 255
thresholds = [10, 118, 120]
@test sum(get_ice_labels(ref_img, tile, 255, thresholds)) == 6515
end
end

0 comments on commit 743e83b

Please sign in to comment.