Skip to content

Commit

Permalink
feat: get_nlabel and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cpaniaguam committed Oct 22, 2024
1 parent 743e83b commit 70ea000
Show file tree
Hide file tree
Showing 3 changed files with 1,053 additions and 12 deletions.
28 changes: 23 additions & 5 deletions src/tilingutils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,29 @@ function get_image_peaks(arr, imgtype="uint8")
return (locs=locs, heights=heights)
end

function get_ice_labels(ref_img::Matrix{RGB{N0f8}}, tile, factor, relaxed_thresholds)
function get_ice_labels(ref_img::Matrix{RGB{N0f8}}, tile, factor, 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]
mask_ice_band_7 = cv[1] .< thresholds[1]
mask_ice_band_2 = cv[2] .> thresholds[2]
mask_ice_band_1 = cv[3] .> thresholds[3]
return mask_ice_band_7 .* mask_ice_band_2 .* mask_ice_band_1
end
end

function get_nlabel(
ref_img, morph_residue, tile, factor, possible_ice_threshold, band_7_threshold_relaxed
)
# filter b/c channels (landmasked channels 2 and 3) and compute peaks
b, c = [float64.(channelview(ref_img)[i, :, :])[tile...] .* factor for i in 2:3]
morph_residue = morph_residue[tile...]

b[b .< possible_ice_threshold] .= 0
c[c .< possible_ice_threshold] .= 0
pksb, pksc = get_image_peaks.([b, c])

!all(length.([pksb.locs, pksc.locs]) .> 2) && return 1

relaxed_thresholds = [band_7_threshold_relaxed, pksb.locs[2], pksc.locs[2]]
ice_labels = get_ice_labels(ref_img, tile, factor, relaxed_thresholds)
return StatsBase.mode(morph_residue[ice_labels])
end
22 changes: 15 additions & 7 deletions test/test-tilingutils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ using IceFloeTracker:
get_brighten_mask,
imbrighten,
get_image_peaks,
get_ice_labels
get_ice_labels,
get_nlabel
using Random
gots = get_optimal_tile_size

Expand Down Expand Up @@ -112,13 +113,20 @@ gots = get_optimal_tile_size
@test sum(h[1:5]) == 11
end

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]
morph_residue = readdlm("test_inputs/morph_residue_tile.csv", ',', Int)

@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

@testset "get_nlabel" begin
# regular use case applies landmask
@test get_nlabel(ref_img, morph_residue, tile, factor, 75, 10) == 1
end
end
Loading

0 comments on commit 70ea000

Please sign in to comment.