Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

Commit

Permalink
Include suggestions given by the CRAN team on the first submission
Browse files Browse the repository at this point in the history
  • Loading branch information
TiagoOlivoto committed May 13, 2021
1 parent a94fc94 commit b3fb181
Show file tree
Hide file tree
Showing 20 changed files with 208 additions and 139 deletions.
11 changes: 6 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ Authors@R:
role = c("aut", "cre"),
email = "[email protected]",
comment = c(ORCID = "0000-0002-0241-9636"))
Description: Provides tools for image manipulation and plant image
analysis that will help you to segment images, create binary images,
measure leaf area, quantify disease severity, count the number of
disease lesions, and obtain statistics of image objects such as
grains, pods, pollen, leaves and more.
Description: Provides tools for image manipulation that will help you to
quantify plant leaf area, disease severity, number of disease lesions,
and obtain statistics of image objects such as grains, pods, pollen,
leaves, and more. Tools for segment images and create binary images
using the method of automatic threshold selection method proposed by
Otsu (1979) <doi:10.1109/tsmc.1979.4310076> are also provided.
License: GPL (>= 3)
Depends:
R (>= 4.0.0)
Expand Down
3 changes: 2 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export(image_horizontal)
export(image_hreflect)
export(image_import)
export(image_index)
export(image_pallete)
export(image_palette)
export(image_pliman)
export(image_resize)
export(image_rotate)
Expand Down Expand Up @@ -52,6 +52,7 @@ importFrom(parallel,makeCluster)
importFrom(parallel,parLapply)
importFrom(parallel,stopCluster)
importFrom(stats,aggregate)
importFrom(stats,as.formula)
importFrom(stats,binomial)
importFrom(stats,glm)
importFrom(stats,kmeans)
Expand Down
5 changes: 0 additions & 5 deletions R/color_palette.R

This file was deleted.

45 changes: 11 additions & 34 deletions R/count_lesions.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,12 @@
#' processing, when `save_image = TRUE`, the processed image will be also
#' saved in such a directory.
#' @param verbose If `TRUE` (default) a summary is shown in the console.
#' @return A data frame with the results for each image.
#' @return A list with the following objects:
#' * `results` A data frame with the results (area, perimeter, radius) for
#' object.
#' * `statistics` A data frame with the summary statistics for the image.
#' * `count` (If `img_pattern` is used), summarizing the count number for each
#' image.
#' @export
#' @md
#' @author Tiago Olivoto \email{tiagoolivoto@@gmail.com}
Expand All @@ -96,6 +101,7 @@
#' healthy <- image_import(image_pliman("sev_healthy.jpg"))
#' lesions <- image_import(image_pliman("sev_sympt.jpg"))
#' image_combine(img, healthy, lesions, ncol = 3)
#' a <-
#' count_lesions(img = img,
#' img_healthy = healthy,
#' img_lesion = lesions,
Expand Down Expand Up @@ -224,18 +230,6 @@ count_lesions <- function(img,
nmask <- watershed(distmap(plant_symp),
tolerance = tol,
ext = ext))
# shape <-
# cbind(data.frame(computeFeatures.shape(nmask)),
# data.frame(computeFeatures.moment(nmask))[,1:2]
# )
# ifelse(!is.null(lower_size),
# shape <- shape[shape$s.area > lower_size, ],
# shape <- shape[shape$s.area > mean(shape$s.area) * 0.1, ])
# if(!is.null(upper_size)){
# shape <- shape[shape$s.area < upper_size, ]
# }
# shape$id <- 1:nrow(shape)
# shape <- shape[, c(9, 7, 8, 1, 2:6)]
if(show_original == TRUE & show_segmentation == FALSE){
im2 <- img
im2@.Data[,,1][!ID] <- col_lesions[1]
Expand Down Expand Up @@ -292,14 +286,12 @@ count_lesions <- function(img,
sintoma$df_in[sample(1:nrow(sintoma$df_in)),][1:nrows,],
fundo$df_in[sample(1:nrow(fundo$df_in)),][1:nrows,]) %>%
transform(Y = ifelse(CODE == "img_background", 0, 1))
# fundo_resto$CODE <- NULL
modelo1 <-
glm(Y ~ R + G + B, family = binomial("logit"), data = fundo_resto) %>%
suppressWarnings()
pred1 <- predict(modelo1, newdata = original$df_in, type="response") %>% round(0)
plant_background <- matrix(pred1, ncol = ncol(original$R))
plant_background <- image_correct(plant_background, perc = 0.009)
# image_show(plant_background)
plant_background[plant_background == 1] <- 2
sadio_sintoma <-
rbind(sadio$df_in[sample(1:nrow(sadio$df_in)),][1:nrows,],
Expand All @@ -318,7 +310,6 @@ count_lesions <- function(img,
leaf_sympts <- matrix(pred3, ncol = ncol(original$R))
leaf_sympts <- 1 - image_correct(leaf_sympts, perc = 0.009)
plant_background[leaf_sympts == 1] <- 3
# mpred1 <- bwlabel(leaf_sympts == 0)
parms <- read.csv(file=system.file("parameters.csv", package = "pliman", mustWork = TRUE),
header = T, sep = ";")
parms2 <- parms[parms$object_size == lesion_size,]
Expand All @@ -333,18 +324,6 @@ count_lesions <- function(img,
nmask <- watershed(distmap(leaf_sympts),
tolerance = tol,
ext = ext))
# shape <-
# cbind(data.frame(computeFeatures.shape(nmask)),
# data.frame(computeFeatures.moment(nmask))[,1:2]
# )
# ifelse(!is.null(lower_size),
# shape <- shape[shape$s.area > lower_size, ],
# shape <- shape[shape$s.area > mean(shape$s.area) * 0.1, ])
# if(!is.null(upper_size)){
# shape <- shape[shape$s.area < upper_size, ]
# }
# shape$id <- 1:nrow(shape)
# shape <- shape[, c(9, 7, 8, 1, 2:6)]
if(show_original == TRUE & show_segmentation == TRUE){
im2 <- colorLabels(nmask)
if(backg){
Expand Down Expand Up @@ -413,9 +392,6 @@ count_lesions <- function(img,
eval(parse(text=x))}))
ext <- ifelse(is.null(extension), parms2[rowid, 3], extension)
tol <- ifelse(is.null(tolerance), parms2[rowid, 4], tolerance)
# print(res)
# print(ext)
# print(tol)
nmask <- watershed(distmap(img2),
tolerance = tol,
ext = ext)
Expand Down Expand Up @@ -464,8 +440,6 @@ count_lesions <- function(img,
}
}



shape <-
cbind(data.frame(computeFeatures.shape(nmask)),
data.frame(computeFeatures.moment(nmask))[,1:2]
Expand All @@ -478,7 +452,6 @@ count_lesions <- function(img,
}
shape$id <- 1:nrow(shape)
shape <- shape[, c(9, 7, 8, 1, 2:6)]

show_mark <- !is.null(marker) && show_segmentation == TRUE | show_segmentation == FALSE
marker <- ifelse(is.null(marker), "point", marker)
marker_col <- ifelse(is.null(marker_col), "white", marker_col)
Expand Down Expand Up @@ -553,8 +526,12 @@ count_lesions <- function(img,
NA)) %>%
transform(statistics = c("n", "min", "mean", "max", "sd", "sum", "prop"))
stats <- stats[c(3, 1, 2)]
shape <- shape[,c(1:6, 8:9, 7)]
colnames(shape) <- c("id", "x", "y", "area", "perimeter", "radius_mean",
"radius_min", "radius_max", "radius_sd")
results <- list(results = shape,
statistics = stats)
class(results) <- "plm_count"
if(verbose == TRUE){
print(results$statistics, row.names = FALSE)
}
Expand Down
20 changes: 12 additions & 8 deletions R/count_objects.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,12 @@
#' processing, when `save_image = TRUE`, the processed image will be also
#' saved in such a directory.
#' @param verbose If `TRUE` (default) a summary is shown in the console.
#' @return A data frame with the results for each image.
#' @return A list with the following objects:
#' * `results` A data frame with the results (area, perimeter, radius) for
#' object.
#' * `statistics` A data frame with the summary statistics for the image.
#' * `count` (If `img_pattern` is used), summarizing the count number for each
#' image.
#' @export
#' @import EBImage
#' @md
Expand Down Expand Up @@ -245,7 +250,6 @@ count_objects <- function(img,
ext = ext)
ID <- which(img2 == 1)
ID2 <- which(img2 == 0)
feat <- computeFeatures.moment(nmask)
}
backg <- !is.null(col_background)
col_background <- col2rgb(ifelse(is.null(col_background), "white", col_background))
Expand Down Expand Up @@ -309,7 +313,7 @@ count_objects <- function(img,
shape$id <- 1:nrow(shape)
shape <- shape[, c(9, 7, 8, 1, 2:6)]
show_mark <- !is.null(marker) && show_segmentation == TRUE | show_segmentation == FALSE
marker <- ifelse(is.null(marker), "point", marker)
marker <- ifelse(is.null(marker), "text", marker)
marker_col <- ifelse(is.null(marker_col), "white", marker_col)
marker_size <- ifelse(is.null(marker_size), 0.9, marker_size)
if(show_image == TRUE){
Expand Down Expand Up @@ -346,16 +350,16 @@ count_objects <- function(img,
if(marker == "text"){
marker_size <- ifelse(is.null(marker_size), 0.75, marker_size)
image_show(im2)
text(feat[,1],
feat[,2],
seq(1:nrow(feat)),
text(shape[,2],
shape[,3],
shape[,1],
col = marker_col,
cex = marker_size)
} else{
marker_size <- ifelse(is.null(marker_size), 0.75, marker_size)
image_show(im2)
points(feat[,1],
feat[,2],
text(shape[,2],
shape[,3],
col = marker_col,
pch = 16,
cex = marker_size)
Expand Down
3 changes: 2 additions & 1 deletion R/symptomatic_area.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
#' processing, when `save_image = TRUE`, the processed image will be also
#' saved in such a directory.
#' @param verbose If `TRUE` (default) a summary is shown in the console.
#' @return A data frame with the results for each image.
#' @return A data frame with the results (healthy and symptomatic area) for each
#' image.
#' @export
#' @md
#' @importFrom stats binomial glm predict kmeans sd aggregate
Expand Down
14 changes: 14 additions & 0 deletions R/utils_file.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,23 @@
#' @param remove_original Remove original files after manipulation? defaults to
#' `FALSE`. If `TRUE` the files in `pattern` will be removed.
#' @param verbose If `FALSE`, the code is run silently.
#' @return
#' * `file_extension()`, `file_name()`, and `file_dir()` return a character
#' string.
#' * `manipulate_files()` No return value. If `verbose == TRUE`, a message is
#' printed indicating which operation succeeded (or not) for each of the files
#' attempted.
#' @export
#' @examples
#' \donttest{
#' library(pliman)
#' # get file name, directory and extension
#' file <- "E:/my_folder/my_subfolder/image1.png"
#' file_dir(file)
#' file_name(file)
#' file_extension(file)
#'
#' # manipulate files
#' dir <- tempdir()
#' list.files(dir)
#' file.create(paste0(dir, "/test.txt"))
Expand Down
20 changes: 12 additions & 8 deletions R/utils_imagem.R
Original file line number Diff line number Diff line change
Expand Up @@ -535,9 +535,9 @@ image_binary <- function(image,
}
}

#' Image indices
#' Image indexes
#'
#' Builds image indices using Red, Green, Blue, Red-Edge, and NIR bands.
#' Builds image indexes using Red, Green, Blue, Red-Edge, and NIR bands.
#' @details
#' The following indexes are available in pliman.
#'
Expand Down Expand Up @@ -992,14 +992,17 @@ image_to_mat <- function(image,
#' @param workers A positive numeric scalar or a function specifying the maximum
#' number of parallel processes that can be active at the same time.
#' @param verbose If `TRUE` (default) a summary is shown in the console.
#' @return A list with `npal` color palettes of class `Image`.
#' @export
#' @examples
#' \donttest{
#' library(pliman)
#'img <- image_import(image_pliman("sev_leaf.jpg"))
#'pal <- image_pallete(img, 2)
#'pal <- image_palette(img, 2)
#'image_show(pal[[1]])
#'image_show(pal[[2]])
image_pallete <- function(image,
#'}
image_palette <- function(image,
npal,
nstart = 25,
parallel = FALSE,
Expand All @@ -1017,9 +1020,9 @@ image_pallete <- function(image,
if(verbose == TRUE){
message("Image processing using multiple sessions (",nworkers, "). Please wait.")
}
parLapply(clust, image, image_pallete, npal, nstart)
parLapply(clust, image, image_palette, npal, nstart)
} else{
lapply(image, image_pallete, npal, nstart)
lapply(image, image_palette, npal, nstart)
}
} else{
df <- image_to_mat(image)$df_in
Expand All @@ -1032,7 +1035,7 @@ image_pallete <- function(image,
R <- df1[1:dim_mat^2, 1]
G <- df1[1:dim_mat^2, 2]
B <- df1[1:dim_mat^2, 3]
rgbs[[i]] <- array(c(R, G, B), dim = c(dim_mat, dim_mat, 3))
rgbs[[i]] <- as.Image(array(c(R, G, B), dim = c(dim_mat, dim_mat, 3)))
}
return(rgbs)
}
Expand All @@ -1048,7 +1051,8 @@ image_pallete <- function(image,
#' @param dpi The image resolution in dots per inch.
#' @param px The number of pixels.
#' @param cm The size in centimeters.
#' @return A numerical value.
#' @return A numeric value or a vector of numeric values if the input data is a
#' vector
#' @export
#' @author Tiago Olivoto \email{tiagoolivoto@@gmail.com}
#' @examples
Expand Down
Loading

0 comments on commit b3fb181

Please sign in to comment.