# Set working direcotory
1setwd("C:/GitHub/data/cake/")
- 1
- Path to your working directory. In cake folder we have two different cores.
Before any spectral indices and properties are calculated, normalizing the data and expressing it as a reflectance is necessary. Here, reflectance is a fraction of the signal between the dark and white references acquired during or before the scan.
Normalization is achieved by following the equation:
\[ ref = (d_{raw} - ref_{d})/(ref_{w} - ref_{d}) \]
where:
ref: normalized data cube;
draw: raw captured data;
refd: dark reference data;
refw: white reference data.
Which can be modified for different acquisition times for white reference:
\[ ref = (d_{raw} - ref_{dar})/(ref_{w} - ref_{d}) * t_{int-w}/t_{int-s} \]
where:
tint-w: integration time of white reference;
tint-s: integration time of captured data (sample).
If Shiny GUI was used for data selection, cropping, and calibration, then it would be easy to pass Shiny’s output to the normalization routine. The normalized files will be written into your data’s products directory.
First, this is specific only for workflow, where you’d like to calculate reflectance from the Shiny output. We must set the working directory (otherwise, we discourage this approach in R). Working directory should point two levels above your /capture data directory.
For example, if you are working with “YOUR CORE” then working directory should point one level above it, and therefore two levels above the capture.
– WORKING DIRECTORY<directory>
–– YOUR CORE <directory>
––– capture <directory>
# Set working direcotory
1setwd("C:/GitHub/data/cake/")
You either have the HSItools::run_core()
output in memory or you need to read it from disk.
# Read from disk
<- readRDS("Achive_half_WR_240212-111356/HSItools_core.rds") hsi_tools_core
Then, use the standard function to calculate the reflectance.
If you used different integration times for your sample and white references, provide this information in the function.
# Create normalized reflectance file
1<- hsi_tools_core |>
reflectance 2::prepare_core(
HSItools3tints = 90,
4tintw = 30)
It is planned to optionally iterate over multiple directories using, for example, the {purrr} package. This will need to get rid of setwd() call.
If no Shiny output is available and input is not produced by hand, the normalization routine can be run without it. In such a case, the entire capture data will be normalized. However, without Shiny output, it is harder to calibrate distances properly.
Here, we normalize all the captured data with all the available layers between 400 and 1000 nm.
# Store the path
<- "data/my_core"
path
# Create normalized reflectance file
1<- path |>
reflectance 2::prepare_core(path = path, layers = c(400:1000), extent = "capture") HSItools
It is possible to iterate over multiple directories at once using the {purrr}
package.
# Store the paths
1<- list(
paths core_1 = "data/my_core_1",
core_2 = "data/my_core_2")
# Or easier, with listing
2<- fs::dir_ls("data")
paths
# Create normalized reflectance files
3<- paths |>
reflectance ::map(\(i) HSItools::prepare_core(
purrrpath = i,
layers = c(400:1000),
4extent = "capture"))
Applying spectral smoothing, such as the Savitzky-Golay spectral filter (Savitzky and Golay 1964), prevents spurious, random peaks and troughs from significantly influencing the calculation results.
This function applies a smooth filter to every pixel. Depending on the size of your data, it will take considerable time to run.
You might be interested in smoothing your data spatially to remove some of the noise in the XY domain. Data is saved to disk.
This function applies a focal median filter to every pixel. Depending on the size of your data, it will take considerable time to run. More than the Savitzky-Golay. Consider running it on the calculated index rasters and ROIs.
We can process our data further by removing the continuum, which follows the rule of dividing the spectrum by its bounding box. This way, the spectrum becomes flatter.
While function technically works, it is not producing desired output for HSI means.
For later use, generate a RGB (CIR, NIR) preview.