phenocamr icon indicating copy to clipboard operation
phenocamr copied to clipboard

Hue (HSV) based snow flagging

Open khufkens opened this issue 4 years ago • 2 comments

A Hue based filter performs well in finding images with snow and cloud contamination, even on average daily values across an ROI (no image processing needed).

# HSV based snow flagging
library(phenocamr)
library(tidyverse)

if(!file.exists(file.path(tempdir(),"chibougamau_EN_1000_1day.csv"))){
  download_phenocam(site = "chibougamau",
                    out_dir = tempdir(),
                    frequency = 1,
                    roi_id = 1000)
}

# read data
df <- read.table(file.path(tempdir(),"chibougamau_EN_1000_1day.csv"),
                 sep = ",",
                 header = TRUE,
                 stringsAsFactors = FALSE)

df <- df %>% filter(!is.na(r_mean))

hsv <- rgb2hsv(df$r_mean, df$g_mean, df$b_mean)

df$snow_flag <- ifelse(hsv[1,] > 0.55 & hsv[1,] < 0.97,"snow","no snow")

p <- ggplot(df) +
  geom_point(aes(as.Date(date), gcc_90, col = as.factor(snow_flag))) +
  theme_minimal()

print(p)

snow_flags

khufkens avatar Mar 05 '20 15:03 khufkens