From 743e83b06edb0d4930dc621efe36276c00cd0230 Mon Sep 17 00:00:00 2001 From: Carlos Paniagua Date: Tue, 22 Oct 2024 11:44:23 -0400 Subject: [PATCH] feat: get_ice_labels + tests --- src/tilingutils.jl | 13 ++++++++++--- test/test-tilingutils.jl | 13 ++++++++++++- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/tilingutils.jl b/src/tilingutils.jl index 6adef23f..5add1007 100644 --- a/src/tilingutils.jl +++ b/src/tilingutils.jl @@ -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) @@ -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 \ No newline at end of file diff --git a/test/test-tilingutils.jl b/test/test-tilingutils.jl index 720ccac1..516a76cf 100644 --- a/test/test-tilingutils.jl +++ b/test/test-tilingutils.jl @@ -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 @@ -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 \ No newline at end of file