Skip to content

Instantly share code, notes, and snippets.

@csaybar
Created August 28, 2021 10:41
Show Gist options
  • Save csaybar/dc80d721965f54714a128f8e06dbabd9 to your computer and use it in GitHub Desktop.
Save csaybar/dc80d721965f54714a128f8e06dbabd9 to your computer and use it in GitHub Desktop.
<<<<<<<<<<>>>>>>>>>>>>>
library(jsonlite)
library(reticulate)
library(raster)
np <- import("numpy")
save_manual_labeling_scribble <- function(point, output) {
points_x <- list.files(
path = sprintf("%s/%s.iris/segmentation", point, basename(point)),
pattern = "2_final\\.npy",
full.names = TRUE,
recursive = TRUE
)
points_xx <- list.files(
path = sprintf("%s/%s.iris/segmentation", point, basename(point)),
pattern = "2_user\\.npy",
full.names = TRUE,
recursive = TRUE
)
base <- raster(list.files(
path = point,
pattern = "angle\\.tif",
full.names = TRUE,
recursive = TRUE
)[1])
create_r <- function(input_user, input_seg, base) {
base2 <- base
npfiles <- np$load(input_seg)
npfiles_clear <- np$load(input_user)
# clear
ly01 <- npfiles[,,1] * 1
base[] <- npfiles_clear*1
base2[] <- ly01
ly01 <- base * base2
# thick cloud - center
ly02 <- npfiles[,,2] * 2
base[] <- ly02
ly02 <- base
# thick cloud - edges
ly03 <- npfiles[,,3] * 3
base[] <- ly03
ly03 <- base
# thin cloud - center
ly04 <- npfiles[,,4] * 4
base[] <- ly04
ly04 <- base
layers <- ly01 + ly02 + ly03 + ly04 + ly05 + ly06 + ly07
layers
}
for (index in 1:5) {
input_user <- points_xx[index]
input_seg <- points_x[index]
image_name <- basename(dirname(points_x[index]))
point_name <- points_x[index] %>%
dirname() %>%
dirname() %>%
dirname() %>%
dirname() %>%
basename()
raster_r <- create_r(input_user = input_user, input_seg = input_seg, base = base)
names <- sprintf("%s/%s__%s__scribble.tif", output, point_name, image_name)
writeRaster(x = raster_r, filename = names, overwrite = TRUE)
}
}
# FOLDER WITH SCRIBBLE LABELS
PATH <- "/home/csaybar/Desktop/dd/"
# FOLDER TO SAVE
points <- list.files(PATH, full.names = TRUE)
for (point in points) {
print(paste0("POINT:", basename(points)))
save_manual_labeling_scribble(point, output)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment