FIELDimageR
FIELDimageR: A R package to analyze orthomosaic images from agricultural field trials. This package is a compilation of functions to analyze pos-mosaicking images from research fields, and allows to: crop the image; remove soil effect; build vegetation indices; rotate the image; build the plot shapefile; extract information for each plot; and evaluate stand count, canopy percentage, and plant height.
Install / Use
/learn @OpenDroneMap/FIELDimageRREADME
FIELDimageR: A Tool to Analyze Images From Agricultural Field Trials and Lab in R.
<p align="center"> <img src="https://raw.githubusercontent.com/filipematias23/images/master/readme/FIELDimageR.jpg" width="70%" height="70%"> </p> <div id="menu" />This package is a compilation of functions to analyze orthomosaic images from research fields. To prepare the image it first allows to crop the image, remove soil and weeds and rotate the image. The package also builds a plot shapefile in order to extract information for each plot to evaluate different wavelengths, vegetation indices, stand count, canopy percentage, and plant height.
Resources
2. Loading mosaics and visualizing
3. Removing soil using vegetation indices
4. Building the plot shapefile
5. Building vegetation indices
6. Counting the number of objects (e.g. plants, seeds, etc)
7. Evaluating the object area percentage (e.g. canopy)
8. Extracting data from field images
9. Estimating plant height (e.g., biomass) and creating interpolated mosaics based on sampled points
10. Distance between plants, objects length, and removing objects (plot, cloud, weed, etc.)
11. Resolution and computing time
13. Multispectral and Hyperspectral images
14. Building shapefile with polygons (field blocks, pest damage, soil differences, etc)
Orthomosaic using the open source software OpenDroneMap
Quick tips (memory limits, splitting shapefile, using shapefile from other software, etc)
<div id="instal" />Installation
<div id="Instal_no_docker" />If desired, one can build a rocker/rstudio based Docker image with all the requirements already installed by using the Dockerfile in this repository.
With RStudio
<br />First of all, install R and RStudio. Then, in order to install R/FIELDimageR from GitHub GitHub repository, you need to install the following packages in R. For Windows users who have an R version higher than 4.0, you need to install RTools, tutorial RTools For Windows.
Now install R/FIELDimageR using the
install_githubfunction from devtools package. If necessary, use the argument type="source".
# You may need other packages first:
install.packages(c('terra','mapview','sf','stars','caret','mapedit','devtools',"dplyr","fields","leafem","leafsync","lwgeom","BiocManager","git2r","exactextractr"))
BiocManager::install("EBImage")
# FIELDimageR:
devtools::install_github("OpenDroneMap/FIELDimageR")
devtools::install_github("filipematias23/FIELDimageR.Extra")
If the method above doesn't work, use the next lines by downloading the FIELDimageR-master.zip file
setwd("~/FIELDimageR-master.zip") # ~ is the path from where you saved the file.zip
unzip("FIELDimageR-master.zip")
file.rename("FIELDimageR-master", "FIELDimageR")
shell("R CMD build FIELDimageR") # or system("R CMD build FIELDimageR")
install.packages("FIELDimageR_0.6.0.tar.gz", repos = NULL, type="source") # Make sure to use the right version (e.g. 0.6.0)
<br />
<p align="center">
<img src="https://raw.githubusercontent.com/filipematias23/images/master/readme/Install.jpg" width="50%" height="50%">
</p>
<br />
<div id="Instal_with_docker" />
<br />
With Docker
When building the Docker image you will need the Dockerfile in this repository available on the local machine. Another requirement is that Docker is installed on the machine as well.
Open a terminal window and at the command prompt enter the following command to build the Docker image:
docker build -t fieldimager -f ./Dockerfile ./
The different command line parameters are as follows:
dockeris the Docker command itselfbuildtells Docker that we want to build an image-tindicates that we will be specifying then tag (name) of the created imagefieldimageris the tag (name) of the image and can be any acceptable name; this needs to immediately follow the-tparameter-findicates that we will be providing the name of the Dockerfile containing the instructions for building the image./Dockerfileis the full path to the Dockerfile containing the instructions (in this case, it's in the current folder); this needs to immediately follow the-fparameter./specifies that Docker build should use the current folder as needed (required by Docker build)The container includes a copy of RStudio Server and
tidyverse(see rocker/tidyverse). Alternatively, you can substituterocker/tidyversein the first line ofDockerfilewithrocker/rstudiofor a RStudio environment without thetidyversepackage.Once the docker image is built, you use the Docker run command to access the image using the suggested rocker/rstudio command:
docker run --rm -p 8787:8787 -e PASSWORD=yourpasswordhere fieldimager
<br />Open a web browser window and enter
http://localhost:8787to access the running container. To log into the instance use the username and password ofrstudioandyourpasswordhere.
If you are using anaconda and Linux
To install this package on Linux and anaconda it is necessary to use a series of commands before the recommendations
- Install Xorg dependencies for the plot system (on conda shell)
conda install -c conda-forge xorg-libx11
- Install the BiocManager package manager
install.packages("BiocManager")
- Use the BiocManager to install the EBIMAGE package
BiocManager::install("EBImage")
- If there is an error in the fftw3 library header (fftw3.h) install the dependency (on conda shell)
conda install -c eumetsat fftw3
- If there is an error in the dependency doParallel
install.packages ("doParallel")
- Continue installation
setwd("~/FIELDimageR-master.zip") # ~ is the path from where you saved the file.zip
unzip("FIELDimageR-master.zip")
file.rename("FIELDimageR-master", "FIELDimageR")
system("R CMD build FIELDimageR") #only system works on linux
install.packages("FIELDimageR_0.6.0.tar.gz", repos = NULL, type="source") # Make sure to use the right version (e.g. 0.6.0)
<br />
<div id="p1" />
Using R/FIELDimageR
<p align="center"> <img src="https://raw.githubusercontent.com/filipematias23/images/master/readme/RStudio.jpg" > </p>1. First steps
Taking the first step:
library(FIELDimageR)
library(FIELDimageR.Extra)
library(raster)
library(terra)
library(mapview)
library(sf)
library(stars)
<div id="p2" />
2. Loading mosaics and visualizing
The following example uses an image available to download here: EX1_RGB.tif. If necessary, the image/mosaic size can be reduced around the field boundaries for faster image analysis using the function:
fieldCrop.
# Uploading an example mosaic
EX1 <- rast("EX1_RGB.tif")
# Visualization Option-01 (FIELDimageR.Extra):
fieldView(EX1)
# Visualization Option-02 (raster):
plotRGB(EX1, r = 1, g = 2, b = 3)
# Only if necessary you can crop the mosaic/image to reduce size:
# x11()
# EX1 <- rast(fieldCrop(mosaic = EX1)) # For heavy images (large, high resolution, etc.) please use: fast.plot=T
<br />
<p align="center">
<img src="https://raw.githubusercontent.com/filipematias23/images/master/readme/F1.jpeg">
</p>
<br />
# If necessary you can crop the mosaic/image to reduce size by selecting the aoi (area of interest) using fieldView with editor=TRUE:
aoi<-fieldView(EX1,editor = TRUE)
EX1<-crop(EX1,aoi) # For heavy images (large, high resolution, etc.) please use: fast.plot=T
fieldView(EX1)
<br />
<p align="center">
<img src="https://raw.githubusercontent.com/filipematias23/images/master/readme/FexNew1.jpg">
</p>
<div id="p3" />
3. Removing soil using vegetation indices
The presence of soil can introduce bias in the data extracted from the image. Therefore, removing soil from the image is one of the most important steps for image analysis in agricultural science. Function to use:
fieldMask
EX1.RemSoil <- fieldMask(mosaic = EX1, Red = 1, Green = 2, Blue = 3, index = "HUE")
<br />
<p align="center">
<img src="https://raw.githubusercontent.com/filipematias23/images/master/readme/F3.jpeg">
</p>
<div id="p5" />
4. Building the plot shape file
Once the field has reached a correct straight position, the plot shape file can be drawn by selecting at least four points at the corners of the experiment. Th
