Created
August 28, 2021 10:40
-
-
Save csaybar/a2f694dadc068fb2c4fa2e716dcedd7d to your computer and use it in GitHub Desktop.
<<<<<<<<<>>>>>>>>>>><
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
# thin cloud - edges | |
ly05 <- npfiles[,,5] * 5 | |
base[] <- ly05 | |
ly05 <- base | |
# shadow - center | |
ly06 <- npfiles[,,6] * 6 | |
base[] <- ly06 | |
ly06 <- base | |
# shadow - edges | |
ly07 <- npfiles[,,7] * 7 | |
base[] <- ly07 | |
ly07 <- 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