knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
This tutorial will guide through an analysis process to demonstrate the intended use of the tools. Throughout this document we will use a sample data of a sediment disk. The goal of the data and analysis is to retrieve a vertical profile of phytobenthos distribution.
The sediment disk was sampled in the Scheldt estuary, Belgium, with a contact core having 2 cm radius and 2 mm depth, and preserved in liquid nitrogen until analysis. While frozen, the disk was broken in two halves. One half had the upper surface imaged, while the other had its cross-sectional surface imaged. The imaging spectrometer was a SOC-710P (Surface Optics Corporation, San Diego, US), with 128 bands covering the range from 377.80 nm to 1035.97 nm with a 5 nm spectral sampling. This imaging system had an Instantaneus Field of View (IFOV) of 0.2507 mrad, that translates to 80 $\mu$m resolution with our measurement setup.
The images recorded by the system were processed with the vendor's software to convert the raw digital counts to physical units and apply all necessary corrections (smile correction, flat field corrections, etc). The digital counts data were termed "raw" and the calibrated data (radiance) termed "rad":
library(surfspec) fl.raw <- system.file("extdata", "sed_95.80801ms_f11_AP1.5.cube", package = "surfspec") fl.rad <- system.file("extdata", "sed_95.80801ms_f11_AP1.5_rad.cube.float", package = "surfspec")
Despite optimizations for the integration time, it may be the case that pixels or regions in the area being scanned will be saturated (maximum digital count of the system). Those can happen over surfaces with specular reflectance (e.g., glint) and in areas or wavelength ranges were material exitant radiance * detector band response is much higher than for the image average or spectral average. When converting to physical units, those saturated pixels can be harder to detect since their values will vary per image.
The saturation mask function mask_s
loads the raw hyperspectral cube and creates a mask of saturated values. If run with the default options, the function will return a single mask, where a pixel is set to NA if it is saturated in any band. This is useful if the exitant radiance * detector band response is within a range that can be accommodated in the radiometric resolution of the instrument for all bands. However, different situations might occur, e.g., for a material with low refletcance in the visible but high reflectance in the NIR. In that case in order to achieve appropriate signal to noise ratio in the visible it might be necessary to saturate the NIR range (considering that the integration time is spectrally constant). A second image of the same surface can then be made underexposing in the visible to not saturate in the NIR. In those cases the saturation mask function can be called with defined wavelength ranges, e.g, wrange = c(400, 700) in the first image and wrange = c(700, 1500) for the second one.
It is also possible to use a set of specific wavelengths for the saturation mask. This is of interest when only specific bands will be used in further analysis (e.g., NDVI calculation). This can be done by passing a vector with specific wavelengths (the bands with closest central wavelengths will be used). Note that in those cases, is the user's responsibility to only use in their final analysis the subset of bands that were used for the saturation mask calculations.
An option that bypasses the need to care on wavelength ranges is to set argument layers to TRUE. In that case the returned mask is a raster stack with a mask per layer, but will be slower than processing only a defined range if only a defined range is necessary. The result, however, is more flexible if data is to be stored for different possible uses. This option is also useful in exploring the data to know in which bands the saturation happens and better plan future acquisitions.
In the following example, we will run the saturation mask function only for bands that will be used in the NDVI calculation.
( mk <- mask_s(fl.raw, wave = c(670, 710)) ) par(mar = c(3, 3, 3, 3)) plot(mk, colNA = 'red', col = "white", legend = FALSE, main = "Saturated pixels shown in red")
Once the saturation mask was calculated, we can import and mask the calibrated data. This is performed with the function read_cube
by passing the mask as the second argument. It is also possible to call this function without a mask, in which case the data retrieved may contain saturated pixels at different position and wavelengths that were propagated in the conversion to physical units. This is not advisable in general analysis, but might be of interest for specific processing and in exploring and understanding the data.
( cb <- cube_read(fl.rad, mask = mk) )
We can visualize an RGB composite of the data with the function cube_rgb
. This is a basic function in the sense that it lacks flexibility in scaling of the data to stretch contrast and illumination, but is intended for general visualization of the data in interactive functions. It provide options for a log scaling (log = FALSE, default) or a linear scaling (e.g., log = FALSE and fact = 0.9). It is also possible to visualize any false color composite by passing the wavelengths that should be used for RGB channels. The default is a true color composite using the closest bands to 650 nm, 570 nm, 480 nm.
cube_rgb(cb, fact = 0.8)
The calibrated exitant radiance recorded by the sensor has to be normalized to reflectance to reduce the influence of the spectral quality and quantity of the incident light field. This will increase the covariance of the radiometric information with the desired physical property (e.g., Chl a content) across samples and illumination conditions. The term "reflectance" is used here in the sense of Lambertian equivalent bi-hemispherical reflectance, $\rho$, that is, the exitant radiance integrated over the upper hemisphere normalized by the incident downwelling irradiance. The "Lambertian equivalent" term comes from the extrapolation from the exitant radiance measured in a small solid angle centered in the view direction to the exitant radiance over the hemisphere, by assuming that the surface under measurement is Lambertian, that is, constant exitant radiance in all directions. The same assumption of Lambertian properties is also made for the diffuse reflector reference placed on the image. The scaling factor from the (measured) hemispherical-directional reflectance to the Lambertian equivalent bi-hemispherical reflectance is $\pi$ steradians.
Note that reflectance can also be calculated on the uncalibrated (raw) data if a reference diffuse reflector is present on the image. However this is not advisable since in the processing of calibrating the image to physical units, several corrections are applied (wavelength smile correction, flat field spatial correction, etc).
The function cube_refl
is provided with two methods for the normalization if a surface of known reflectance (reference) is present in the image. Since the position of the reference on the image can vary, this function requires interaction with the user. First the user is prompted to select the lower left (LL) and upper right (UR) extent of the image to process. This can help to reduce the data size and speed up processing if sample is small - but note that the reference diffuse reflector has to be inside the selected extent. The second step requiring interaction is the selection of the reference diffuse reflector area on the image. If the reference diffuse reflector is placed along the scan line (i.e., covering the same scan lines as the target) the selection is simple and involve delimiting the upper and lower limits of the reference plaque. The downwelling irradiance will then be calculated per scan line, making it possible to work under potentially unstable illumination (natural light). Note that all rows in a given scan line inside the area defined as reference are used for calculating the average light per scan line. Therefore, it is necessary that the limits of the reference are defined such that only the reference diffuse reflector is inside the selected area.
The second method is a single downwelling light calculation, averaging all the pixels in the polygon drawn by the user. This is can reduce noise influence on illumination calculations from larger sample average but should only be used under spatio-temporaly constant illuminations (e.g., open space under clear skies with low sun zenith angle or artificial diffuse illumination). Note that what is necessary for the reflectance calculation is that the illumination over the reference diffuse reflector be equal to the illumination over the target and accurate reflectance determinations of the reference diffuse reflector (e.g., NIST traceable).
Our example dataset was collected under natural illumination, so its reflectance will be calculated per scan line:
r8h <- system.file("extdata", "kodak_grey_card.csv", package = "surfspec") %>% read.csv() rf <- cube_refl(cb, rho = r8h, method = "along") #> Select the lower left and upper right corners of the area to process #> Accept (y | n)? y #> Croping selected area...done! #> Select the lower and upper borders of the reference plaque #> Accept (y | n)? y #> Croping reference area...done! #> Processing reflectance...done! #> Writing cube to disk...Finished! cube_rgb(rf, fact = 0.8)
library(magrittr) par(mar = c(5, 5, 3, 2), mfcol = c(1, 2)) cube_rgb(cb, log = FALSE, main = "Select LL and UR of area to process") rect(xleft = 110, ybottom = 200, xright = 420, ytop = 455, lwd = 1, border = "red") rf <- crop(cb, extent(110, 420, 200, 455)) cube_rgb(rf, log = FALSE, main = "Select upper and lower limit of reference") rect(xleft = 110, ybottom = 350, xright = 420, ytop = 455, lwd = 2, border = "red") tp <- crop(rf, extent(110, 420, 350, 455)) r8h <- read.csv(system.file("extdata", "kodak_grey_card.csv", package = "surfspec")) reflm <- t(colSums(tp) / nrow(tp)) refmat <- rf[[1]] for(j in 1:nlayers(rf)) { values(refmat) <- rep(reflm[j, ], each = nrow(rf)) refmat <- refmat * (pi / r8h[j, 2]) rf[[j]] <- (rf[[j]] / refmat) * pi } attr(rf, "metadata") <- attr(cb, "metadata")
cube_rgb(rf, fact = 0.8)
As a final note, the stability of the illumination setup can (should) be tested, by imaging a homogeneous diffuse surface (e.g., a large reference diffuse reflector). Spatial and temporal changes can normally be well identified unless a single gradient aligned to the scan direction is observed. In that case, data can be processed per scan line and per area (beginning of the scan) to separate spatial and temporal effects.
While several common types of processing can be applied to the whole image (in digital counts, radiance or reflectance) there is often the need to extract information over a defined area or pixels of the image. The function cube_sample
is provided with two sampling types: point (or circle) and line. This function is a convenient wrapper for the raster extract function, and the return object keeps relevant metadata in its attributes to allow future plots based on the samples to include the spatial geometries used in the extraction and even to reuse those geometries for a new extraction (either on the same image processed with different parameters or over different images aligned such that relative positions of the target are the same on the image frame).
When sampling points, it is possible to define a buffer in pixel units such that the point is converted to a circle with radius equal to the buffer. No data reduction is applied at this stage and statistics can be applied on the sample object at a later stage. Another possible mode is sampling lines. Those lines are forced to be vertical or horizontal such that profiles can be calculated. It requires that the sample is aligned with the x or y image axis.
For our study case we will sample per line, as vertical profiles:
smp <- cube_sample(3, rf, type = "lines")
x <- matrix(c(217.5833, 217.5833, 261.6981, 261.6981, 343.5497, 343.5497), ncol = 2, nrow = 3, byrow = TRUE) y <- matrix(c(294.7184, 248.9691, 294.7184, 250.0331, 290.9946, 248.9691), ncol = 2, nrow = 3, byrow = TRUE) sample.sp <- list() xyi <- list() for(i in 1:3) { xyi$x <- x[i,] xyi$y <- y[i,] sample.sp[[i]] <- SpatialLines(list(Lines(list(Line(xyi)), ID = as.character(i)))) } sample.sp <- do.call(rbind, sample.sp) smp <- list( type = "lines", n = 3, sp = sample.sp ) smp <- cube_sample(3, rf, type = "lines", reuse = smp)
We can visualize those data with the function sample_plot
, which provides basic visualization. It is possible to add every pixel to the plot, or just descriptive statistics of location and dispersion (defaults are mean
and sd
). It is also possible to subset the samples to include only a given sample with argument id
. In the example below we will show the descriptive statistics of the first two samples. Note that in the case of cross-sectional images and line profiles, this spectral plot of summary statistics is only relevant to see if there is a change along the "x" direction, since all pixels in a given "y" direction profile of a sample are being averaged (so vertical stratification information is lost).
sample_plot(rf, smp, summary = TRUE, loc = mean, disp = sd, na.rm = T, id = c(2, 3))
A wrapper to easily extract the numerical values of the descriptive statistics is the function sample_stat
, called internally by sample_plot
when argument summary = TRUE
. It applies a function to the data - but note that the function should return a single value (like mean
).
sample_stat(smp, mean, single = FALSE, na.rm = TRUE)[1:5, 1:5]
Finally, it is possible to extract data only over the sample area if a region of interest (ROI) mask is included in the metadata of the object. This will be useful if a sample buffer would make a circle grow out of the ROI. Or to sample lines only within the ROI. The ROI mask can be created with image segmentation keeping only 1 cluster, with function cube_seg
explored in the next section.
Our particular interest with this example is to extract the average vertical profile distribution of phythobenthos. While we could manually sample using several sampling lines, this is not ideal. First because manually drawing lines will insert uncertainty on the pixel selection (i.e., may include background or might miss one or two pixels from the top or bottom). It is also not ideal because in principle, with an image where the sample is aligned with the x (or y) axis, every row or scan line is a potential sample.
We will solve the first issue by image segmentation. By masking all other objects in the image other than the target surface, will be simpler to extract information only for the region of interest (ROI). The function cube_seg
will apply the kmeans
function to the hyperspectral cube and allow for interactive aggregation of clusters. The function returns the same cube passed as input, with a new attribute with clusters as a raster layer. For our example we want a single final cluster, with all pixels of the sediment disk (ROI). It is ok if the spectral classification result in some scattered (miss-classified) pixels being included in the final cluster, as long as those are smaller and not spatially connected with the ROI pixels, since it is possible to keep only the largest clump with lcump = TRUE
. This option applies a secondary spatial classification through graph analysis to find clumps of connected pixels and keep only the largest clump. Obviously the option is only useful if only one cluster is desired as the result of the analysis, as is the case when the image classification has the sole purpose of isolating the sample (or a specific region of it) from the rest of the image.
rf <- cube_seg(rf, type = "kmeans", centers = 10, nstart = 10, iter.max = 30, lclump = TRUE) #> Select the lower left and upper right corners of the area to process #> Croping selected area...done! #> Clustering...done! #> Input the number of final aggregated clusters: 1 #> Select clusters to be aggregated as cluster 1 (right click to finish) #> Accept (y | n)? y #> Finding largest clump...done! #> Finished! par(mar = c(5, 5, 3, 3)) plot(attr(rf, "metadata")$cluster, legend = FALSE)
centers <- rbind( c(0.112835740923983, 0.119139503421528, 0.119213503680895, 0.121424221414693, 0.102416496708051, 0.0923083457433726, 0.0884939759485043, 0.0847236945461735, 0.0844802643920035, 0.0852203096111058, 0.0869846727879604, 0.0872353699856571, 0.0856338591032921, 0.0859523269309833, 0.0845862696656869, 0.0833925447334871, 0.0836653017017636, 0.0820931296820949, 0.0829209341449017, 0.0826511640279066, 0.0823256054791768, 0.0823896817663418, 0.0844429207959396, 0.0834786968708013, 0.0847218724436501, 0.0865597839730152, 0.0874471825620375, 0.0894523083729682, 0.0911744002880034, 0.091691371043954, 0.0942358857964729, 0.0952981909116109, 0.0979682703052654, 0.0988529726045624, 0.100276631252447, 0.100978914727489, 0.101889398477997, 0.104082893022672, 0.104108993410684, 0.104882792436651, 0.104492887144997, 0.10493103757526, 0.107019442846352, 0.10554623456203, 0.105476662776351, 0.106464639312404, 0.109120273614163, 0.107071720025673, 0.106824910752855, 0.107185572819772, 0.108160066114244, 0.108766094236603, 0.106752766008001, 0.105497962091954, 0.104572732505217, 0.102363538998021, 0.100141808219558, 0.100037529868181, 0.100689478294582, 0.102740199577545, 0.105830037206107, 0.107130139150663, 0.104639246692361, 0.0992665291941237, 0.100980897852201, 0.108959365015229, 0.122354514551583, 0.142466108846877, 0.153463552544388, 0.145640386483904, 0.133346623427482, 0.123334944504788, 0.115440568348177, 0.110244416476538, 0.109570962250182, 0.115339131056502, 0.128945652664747, 0.106059814236273, 0.119396144673102, 0.121085150930777, 0.121356366344785, 0.123097818953042, 0.123476961329833, 0.125708665229938, 0.123580601839285, 0.128805197376226, 0.128382144904486, 0.123563282442007, 0.12138663279843, 0.128594412271972, 0.121115005090453, 0.123506556778234, 0.130163586327844, 0.132360639535271, 0.129400446653037, 0.134949200647269, 0.134432254093034, 0.130942796851147, 0.133034542766811, 0.133068529869981, 0.132561009792218, 0.137719524235522, 0.13815685256454, 0.130244059070032, 0.139241899433387, 0.137580524410951, 0.135739685387864, 0.144817496916013, 0.16514537249356, 0.149714842470375, 0.137245602006105, 0.143413828451465, 0.140790487370346, 0.140967312158041, 0.139750994599367, 0.136574619525701, 0.141877490159149, 0.140410838585322, 0.139936389468078, 0.141795269045725, 0.142887739483647, 0.143740680958873, 0.144690640163006, 0.144134105652013, 0.144699229830306, 0.145121883312684, 0.145693073308944, 0.145594147582013), c(0.110614468447783, 0.116379883027693, 0.115023496229578, 0.114903813680224, 0.0944322832483489, 0.0817578633707555, 0.0762182808244123, 0.0711465238253939, 0.0689641746510802, 0.0681768555701828, 0.0687820006326675, 0.0687166274002407, 0.0667917302848321, 0.0666421149119345, 0.0655020312246419, 0.0644537206547543, 0.0648828268182272, 0.0638034529782267, 0.0643303835964577, 0.0640413948084271, 0.0638520503248549, 0.0639896975117416, 0.0658568131127176, 0.0652633231336634, 0.0665685003640177, 0.06831725634927, 0.0692928018971323, 0.0709150321756419, 0.0725189135477135, 0.0729776092650308, 0.0752894388787475, 0.0762084126077417, 0.0785964092059861, 0.0796064570409982, 0.0805130645755463, 0.0812700647685932, 0.0822054035339626, 0.0843204733418025, 0.0846970200770625, 0.0855118668426353, 0.0852477525559251, 0.0856985593330626, 0.0874333974673322, 0.086373159065103, 0.0861276693084018, 0.0867489646810917, 0.0887789945555212, 0.0875232954465848, 0.0874448757121064, 0.0875009504509989, 0.088111806496144, 0.0886896231215084, 0.0873188456480092, 0.0869237148767801, 0.0863887247720242, 0.0846491044568779, 0.0830640417947316, 0.0830464724019264, 0.0835966164538711, 0.0853864658390263, 0.0881804363425512, 0.0894826302247707, 0.0873966204785886, 0.0825752394983296, 0.0831405172773405, 0.088533341405503, 0.0983563245623793, 0.113848387446954, 0.122814910329999, 0.116700593686397, 0.107391718497654, 0.0999178124460583, 0.0940145788334364, 0.0894500682775994, 0.0887112044998266, 0.0935299332398209, 0.105043037026273, 0.0873706338764084, 0.097518156939909, 0.0991154918447137, 0.0999198466176268, 0.100914940853277, 0.101237810279044, 0.102965831137952, 0.101417539281508, 0.10608903320829, 0.105927837859597, 0.102293954271191, 0.100769093263531, 0.106752117235039, 0.100612636949759, 0.10285398634386, 0.108277302628739, 0.110259635740427, 0.108476513346139, 0.113008286429078, 0.112614074848014, 0.109640546324612, 0.111569310311524, 0.111397084727924, 0.111423112263748, 0.115722257307721, 0.116977834731125, 0.110658437195184, 0.118204386612326, 0.117655686171732, 0.116556602716782, 0.123914330005847, 0.143138284821884, 0.134121235678584, 0.123644866762071, 0.128945851599334, 0.127601053954072, 0.127672292838472, 0.125685914483473, 0.123533441026154, 0.127934242274263, 0.127222162009039, 0.127763597155158, 0.130361183334666, 0.132357177618783, 0.133735162646439, 0.135073555055132, 0.136604655039789, 0.137786318368147, 0.139158332017704, 0.139960072838806, 0.141171510519614), c(0.106062273306964, 0.118983320704757, 0.135065075888762, 0.156457874432808, 0.16925758396363, 0.185591055322522, 0.193691206020157, 0.196093537416226, 0.19844408628986, 0.198490276281208, 0.201387587772691, 0.201756716031798, 0.202010503060481, 0.204494257313053, 0.204727483215019, 0.203776837995635, 0.204509265699127, 0.202184724142867, 0.202457173218775, 0.200992027115528, 0.199342292971542, 0.199267871791472, 0.201145099197001, 0.198086051208556, 0.19951345226623, 0.199899963900915, 0.199384327419937, 0.201046603046057, 0.201828719024033, 0.200057090474752, 0.201552250423373, 0.200383870991891, 0.200884447367068, 0.202775888485759, 0.202665834038648, 0.202033481496332, 0.201032927542123, 0.203147831455608, 0.202160524750638, 0.202657012163657, 0.204856267628247, 0.203942958760021, 0.203520860362614, 0.203206837651708, 0.200567892444374, 0.19956715172449, 0.20195516735449, 0.197733442214706, 0.19670295899759, 0.195864221159653, 0.195880408919178, 0.195961382246739, 0.191285289309485, 0.187124543760657, 0.186572333134611, 0.1838123677691, 0.182598278220459, 0.182053158699531, 0.180749316470104, 0.182582168770545, 0.184230334168058, 0.181407241979322, 0.17561111480599, 0.168568513818052, 0.168622301679288, 0.176091752448558, 0.185872334706275, 0.191343485807891, 0.189235261543717, 0.18340801316493, 0.177522909220291, 0.171536193550836, 0.166283042211035, 0.164180533634708, 0.166290430395526, 0.169502516229524, 0.177701829487433, 0.155905165828998, 0.164620659486996, 0.165488204286505, 0.163827343097984, 0.161965158566699, 0.16061627953543, 0.161370621568152, 0.158164803175916, 0.163381988409857, 0.160077660467325, 0.155858248884836, 0.151252158757951, 0.157929761373676, 0.149460948913488, 0.151642824550715, 0.158484222938728, 0.159221199415457, 0.156861687655406, 0.159345865530283, 0.157518623730861, 0.153148966877316, 0.155044816058513, 0.155405570454728, 0.154126162666644, 0.156380049321349, 0.156070580186464, 0.151001259046419, 0.153815426156259, 0.150962951859551, 0.150132368234375, 0.152759376681105, 0.161029376243262, 0.155549532297013, 0.147845373220842, 0.151166649251308, 0.149274148588223, 0.147610485684043, 0.145937776211399, 0.144666018627684, 0.145645590059693, 0.144325851243106, 0.142976785404399, 0.143492521071648, 0.144359716141571, 0.144411984562139, 0.144211228409022, 0.143472655578579, 0.142972287465505, 0.142715533892937, 0.143225715995971, 0.143381880811779), c(0.113223810211302, 0.121732143033166, 0.125003311403792, 0.132115162607682, 0.11998410266272, 0.115957669305876, 0.116682264377133, 0.117233066171449, 0.121675731518112, 0.126486030135777, 0.131836886913873, 0.134182413959437, 0.133235047655791, 0.134514917451966, 0.132726177677117, 0.131757455993563, 0.131065857772049, 0.128327915244937, 0.129477926024666, 0.129129977062906, 0.127765925369918, 0.127268337118576, 0.12967656657744, 0.127457142323048, 0.129142620043525, 0.130235290573066, 0.130166587844553, 0.131428011374826, 0.131868538570121, 0.1308890275626, 0.133422888805012, 0.133287273451291, 0.134536459231476, 0.134739083278212, 0.136260678100619, 0.136376324131815, 0.136718753626573, 0.138949120508161, 0.138774452141306, 0.139095114925915, 0.138715469469336, 0.139083550211608, 0.141500972325666, 0.139077798186735, 0.139019481785793, 0.140968180694091, 0.143879968054707, 0.142262465129587, 0.142830319983191, 0.144409255523396, 0.145545677566379, 0.145945069794459, 0.142684764089777, 0.140511079791367, 0.140644167195304, 0.139858509217762, 0.137856673205082, 0.13931012000873, 0.140556255799707, 0.142155730013568, 0.144856778055305, 0.143607420392199, 0.138141871859921, 0.130340312523157, 0.133232348581654, 0.145378069409184, 0.164555467239151, 0.186581607663814, 0.192985618172663, 0.178738763174003, 0.164783046896488, 0.152610557223962, 0.144505217702568, 0.140782956745751, 0.142510014452362, 0.151296647595478, 0.167812258878014, 0.136423051648226, 0.152793277964266, 0.154898591609763, 0.153846745866363, 0.156332568601917, 0.157351371955589, 0.159919208157262, 0.157342984919102, 0.163216445808048, 0.162559904927074, 0.157295073051333, 0.15418495674263, 0.162447066029412, 0.152851830154782, 0.156441735381694, 0.165238153786922, 0.167463817315454, 0.162799289681256, 0.167015733703909, 0.16583718011361, 0.160310479470709, 0.163866654235864, 0.16591907351835, 0.166093848676861, 0.170829219517598, 0.17130063596796, 0.160598481663683, 0.172685981118945, 0.169202667815582, 0.165951040478597, 0.171856626473378, 0.19351894350273, 0.17376697243216, 0.157705279708823, 0.165299212001524, 0.161749770784312, 0.160905414150516, 0.15863462865893, 0.155819827542644, 0.161149580016046, 0.159730032668287, 0.159016463671768, 0.159525855388518, 0.159022763776729, 0.159008716886429, 0.158018580935324, 0.156075662742349, 0.154266504282483, 0.15319259254836, 0.152351187414787, 0.150997178138051), c(0.104099507026665, 0.109802270495316, 0.108266852455403, 0.107137071179023, 0.0873201891627847, 0.0725179263983654, 0.0662778967616633, 0.0607130980314949, 0.0579324107866391, 0.0566500770334694, 0.0565966723582536, 0.0568221943085814, 0.0546454987319071, 0.0543083569390526, 0.0530557503528726, 0.0518547295677172, 0.0519532879198115, 0.0510432457431546, 0.0511832768812071, 0.0509432753515787, 0.0506132484503423, 0.0505576800964956, 0.0519501314922163, 0.0516116754812299, 0.0526736426123643, 0.0540377846239334, 0.055019707653072, 0.0563529735174607, 0.0579238694591351, 0.0585768727142507, 0.0602124347518701, 0.0610379095590336, 0.0632378533540293, 0.0641677218066633, 0.0646545916816902, 0.0654496480500289, 0.0663692408663085, 0.0681050903893078, 0.0687161999295322, 0.0692072521035784, 0.0689708238226503, 0.0693641872414937, 0.0708998885786185, 0.0702745195211628, 0.0699663319297999, 0.070435747377203, 0.0716449204852525, 0.0709302779070569, 0.0709516487157228, 0.0708813027733058, 0.0713317368446133, 0.0721656620768083, 0.071488556384971, 0.0714726127006616, 0.071081289061586, 0.0701448998977682, 0.0692982507156975, 0.0691411552449832, 0.0695705738470047, 0.0708246929366531, 0.073202101861636, 0.0749207003611337, 0.0737165953599261, 0.0697918563727044, 0.0695069779535345, 0.0724103606099831, 0.0787074962860391, 0.0888546689742374, 0.0941845156056063, 0.0902073300578079, 0.0854380427905676, 0.0811279321003256, 0.0774165700473425, 0.0745267426511848, 0.0742323194656668, 0.0781409325469329, 0.0869080514674253, 0.0750999830988481, 0.080873326114777, 0.0818540030636627, 0.0826197599968578, 0.0834275161204135, 0.083623034038945, 0.0848528627393798, 0.0835850067856283, 0.0873805971739675, 0.0871916574049954, 0.0854594692745679, 0.0841190556116697, 0.0887973568053616, 0.0840695989213535, 0.0861457459208994, 0.0905164650594948, 0.091587548513948, 0.090768786617349, 0.0939077605105777, 0.0935565156068675, 0.0921087825694416, 0.0937357125974647, 0.0936894761718419, 0.0937854429315732, 0.0968275102246596, 0.0979836190524058, 0.0947291081580226, 0.099834587850356, 0.100858327370879, 0.100867361888902, 0.106259391803099, 0.120976356086467, 0.119016125880988, 0.113059928694134, 0.116202473055328, 0.115112330051424, 0.115085041960275, 0.113204064535266, 0.111666102226977, 0.115003354755045, 0.115540787718133, 0.116881150068069, 0.118851695545605, 0.121067985882672, 0.123798466658783, 0.125544944314709, 0.127092784886073, 0.129628783357033, 0.131558568351831, 0.133754448257377, 0.135577980834087), c(0.114508108818964, 0.12703374024344, 0.141428277241283, 0.163124511417681, 0.170288836570392, 0.187202539412192, 0.196766897048477, 0.199066186557541, 0.202088307187938, 0.203068980369931, 0.205830750681435, 0.205106933358112, 0.204691576186991, 0.208374051623369, 0.209001550814347, 0.208740024462271, 0.209774340586016, 0.206215886038482, 0.206181340493325, 0.20467012136987, 0.202579736872343, 0.20265882740591, 0.204637806681914, 0.200107663414713, 0.200834663068308, 0.201612364507657, 0.20126740501484, 0.202049399914012, 0.202683675425973, 0.202120528215393, 0.206029814162858, 0.20299333569541, 0.202449505316333, 0.203840353943736, 0.20489753809782, 0.206458996502791, 0.206422225788363, 0.207128754802123, 0.205754348588228, 0.207754515539007, 0.207652644569765, 0.206653022437306, 0.208726294330428, 0.20683134674077, 0.205922337819231, 0.205484529317904, 0.209443411366757, 0.204600432793196, 0.201849322910884, 0.201969979356413, 0.202702647114365, 0.200713924266417, 0.192877646564599, 0.186216395333139, 0.185430952379192, 0.1826847219348, 0.181911454233625, 0.184604479069623, 0.186287774471652, 0.188621731747393, 0.185534253407522, 0.176252825100834, 0.169728541608123, 0.161520992060561, 0.174113666308407, 0.20374118684288, 0.227805397188121, 0.230709294452353, 0.217004628302388, 0.198121767453863, 0.180904289493072, 0.164372665057995, 0.156946752900351, 0.160281208340701, 0.169403968989209, 0.175756086092973, 0.197207127598117, 0.150732530601618, 0.167657748008163, 0.171083115910169, 0.170952551588223, 0.170504594287224, 0.168435956787639, 0.169107303652266, 0.166358991525033, 0.172451199507855, 0.172076587504212, 0.164613701709329, 0.160488453522319, 0.167912807402479, 0.15724506240196, 0.160595555828042, 0.169697980049229, 0.173531400102547, 0.169687042596913, 0.171324709208971, 0.170504055517287, 0.163234885684078, 0.165310497329836, 0.166033884091803, 0.166416142352397, 0.170997373376322, 0.173612978812811, 0.161189737564566, 0.171247681895921, 0.166198356588078, 0.16137582550266, 0.166629284951299, 0.184739289990799, 0.177507360804769, 0.153559823520137, 0.165448466050364, 0.160454126101805, 0.15903318941218, 0.155086152558965, 0.152345917694152, 0.155623829304642, 0.155450084302899, 0.152681391411735, 0.153985330039861, 0.156279341144965, 0.156811836871095, 0.155980691413048, 0.154004923174532, 0.152822583237982, 0.151773056396728, 0.150887784015378, 0.150241380276745), c(0.123600445608929, 0.136124457947161, 0.151228405416958, 0.177448869776473, 0.18515554007399, 0.211191729972602, 0.239433541026696, 0.271300955581917, 0.316291295267917, 0.358645724083381, 0.391688163476016, 0.406185313586205, 0.40337416364087, 0.397434840520854, 0.377252156220416, 0.350907338359369, 0.334168649460904, 0.308179856135101, 0.292617718063334, 0.280035733545899, 0.258841451907915, 0.242788273269537, 0.247299905491884, 0.235128931031025, 0.220639384218625, 0.223767653580696, 0.226896674465881, 0.216857802694437, 0.222430437330216, 0.232529469346874, 0.229979889260398, 0.224981644481578, 0.223934344356022, 0.229820398584245, 0.240176938592441, 0.244400629448512, 0.244528654391173, 0.256392551871835, 0.260649644272037, 0.269650628800115, 0.27573682714707, 0.274152270069829, 0.285580734411875, 0.298575083335871, 0.295045526491271, 0.302495812928235, 0.315622008114895, 0.322392027214091, 0.319954364939972, 0.322475982563836, 0.326590378448446, 0.330639147648105, 0.323159715485951, 0.320064989583833, 0.327447861354187, 0.326922831633104, 0.326858368894411, 0.333978449068372, 0.339821584404461, 0.347696199540108, 0.350400525110739, 0.336085542169198, 0.314601652521305, 0.296118599554849, 0.31575557258394, 0.371546594869523, 0.435011467447987, 0.475784367354459, 0.457606617656965, 0.410334399295232, 0.370983488187588, 0.338725652644243, 0.319202211719972, 0.322406770533355, 0.339250362266308, 0.362652714132632, 0.412194296481117, 0.316087355452871, 0.361526246739443, 0.366378431597715, 0.36417616312466, 0.365866158532087, 0.366233178389766, 0.373412413729562, 0.365661518283622, 0.375281692024261, 0.378321264786695, 0.358991340354637, 0.350121379056305, 0.368703638119672, 0.344646397248778, 0.352720572992607, 0.373339012028679, 0.378081884491381, 0.366251705500184, 0.374782817231284, 0.371041405453253, 0.355396757680903, 0.359719234484213, 0.364274477517163, 0.364262021565563, 0.38090143057089, 0.377433993277096, 0.341208849634443, 0.367519901621909, 0.355725066056327, 0.34259137014548, 0.353930078170918, 0.398575696995649, 0.335252596824257, 0.279909391882558, 0.30435704609389, 0.289124664254289, 0.284008235764251, 0.276872371870374, 0.274264337682219, 0.287070717524599, 0.279595815236606, 0.269424155196816, 0.268118285943591, 0.263528755811787, 0.256795313702059, 0.24621630574345, 0.232333979357487, 0.221708641165779, 0.211034495836843, 0.204945845263345, 0.193420543557122), c(0.0887841837076874, 0.0967033012497305, 0.100349210995802, 0.103411037790377, 0.0964388378664979, 0.0888651523163083, 0.0963468161565718, 0.114436056716737, 0.149332576316276, 0.193105939095485, 0.232329733501874, 0.264017154703607, 0.271047559211489, 0.280058895305042, 0.277742309494359, 0.269527981053421, 0.262796396906281, 0.25881497624454, 0.254980471619081, 0.250948998327392, 0.246166330927921, 0.238858928097804, 0.234359448606318, 0.226209226767037, 0.21761945319574, 0.215655291402349, 0.211454588170189, 0.207113942587292, 0.201940916854926, 0.194749320361535, 0.189061752670295, 0.185861405399111, 0.183696407225582, 0.181585885184906, 0.179808845076342, 0.178810963738585, 0.176752584137561, 0.173213336110208, 0.170458969941599, 0.16850128112232, 0.170836205457474, 0.17262110046944, 0.173178785955989, 0.175609357359804, 0.175818580152827, 0.177315004731484, 0.178316628807908, 0.178608292477855, 0.179676280386613, 0.180373104811641, 0.181459160847264, 0.184526733712531, 0.185305872348824, 0.188725425866841, 0.195199454592565, 0.201812280988916, 0.209554879039688, 0.211202829381525, 0.209694705978789, 0.209011650469846, 0.205709980547474, 0.198846093887679, 0.199374835101689, 0.204992155083502, 0.2149770272709, 0.226115481165276, 0.227086400003885, 0.205303774094433, 0.177682004353754, 0.170627602388346, 0.178614609250285, 0.185505796770949, 0.196927043003636, 0.215308892143356, 0.235794210501114, 0.242193745925339, 0.238130910309045, 0.233280608368272, 0.221803088612397, 0.221193813349076, 0.221396489843159, 0.220581940675578, 0.221710900755103, 0.223373110778775, 0.218338139685162, 0.223363335350732, 0.214058906059906, 0.216751621968077, 0.212602389013943, 0.220558711351492, 0.211330581436161, 0.212643469778623, 0.220520573259326, 0.217414371200375, 0.216928023581553, 0.212401963544614, 0.203809733470003, 0.194391524585625, 0.19589466259474, 0.202875077411845, 0.206082013080355, 0.205085762476125, 0.204470874951529, 0.206791657899458, 0.201333673394458, 0.19949924559119, 0.198683872263193, 0.190622562978188, 0.176558899411696, 0.187625703775985, 0.187776908336356, 0.185062206094823, 0.184885071302535, 0.18287384686608, 0.182232589131654, 0.184338696214147, 0.176391325445257, 0.176729239587091, 0.175319931793324, 0.172444348059241, 0.167571867546233, 0.163046099129766, 0.158432598604235, 0.157433496430667, 0.153534267586891, 0.151314149427618, 0.150781417348029, 0.148894582838167), c(0.111774605443226, 0.125719675173362, 0.13929011804216, 0.160792890972659, 0.16903462401573, 0.184347101615048, 0.197771873069452, 0.209842769209953, 0.22652743457287, 0.243101568746508, 0.258016246480539, 0.264867008115877, 0.265961533083635, 0.271114544102959, 0.269585265613654, 0.266592421495885, 0.266025758092748, 0.258965726667906, 0.255858763687167, 0.250202947661427, 0.238775874177615, 0.229771741172847, 0.233439020228152, 0.223922490890996, 0.214301661058676, 0.216868966087407, 0.218773692152372, 0.211059463374755, 0.215127392836353, 0.220420831631796, 0.220156590947334, 0.216706848538974, 0.216344993963253, 0.21991288128729, 0.226396432365565, 0.227517537334386, 0.2273013080452, 0.234149036235085, 0.234669630799223, 0.239050845852962, 0.241516559877816, 0.239749689312542, 0.24539082121177, 0.2472446050641, 0.244838222751723, 0.24796200185722, 0.252999510579542, 0.251243074296736, 0.251428877277409, 0.254828610183562, 0.256488441288763, 0.256858105241668, 0.250868065830539, 0.248117637327489, 0.249558214280827, 0.247113398805845, 0.246344511890236, 0.249524269106926, 0.252393618846933, 0.255128362891721, 0.255119453604315, 0.247589311105948, 0.238339832746515, 0.229866073083352, 0.240963832091759, 0.268061310527664, 0.293909037997033, 0.307393130207179, 0.29710400287135, 0.273894644762371, 0.256839484487679, 0.240866233284275, 0.234643254611714, 0.240649358095492, 0.252495784275964, 0.263565115849761, 0.281754994911014, 0.236400024308001, 0.254877974662711, 0.257867078059444, 0.257289007744368, 0.258039949571385, 0.257773025983981, 0.260600668213823, 0.254511635969667, 0.262435213023541, 0.260328729216959, 0.253312717064046, 0.247179292398048, 0.259060278754024, 0.243863342658562, 0.249423631229529, 0.261282764923047, 0.263164968065479, 0.25748452405427, 0.26143966659027, 0.258104872104584, 0.248506718808237, 0.251818866706362, 0.254948346528645, 0.254327769957337, 0.259505753569743, 0.259431754257165, 0.24437162641655, 0.255289471872589, 0.24787331916684, 0.241980442375529, 0.246536678105008, 0.2636448687819, 0.237092766618612, 0.212392584292912, 0.22385947391683, 0.217140324925091, 0.214568296155217, 0.209807333043393, 0.208647414421042, 0.212322128790559, 0.208179544036587, 0.203988272404554, 0.20438548568271, 0.200035257958898, 0.196193726002878, 0.190543915090315, 0.186215222429703, 0.181113864952589, 0.174233477891368, 0.171720527386402, 0.168417734221793), c(0.0940300337468149, 0.108931503788282, 0.12992683274649, 0.153095688634757, 0.180323726847525, 0.192551682229498, 0.199902018009348, 0.202948758246051, 0.205117807882803, 0.205092836473534, 0.205908915817695, 0.209645982066222, 0.210594040831231, 0.212346165262376, 0.213673961669256, 0.21229222347992, 0.210449996874966, 0.212189053028265, 0.20973234654678, 0.207205892313905, 0.208361232705673, 0.208448027966856, 0.206551363716793, 0.205748936144221, 0.206774447418945, 0.20582540414313, 0.206347765173295, 0.20696812944932, 0.207641839005051, 0.207986986455299, 0.207549827498842, 0.206713471201386, 0.206922522019511, 0.208396353400128, 0.207897621006316, 0.210077671290543, 0.209394096397965, 0.208438681468075, 0.208660491401068, 0.208882852983576, 0.211462317473727, 0.210863699710631, 0.209168176136983, 0.209289051766767, 0.20677826670037, 0.207565440068039, 0.207254915760042, 0.205101319022087, 0.203180034681679, 0.201338517874458, 0.199801713266985, 0.198248016789157, 0.196199984369647, 0.195320884928153, 0.198179731860345, 0.19997532309497, 0.202351466074963, 0.20207194860282, 0.198667830476865, 0.195079190028027, 0.189613038233111, 0.184916997567563, 0.189414803392359, 0.200110821675736, 0.21052965010543, 0.213085635915155, 0.194541964502897, 0.165573975254977, 0.148647924517382, 0.148362366800177, 0.153814119105151, 0.159103775963797, 0.171772150938098, 0.188249871680911, 0.197270668657234, 0.189153650554888, 0.180173208888159, 0.183139288434607, 0.171997152559581, 0.172337349829281, 0.172077848947085, 0.168250261669634, 0.165905671977749, 0.165335820781252, 0.160728225403008, 0.16433162883287, 0.158357958126347, 0.162234217610292, 0.157779928061606, 0.161405811587965, 0.155680456239934, 0.157706921083774, 0.162310405464552, 0.159914985399532, 0.162743140039333, 0.162305098061346, 0.161208830361573, 0.159579517211889, 0.159975896968462, 0.158496839943705, 0.155845157705207, 0.153082916717012, 0.153515328621224, 0.15823719509212, 0.153304602049659, 0.153657284898027, 0.155220002742855, 0.149954081289902, 0.14030446371138, 0.153040421367763, 0.153481189713858, 0.151581644286047, 0.15151759718194, 0.149548902987842, 0.148133072070998, 0.149985331480851, 0.145133722681868, 0.145646804890387, 0.144202077276362, 0.141275705797406, 0.141007671264377, 0.140857681406534, 0.14142597872622, 0.141993573806223, 0.1412547778776, 0.141242612554097, 0.140588586910816, 0.140660549995183) ) par(mar = c(5, 5, 3, 2), mfcol = c(1, 2)) cube_rgb(rf, log = FALSE, main = "Select LL and UR of area to process") rect(xleft = 150, ybottom = 250, xright = 420, ytop = 350, lwd = 2, border = "red") tp <- crop(rf, extent(150, 420, 250, 350)) val <- raster::values(tp) id <- as.logical(apply(val, 1, sum)) clf <- kmeans(val[which(!is.na(id)), ], centers = centers, nstart = 1) val[which(!is.na(id)), 1] <- clf$cluster clfr <- tp[[1]] values(clfr) <- val[, 1] * id n <- 10 cols <- n %>% rainbow(start = 0, end = 0.8) %>% rev() raster::plot(clfr, main = "Select the clusters to aggregate", col = colorRampPalette(cols)(256), legend = FALSE, xlab = "Scan line", ylab = "Row") m <- cbind(1:10, c(1, 1, NA, 1, 1, NA, NA, NA, NA, NA)) clfr <- reclassify(clfr, m) clfr_sp <- raster::clump(clfr) tb <- table(raster::values(clfr_sp)) id <- as.numeric(names(sort(tb, decreasing = TRUE))[1]) clfr[clfr_sp != id] <- NA clfr <- extend(clfr, extent(rf)) meta <- attr(rf, "metadata") meta$cluster <- clfr attr(rf, "metadata") <- meta
par(mar = c(5, 5, 3, 3)) plot(attr(rf, "metadata")$cluster, xlab = "Scan line", ylab = "Row", legend = FALSE)
Now that we have a sample mask on the object metadata, we can extract and align all possible profiles in a given orientation (columns for "y", or rows for "x"). This is performed by the function cube_pro_seg
. For profiles along "y" axis (default), the profiles will be aligned at their top most pixel. For profiles along "x" axis, the profiles will be aligned at their left most pixel. For the our sample dataset, we will extract all "y" profiles and visualize the spatial distribution of NDVI. Note that because of the alignment, every pixel at a given row is at the same distance of the top of the sediment.
pf <- cube_pro_seg(rf) par(mar = c(5, 5, 3, 3)) plot((pf[[86]] - pf[[60]]) / (pf[[86]] + pf[[60]]), xlab = "Scan line", ylab = "Row")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.