-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.Rhistory
78 lines (78 loc) · 2.45 KB
/
.Rhistory
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
library("imager")
clusterize <- function(file_path) {
# get a kmeans df
# input image file path
# output percent leaf cover first sky, second leaves I think
image <- load.image(file_path)
image <- grayscale(image)
# Note, there is a bug where if the image is already BW, the above line causes a failure
# do the kmeans clustering, looking for 2 clusters. as.vector is needed or else it only does the first row for some reason
km <- kmeans(as.vector(image), centers = 2)
# note km$size returns a two vector - first is sky, second is leaves
num_pixels <- dim(image)[1] * dim(image)[2]
percents <- km$size/num_pixels*100
# note: currently returns in order of higher to lower percent,
# this is a problem if there is more sky in an image than leaves.
# I can deal with this by calculating the average value of the pixel
# values and executing some code to switch the order in that case.
return(percents)
}
# next step is to setup the function to loop through files in folder and make data frames and graphs!!
# I think that is enough work on this for tonight
clusterize(file.choose())
im <- file.choose()
im
clusterize(im)
library(imager)
clusterize(im)
test <- load.image(im)
test <- load.image(im)
test <- load.image(file.choose())
source('~/Documents/canopy-cover/main.R')
library(tcltk)
loopFiles(tk_choose.dir())
loopFiles(tk_choose.dir())
df <- loopFiles(tk_choose.dir())
df2 <- loopFiles(tk_choose.dir())
df
df2
l <- list(df, df2)
makeGraphs(l)
df3 <- loopFiles(tk_choose.dir())
df4 <- loopFiles(tk_choose.dir())
l
l
l <- list(df, df2, df3, df4)
makeGraphs(l)
source('~/Documents/canopy-cover/main.R')
list.files()
library(tcltk)
setwd(tk_choose.dir())
source('~/Documents/canopy-cover/main.R')
source('~/Documents/canopy-cover/main.R')
source('~/Documents/canopy-cover/main.R')
ls
list.files()
setwd(tk_choose.dir())
source('~/Documents/canopy-cover/main.R')
source('~/Documents/canopy-cover/main.R')
script.dir <- tk_choose.dir()
setwd(script.dir)
list.dirs(path = "./photos/")
cat(script.dir + "./photos")
cat(script.dir,"./photos")
cat(script.dir,"/photos")
cat(script.dir,"/photos", sep="")
source('~/Documents/canopy-cover/main.R')
cat(script.dir)
cat(script.dir, "photos", sep="")
source('~/Documents/canopy-cover/main.R')
as.character(cat(script.dir))
script.dir
?setwd
source('~/Documents/canopy-cover/main.R')
source('~/Documents/canopy-cover/main.R')
setwd(tk_choose.dir())
list.dirs(path = "./photos/")
list.dirs(path = "./photos/", recursive = F)
source('~/Documents/canopy-cover/main.R')