Skip to content

Commit

Permalink
update to jpeg and streamline DT
Browse files Browse the repository at this point in the history
  • Loading branch information
wincowgerDEV committed May 15, 2024
1 parent 0a6ccdf commit 633947b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,14 @@ importFrom(data.table,setorder)
importFrom(data.table,transpose)
importFrom(digest,digest)
importFrom(glmnet,predict.glmnet)
importFrom(grDevices,as.raster)
importFrom(grDevices,chull)
importFrom(grDevices,col2rgb)
importFrom(graphics,matlines)
importFrom(graphics,matplot)
importFrom(hyperSpec,read.jdx)
importFrom(hyperSpec,read.spc)
importFrom(jpeg,readJPEG)
importFrom(jsonlite,read_json)
importFrom(jsonlite,write_json)
importFrom(methods,new)
Expand Down
18 changes: 11 additions & 7 deletions R/def_features.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,14 @@ collapse_spec.OpenSpecy <- function(x, ...) {
ts$id <- x$metadata$feature_id
x$spectra <- ts[, lapply(.SD, median, na.rm = T), by = "id"] |>
transpose(make.names = "id")

if(all(c("r", "g", "b") %in% names(x$metadata))){
x$metadata[, r := as.integer(sqrt(mean(r^2))), by = "feature_id"]
x$metadata[, g := as.integer(sqrt(mean(g^2))), by = "feature_id"]
x$metadata[, b := as.integer(sqrt(mean(b^2))), by = "feature_id"]

r <- g <- b <- NULL

if(all(c("r", "g", "b") %in% names(x$metadata))){
x$metadata[, `:=`(r = as.integer(sqrt(mean(r^2))),
g = as.integer(sqrt(mean(g^2))),
b = as.integer(sqrt(mean(b^2)))), by = "feature_id"]

x$metadata <- x$metadata |>
unique(by = c("feature_id", "area", "feret_max", "centroid_y",
"centroid_x", "first_x", "first_y", "rand_x", "rand_y",
Expand Down Expand Up @@ -141,7 +144,8 @@ def_features.OpenSpecy <- function(x, features, shape_kernel = c(3,3), img = NUL
}


#' @importFrom grDevices chull
#' @importFrom grDevices chull as.raster col2rgb
#' @importFrom jpeg readJPEG
#' @importFrom stats dist
.def_features <- function(x, binary, shape_kernel = c(3,3), img = NULL, bottom_left = NULL, top_right = NULL, name = NULL) {
# Label connected components in the binary image
Expand Down Expand Up @@ -176,7 +180,7 @@ def_features.OpenSpecy <- function(x, features, shape_kernel = c(3,3), img = NUL

#Add color extraction here.
if(!is.null(img) & !is.null(bottom_left) & !is.null(top_right)){
mosaic <- image_read(img)
mosaic <- readJPEG(img)
map_dim <- c(length(unique(x$metadata$x)),
length(unique(x$metadata$y)))
xscale = (top_right[1]-bottom_left[1])/map_dim[1]
Expand Down

0 comments on commit 633947b

Please sign in to comment.