Skip to content
This repository has been archived by the owner on Jan 14, 2025. It is now read-only.

Commit

Permalink
Merge branch 'dev' into dev_3
Browse files Browse the repository at this point in the history
  • Loading branch information
Claudius-Appel committed Aug 28, 2024
2 parents 9e57db5 + 90395ef commit deb514b
Show file tree
Hide file tree
Showing 52 changed files with 129 additions and 52 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: duflor.gui
Title: Frontend for duflor-package
Version: 1.0.4
Version: 1.0.5
Author: Claudius Appel
Authors@R: c(
person("Claudius", "Appel", email = "[email protected]" , role = c("aut", "cre"))
Expand Down
5 changes: 4 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ importFrom(DT,renderDataTable)
importFrom(doParallel,registerDoParallel)
importFrom(doParallel,stopImplicitCluster)
importFrom(dplyr,bind_rows)
importFrom(duflor,HSVtoRGB)
importFrom(duflor,apply_HSV_color_by_mask)
importFrom(duflor,extract_pixels_HSV)
importFrom(duflor,load_image)
Expand All @@ -23,10 +22,13 @@ importFrom(ggplot2,guides)
importFrom(ggplot2,labs)
importFrom(ggplot2,theme)
importFrom(ggplot2,theme_minimal)
importFrom(imager,HSVtoRGB)
importFrom(imager,RGBtosRGB)
importFrom(imager,display)
importFrom(imager,draw_rect)
importFrom(imager,grabRect)
importFrom(imager,height)
importFrom(imager,save.image)
importFrom(imager,width)
importFrom(magrittr,"%>%")
importFrom(openxlsx,write.xlsx)
Expand Down Expand Up @@ -103,6 +105,7 @@ importFrom(stringr,str_split)
importFrom(stringr,str_to_lower)
importFrom(stringr,str_to_upper)
importFrom(stringr,str_trim)
importFrom(tools,file_path_sans_ext)
importFrom(utils,hasName)
importFrom(utils,packageDescription)
importFrom(utils,write.csv2)
6 changes: 3 additions & 3 deletions R/app.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@
#' @importFrom imager draw_rect
#' @importFrom imager grabRect
#' @importFrom imager display
#' @importFrom imager HSVtoRGB
#' @importFrom duflor load_image
#' @importFrom duflor extract_pixels_HSV
#' @importFrom duflor apply_HSV_color_by_mask
#' @importFrom duflor HSVtoRGB
#' @importFrom utils packageDescription
#' @return .
#' @export
Expand Down Expand Up @@ -1190,11 +1190,11 @@ duflor_gui <- function() {
)
return()
} else {
results_path <- str_c(
results_path <- normalizePath(str_c(
dirname(DATA$results$results$full_path[[1]]),
"/results/results_",
input$date_of_image_shooting
)
))
out <- store_results_to_file(
results = DATA$results,
results_path = results_path,
Expand Down
49 changes: 49 additions & 0 deletions R/execute_multiple.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
#' @importFrom dplyr bind_rows
#' @importFrom imager width
#' @importFrom imager height
#' @importFrom imager save.image
#' @importFrom imager RGBtosRGB
#' @importFrom stringr str_c
#' @importFrom imager HSVtoRGB
#' @importFrom tools file_path_sans_ext
#'
execute_multiple <- function(files, input, DATA, DEBUGKEYS, FLAGS) {
#### INPUT VALIDATION ####
Expand Down Expand Up @@ -42,12 +47,24 @@ execute_multiple <- function(files, input, DATA, DEBUGKEYS, FLAGS) {
identifiersearch_y0 = input$identifiersearch_y0
identifiersearch_y1 = input$identifiersearch_y1
identifier_area <- input$identifier_area
do_save_masks <- input$do_save_masks
if (do_save_masks) {
results_path <- normalizePath(str_c(
dirname(files$images_filtered[1]),
"/results"
))
if (isFALSE(dir.exists(results_path))) {
dir.create(results_path)
}
}
do_save_high_contrast_masks <- input$do_save_high_contrast_masks
foreach_result <- foreach(index = 1:length(files$index),.packages = c("duflor","duflor.gui"), .verbose = T,.inorder = F) %dopar% {
# stop(simpleError("parallelisation is not implemented yet. figure out how to do so!!"))
current_results <- data.frame(matrix(NA, nrow = 1, ncol = length(names(results_object))))
colnames(current_results) <- names(results_object)
## NAME
file <- files$images_filtered[index]
bnf <- file_path_sans_ext(basename(file))
current_results$full_path <- file
current_results$image_name <- basename(file)
## DATE_OF_ANALYSIS
Expand Down Expand Up @@ -133,6 +150,17 @@ execute_multiple <- function(files, input, DATA, DEBUGKEYS, FLAGS) {
current_results[[str_c(name,"_area")]] <- areas[[name]]
current_results[[str_c(name,"_count")]] <- hsv_results[[name]]$pixel.count
current_results[[str_c(name,"_fraction")]] <- hsv_results[[name]]$pixel.count/(prod(image_dimensions))
if (do_save_masks) {
mask_path <- normalizePath(str_c(results_path, "/", bnf, "_", name, ".png"))
save.image(RGBtosRGB(HSVtoRGB(
apply_HSV_color_by_mask(
pixel.array = im,
pixel.idx = hsv_results[[name]]$pixel.idx,
target.color = "red",
mask_extreme = do_save_high_contrast_masks
)
)),file = mask_path)
}
}
## UPDATE RESULTS_OBJECT
# results_object <- update_resultsObject(results_object,current_results)
Expand All @@ -141,12 +169,22 @@ execute_multiple <- function(files, input, DATA, DEBUGKEYS, FLAGS) {
}
results_object <- bind_rows(foreach_result,.id = NULL)
} else {
if (input$do_save_masks) {
results_path <- normalizePath(str_c(
dirname(files$images_filtered[1]),
"/results"
))
if (isFALSE(dir.exists(results_path))) {
dir.create(results_path)
}
}
for (index in files$index) {
# create a results-row to be merged into the `results_object`
current_results <- data.frame(matrix(NA, nrow = 1, ncol = length(names(results_object))))
colnames(current_results) <- names(results_object)
## NAME
file <- files$images_filtered[index]
bnf <- file_path_sans_ext(basename(file))
current_results$full_path <- file
current_results$image_name <- basename(file)
## DATE_OF_ANALYSIS
Expand Down Expand Up @@ -232,6 +270,17 @@ execute_multiple <- function(files, input, DATA, DEBUGKEYS, FLAGS) {
current_results[[str_c(name,"_area")]] <- areas[[name]]
current_results[[str_c(name,"_count")]] <- hsv_results[[name]]$pixel.count
current_results[[str_c(name,"_fraction")]] <- hsv_results[[name]]$pixel.count/(prod(image_dimensions))
if (input$do_save_masks) {
mask_path <- normalizePath(str_c(results_path, "/", bnf, "_", name, ".png"))
save.image(RGBtosRGB(HSVtoRGB(
apply_HSV_color_by_mask(
pixel.array = im,
pixel.idx = hsv_results[[name]]$pixel.idx,
target.color = "red",
mask_extreme = input$do_save_high_contrast_masks
)
)),file = mask_path)
}
}
## UPDATE RESULTS_OBJECT
current_results$area_per_pixel <- areas$area_per_pixel
Expand Down
21 changes: 21 additions & 0 deletions R/execute_single.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,21 @@ execute_single <- function(file, input, DATA, DEBUGKEYS, FLAGS) {
colnames(current_results) <- names(results_object)
#TODO: decide if these paths must be sanitized still?
current_results$full_path <- file
bnf <- file_path_sans_ext(basename(file))
current_results$image_name <- basename(file)
## DATE_OF_ANALYSIS
current_results$date_of_analysis <- input$date_of_image_shooting
## IMAGE DIMENSIONS
image_dimensions <- as.integer(get_image_dimensions(file))
if (input$do_save_masks) {
results_path <- normalizePath(str_c(
dirname(file),
"/results"
))
if (isFALSE(dir.exists(results_path))) {
dir.create(results_path)
}
}
## LOAD IMAGE
if (input$do_crop_image) {
im <- load_image(
Expand Down Expand Up @@ -103,6 +113,17 @@ execute_single <- function(file, input, DATA, DEBUGKEYS, FLAGS) {
current_results[[str_c(name,"_area")]] <- areas[[name]]
current_results[[str_c(name,"_count")]] <- hsv_results[[name]]$pixel.count
current_results[[str_c(name,"_fraction")]] <- hsv_results[[name]]$pixel.count/(prod(image_dimensions))
if (input$do_save_masks) {
mask_path <- normalizePath(str_c(results_path, "/", bnf, "_", name, ".png"))
save.image(RGBtosRGB(HSVtoRGB(
apply_HSV_color_by_mask(
pixel.array = im,
pixel.idx = hsv_results[[name]]$pixel.idx,
target.color = "red",
mask_extreme = input$do_save_high_contrast_masks
)
)),file = mask_path)
}
}
current_results$area_per_pixel <- areas$area_per_pixel
## UPDATE RESULTS_OBJECT
Expand Down
2 changes: 2 additions & 0 deletions R/select_spectra_gui_comp.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ select_spectra_gui_comp <- function(input) {
# tags$h5('As a result, all images will be processed at full resolution. This is safer, but slower.'),
footer=tagList(
checkboxGroupInput("selected_spectra","Select spectra to analyse",choices = all_choices,selected = choices),
checkboxInput("do_save_masks","Save the spectrum-masks?"),
checkboxInput("do_save_high_contrast_masks","Save the high-contrast-masks instead?"),
actionButton('submit_selected_spectra', 'Submit choices'),
modalButton('cancel')
)
Expand Down
2 changes: 1 addition & 1 deletion R/store_KPI_plot_to_file.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#' @importFrom stringr str_c
#'
store_KPI_plot_to_file <- function(input, DATA) {
results_path <- str_c(dirname(DATA$results$results$full_path[[1]]),"/results/")
results_path <- normalizePath(str_c(dirname(DATA$results$results$full_path[[1]]),"/results/"))
dir <- dirname(results_path)
if (isFALSE(dir.exists(dir))) {
dir.create(dir)
Expand Down
2 changes: 2 additions & 0 deletions R/store_results_to_file.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ store_results_to_file <- function(results, results_path, save_to_xlsx=FALSE, set
}
if (isTRUE(save_to_xlsx)) {
results_path <- str_c(results_path,".xlsx")
results_path <- normalizePath(results_path)
dir <- dirname(results_path)
if (isFALSE(dir.exists(dir))) {
dir.create(dir)
Expand All @@ -51,6 +52,7 @@ store_results_to_file <- function(results, results_path, save_to_xlsx=FALSE, set
) ## sign the file with being created by this username on this machine.
} else {
results_path <- str_c(results_path,".csv")
results_path <- normalizePath(results_path)
dir <- dirname(results_path)
if (isFALSE(dir.exists(dir))) {
dir.create(dir)
Expand Down
2 changes: 1 addition & 1 deletion docs/404.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/LICENSE-text.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/LICENSE.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/articles/general-user-manual.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/articles/identifier-cropping.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/articles/image-cropping.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/articles/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/articles/modifying-hsv-bounds.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/articles/optimising-speed.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/articles/parallelisation.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/articles/raising-issues.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/articles/saving-and-restoring-application-states.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions docs/authors.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ articles:
parallelisation: parallelisation.html
raising-issues: raising-issues.html
saving-and-restoring-application-states: saving-and-restoring-application-states.html
last_built: 2024-08-28T13:46Z
last_built: 2024-08-28T21:26Z
urls:
reference: https://Claudius-Appel.github.io/duflor.gui/reference
article: https://Claudius-Appel.github.io/duflor.gui/articles
2 changes: 1 addition & 1 deletion docs/reference/convert_pixels_to_area_gui.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit deb514b

Please sign in to comment.