Ridler_auto: Automatically analyzing canopy openness

Description Usage Arguments Value Author(s) References Examples

View source: R/Ridler_auto.R

Description

Ridler_auto uses the Ridler and Calvard algorithm (1978) to iterativelly find the threshold for each picture in order to calculate the proportion of sky (canopy openness) in multiple pictures at time.

Usage

1
Ridler_auto(path1, path2 = TRUE, write = TRUE, pixel)

Arguments

path1

corresponds to the path to the picture folders.

path2

if TRUE it indicates that there are sub-folder within path1, for example different year folders. Then the alogrithm will look within these folders to analyze the pictures.

write

if TRUE, the function will write the result file as a .csv in path1.

pixel

Indicates the number of pixel of the hemispherical picture. If not given, Ridler_auto will use the total number of pixel detected.

Value

if path2==FALSE, the value is a dataframe with two columns. The first one, "Name", corresponds to the name of each picture. The second one, "Sky", is the proportion of sky pixels corresponding to each picture. If path2==TRUE, the value is a list containing one dataframe (similar to the one previously described) for each picture sub-folder. The names of the list correspond to the names of the sub-folders.

Author(s)

Benedicte Bachelot

References

Ridler, T.W. & Calvard, S. (1978). Picture thresholding an iterative selection method. IEEE transactions on Systems, Man and Cybernetics, 8(8), 630-632.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
## The function is currently defined as
function (path1, path2 = TRUE, write = TRUE, pixel) 
{
    R <- list()
    setwd(path1)
    ll <- list.files(path = path1)
    for (j in 1:length(ll)) {
        if (path2 == TRUE) {
            file <- ll[j]
            l <- list.files(path = file)
            eval(parse(text = paste("setwd('", path1, "/", file, 
                "')", sep = "")))
        }
        if (path2 == FALSE) {
            l <- ll
        }
        Result <- matrix(data = NA, nrow = length(l), ncol = 2)
        for (k in 1:length(l)) {
            r <- Ridler(readImage(l[k]), pixel, p = FALSE)
            Result[k, 1] <- l[k]
            Result[k, 2] <- r
        }
        setwd(path1)
        Result <- data.frame(Result)
        Result[, 1] <- as.character(Result[, 1])
        Result[, 2] <- as.numeric(as.character(Result[, 2]))
        colnames(Result) <- c("Name", "Sky")
        R[[j]] <- Result
        if (write == TRUE & path2 == TRUE) {
            eval(parse(text = paste("write.csv(Result,'Result_", 
                file, ".csv')", sep = "")))
            names(R)[j] <- file
        }
        if (write == FALSE & path2 == TRUE) {
            names(R)[j] <- file
        }
        if (write == TRUE & path2 == FALSE) {
            write.csv(R[[1]], "Result.csv")
        }
    }
    if (path2 == TRUE) {
        return(R)
    }
    if (path2 == FALSE) {
        return(R[[1]])
    }
  }

Sky documentation built on May 2, 2019, 2:50 p.m.