-
Notifications
You must be signed in to change notification settings - Fork 2
/
normalizeR
65 lines (50 loc) · 1.93 KB
/
normalizeR
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
#load libraries
library(raster)
library(tictoc)
#library(devtools)
#devtools::install_github("timelyportfolio/svgPanZoom")
#devtools::install_github("duncantl/SVGAnnotation")
library(svglite)
library(svgPanZoom)
library(SVGAnnotation)
library(tcltk)
library(progress)
#internal functions
source('~/Desktop/INF_550_Notes/standardize.R')
#go to directory where raw files are saved
setwd()
#choose band_names
names <- c("X569.71","X589.88","X615.22","X630.49","X659.89","X665.02","X689.43","X730.74","X790.43","X845.12","X899.86")
#function
normalizeR <- function(names){
tic()
Filters <- matrix(c("*",".raw"),1, 2, byrow = TRUE)
data <- tk_choose.files(caption="choose Data File",filter = Filters)
filen <- brick(data)
white <- tk_choose.files(caption="choose 'WHITEREF' File",filter = Filters)
dark <-tk_choose.files(caption="choose 'DARKREF' File",filter = Filters)
raw <- raster::subset(filen,names)
#is there an option to add extra zoom?
plotRGB(raw,c(1,5,8), axes=TRUE, stretch="hist", main="Raw Image")
cropC <- drawExtent()
stripe <- crop(raw,cropC)
names(stripe) <- names(raw)
#header file has to exist in same file or this breaks!
whiteRow <- createReferenceMeanRow(white,stripe,"WhiteRow.tif",names)
names(whiteRow) <- names(stripe)
darkRow <- createReferenceMeanRow(dark,stripe,"DarkRow.tif",names)
names(darkRow) <- names(stripe)
#find length of core stripe to break up white
len <- stripe@nrows
#disaggregate whiterow to length
whiteRef <- disaggregate(whiteRow,fact = c(1,len))
darkRef <- disaggregate(darkRow,fact = c(1,len))
#set extents to be the same between stripe and reference files
extent(whiteRef) <- extent(stripe)
extent(darkRef) <- extent(stripe)
#normalization is fast! 47 seconds for Tutae
normalized <- overlay(stripe,whiteRef,darkRef,fun = normFun,filename = "normalized.tif",overwrite = TRUE)
names(normalized) <- names(stripe)
return(normalized)
}
core_name <- normalizeR()