Skip to content

Commit

Permalink
Changed reflectance to falsecolor
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmwatkins committed Nov 8, 2023
1 parent 290d7bd commit f4ccfeb
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 29 deletions.
8 changes: 4 additions & 4 deletions src/cloudmask.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""
create_cloudmask(reflectance_image; prelim_threshold, band_7_threshold, band_2_threshold, ratio_lower, ratio_upper)
create_cloudmask(falsecolor_image; prelim_threshold, band_7_threshold, band_2_threshold, ratio_lower, ratio_upper)
Convert a 3-channel false color reflectance image to a 1-channel binary matrix; clouds = 0, else = 1. Default thresholds are defined in the published Ice Floe Tracker article: Remote Sensing of the Environment 234 (2019) 111406.
# Arguments
- `reflectance_image`: corrected reflectance false color image - bands [7,2,1]
- `falsecolor_image`: corrected reflectance false color image - bands [7,2,1]
- `prelim_threshold`: threshold value used to identify clouds in band 7, N0f8(RGB intensity/255)
- `band_7_threshold`: threshold value used to identify cloud-ice in band 7, N0f8(RGB intensity/255)
- `band_2_threshold`: threshold value used to identify cloud-ice in band 2, N0f8(RGB intensity/255)
Expand Down Expand Up @@ -41,12 +41,12 @@ function create_cloudmask(
end

"""
apply_cloudmask(reflectance_image, cloudmask)
apply_cloudmask(ref_image, cloudmask)
Zero out pixels containing clouds where clouds and ice are not discernable. Arguments should be of the same size.
# Arguments
- `reference_image`: corrected reflectance false color image - bands [7,2,1] or grayscale
- `ref_image`: reference image, e.g. corrected reflectance false color image bands [7,2,1] or grayscale
- `cloudmask`: binary cloudmask with clouds = 0, else = 1
"""
Expand Down
12 changes: 6 additions & 6 deletions src/find_ice_labels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ function find_reflectance_peaks(
end

"""
find_ice_labels(reflectance_image, landmask; band_7_threshold, band_2_threshold, band_1_threshold, band_7_relaxed_threshold, band_1_relaxed_threshold, possible_ice_threshold)
find_ice_labels(falsecolor_image, landmask; band_7_threshold, band_2_threshold, band_1_threshold, band_7_relaxed_threshold, band_1_relaxed_threshold, possible_ice_threshold)
Locate the pixels of obvious ice from false color reflectance image. Returns a binary mask with ice floes contrasted from background. Default thresholds are defined in the published Ice Floe Tracker article: Remote Sensing of the Environment 234 (2019) 111406.
Locate the pixels of likely ice from false color reflectance image. Returns a binary mask with ice floes contrasted from background. Default thresholds are defined in the published Ice Floe Tracker article: Remote Sensing of the Environment 234 (2019) 111406.
# Arguments
- `reflectance_image`: corrected reflectance false color image - bands [7,2,1]
- `falsecolor_image`: corrected reflectance false color image - bands [7,2,1]
- `landmask`: bitmatrix landmask for region of interest
- `band_7_threshold`: threshold value used to identify ice in band 7, N0f8(RGB intensity/255)
- `band_2_threshold`: threshold value used to identify ice in band 2, N0f8(RGB intensity/255)
Expand All @@ -44,7 +44,7 @@ Locate the pixels of obvious ice from false color reflectance image. Returns a b
"""
function find_ice_labels(
reflectance_image::Matrix{RGB{Float64}},
falsecolor_image::Matrix{RGB{Float64}},
landmask::BitMatrix;
band_7_threshold::Float64=Float64(5 / 255),
band_2_threshold::Float64=Float64(230 / 255),
Expand All @@ -55,7 +55,7 @@ function find_ice_labels(
)::Vector{Int64}

## Make ice masks
cv = channelview(reflectance_image)
cv = channelview(falsecolor_image)

mask_ice_band_7 = @view(cv[1, :, :]) .< band_7_threshold #5 / 255
mask_ice_band_2 = @view(cv[2, :, :]) .> band_2_threshold #230 / 255
Expand All @@ -64,7 +64,7 @@ function find_ice_labels(
ice_labels = remove_landmask(landmask, ice)
# @info "Done with masks" # to uncomment when logger is added

## Find obvious ice floes
## Find likely ice floes
if sum(abs.(ice_labels)) == 0
mask_ice_band_7 = @view(cv[1, :, :]) .< band_7_threshold_relaxed #10 / 255
mask_ice_band_1 = @view(cv[3, :, :]) .> band_1_threshold_relaxed #190 / 255
Expand Down
22 changes: 11 additions & 11 deletions src/ice-water-discrimination.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
discriminate_ice_water(
reflectance_image::Matrix{RGB{Float64}},
falsecolor_image::Matrix{RGB{Float64}},
normalized_image::Matrix{Gray{Float64}},
landmask_bitmatrix::T,
cloudmask_bitmatrix::T,
Expand All @@ -19,16 +19,16 @@
Generates an image with ice floes apparent after filtering and combining previously processed versions of reflectance and truecolor images from the same region of interest. Returns an image ready for segmentation to isolate floes.
Generates an image with ice floes apparent after filtering and combining previously processed versions of falsecolor and truecolor images from the same region of interest. Returns an image ready for segmentation to isolate floes.
Note: This function mutates the landmask object to avoid unnecessary memory allocation. If you need the original landmask, make a copy before passing it to this function. Example: `discriminate_ice_water(reflectance_image, normalized_image, copy(landmask_bitmatrix), cloudmask_bitmatrix)`
Note: This function mutates the landmask object to avoid unnecessary memory allocation. If you need the original landmask, make a copy before passing it to this function. Example: `discriminate_ice_water(falsecolor_image, normalized_image, copy(landmask_bitmatrix), cloudmask_bitmatrix)`
# Arguments
- `reflectance_image`: input image in false color reflectance
- `falsecolor_image`: input image in false color reflectance
- `normalized_image`: normalized version of true color image
- `landmask_bitmatrix`: landmask for region of interest
- `cloudmask_bitmatrix`: cloudmask for region of interest
- `floes_threshold`: heuristic applied to original reflectance image
- `floes_threshold`: heuristic applied to original false color image
- `mask_clouds_lower`: lower heuristic applied to mask out clouds
- `mask_clouds_upper`: upper heuristic applied to mask out clouds
- `kurt_thresh_lower`: lower heuristic used to set pixel value threshold based on kurtosis in histogram
Expand All @@ -42,7 +42,7 @@ Note: This function mutates the landmask object to avoid unnecessary memory allo
"""
function discriminate_ice_water(
reflectance_image::Matrix{RGB{Float64}},
falsecolor_image::Matrix{RGB{Float64}},
normalized_image::Matrix{Gray{Float64}},
landmask_bitmatrix::T,
cloudmask_bitmatrix::T,
Expand All @@ -59,16 +59,16 @@ function discriminate_ice_water(
nbins::Real=155,
)::AbstractMatrix where {T<:AbstractArray{Bool}}
clouds_channel = IceFloeTracker.create_clouds_channel(
cloudmask_bitmatrix, reflectance_image
cloudmask_bitmatrix, falsecolor_image
)
reflectance_image_band7 = @view(channelview(reflectance_image)[1, :, :])
falsecolor_image_band7 = @view(channelview(falsecolor_image)[1, :, :])

# first define all of the image variations
image_clouds = IceFloeTracker.apply_landmask(clouds_channel, landmask_bitmatrix) # output during cloudmask apply, landmasked
image_cloudless = IceFloeTracker.apply_landmask(
reflectance_image_band7, landmask_bitmatrix
) # channel 1 (band 7) from source reflectance image, landmasked
image_floes = IceFloeTracker.apply_landmask(reflectance_image, landmask_bitmatrix) # source reflectance, landmasked
falsecolor_image_band7, landmask_bitmatrix
) # channel 1 (band 7) from source falsecolor image, landmasked
image_floes = IceFloeTracker.apply_landmask(falsecolor_image, landmask_bitmatrix) # source false color reflectance, landmasked
image_floes_view = channelview(image_floes)

floes_band_2 = @view(image_floes_view[2, :, :])
Expand Down
4 changes: 2 additions & 2 deletions test/config.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
test_data_dir = "./test_inputs"
test_output_dir = "./test_outputs"
truecolor_test_image_file = "$(test_data_dir)/NE_Greenland_truecolor.2020162.aqua.250m.tiff"
reflectance_test_image_file = "$(test_data_dir)/NE_Greenland_reflectance.2020162.aqua.250m.tiff"
reflectance_b7_test_file = "$(test_data_dir)/ref_image_b7.png"
falsecolor_test_image_file = "$(test_data_dir)/NE_Greenland_reflectance.2020162.aqua.250m.tiff"
falsecolor_b7_test_file = "$(test_data_dir)/ref_image_b7.png"
landmask_file = "$(test_data_dir)/landmask.tiff"
landmask_no_dilate_file = "$(test_data_dir)/landmask_no_dilate.png"
current_landmask_file = "$(test_data_dir)/current_landmask.png"
Expand Down
6 changes: 3 additions & 3 deletions test/test-discrim-ice-water.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
println("------------------------------------------------")
println("------------ Create Ice-Water Discrimination Test --------------")
input_image = float64.(load(truecolor_test_image_file)[test_region...])
reflectance_image = float64.(load(reflectance_test_image_file)[test_region...])
falsecolor_image = float64.(load(falsecolor_test_image_file)[test_region...])
landmask = convert(BitMatrix, load(current_landmask_file))
landmask_no_dilate = convert(BitMatrix, float64.(load(landmask_no_dilate_file)))
cloudmask = IceFloeTracker.create_cloudmask(reflectance_image)
cloudmask = IceFloeTracker.create_cloudmask(falsecolor_image)
matlab_ice_water_discrim =
float64.(load("$(test_data_dir)/matlab_ice_water_discrim.png"))

Expand All @@ -15,7 +15,7 @@
image_sharpened, image_sharpened_gray, landmask
)
ice_water_discrim = IceFloeTracker.discriminate_ice_water(
reflectance_image, normalized_image, landmask, cloudmask
falsecolor_image, normalized_image, landmask, cloudmask
)
@test (@test_approx_eq_sigma_eps ice_water_discrim matlab_ice_water_discrim [0, 0] 0.065) ==
nothing
Expand Down
6 changes: 3 additions & 3 deletions test/test-find-ice-labels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
println("------------------------------------------------")
println("------------ Create Ice Labels Test --------------")

reflectance_image = float64.(load(reflectance_test_image_file)[test_region...])
falsecolor_image = float64.(load(falsecolor_test_image_file)[test_region...])
landmask = convert(BitMatrix, load(current_landmask_file))
ice_labels_matlab = DelimitedFiles.readdlm(
"$(test_data_dir)/ice_labels_matlab.csv", ','
)
ice_labels_matlab = vec(ice_labels_matlab)

@time ice_labels_julia = IceFloeTracker.find_ice_labels(reflectance_image, landmask)
@time ice_labels_julia = IceFloeTracker.find_ice_labels(falsecolor_image, landmask)

DelimitedFiles.writedlm("ice_labels_julia.csv", ice_labels_julia, ',')

@test ice_labels_matlab == ice_labels_julia

@time ice_labels_ice_floe_region = IceFloeTracker.find_ice_labels(
reflectance_image[ice_floe_test_region...], landmask[ice_floe_test_region...]
falsecolor_image[ice_floe_test_region...], landmask[ice_floe_test_region...]
)

DelimitedFiles.writedlm("ice_labels_floe_region.csv", ice_labels_ice_floe_region, ',')
Expand Down

0 comments on commit f4ccfeb

Please sign in to comment.