SkillAgentSearch skills...

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/FIELDimageR
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

FIELDimageR: A Tool to Analyze Images From Agricultural Field Trials and Lab in R.

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.

<p align="center"> <img src="https://raw.githubusercontent.com/filipematias23/images/master/readme/FIELDimageR.jpg" width="70%" height="70%"> </p> <div id="menu" />

Resources

Installation

1. First steps

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

12. Crop growth cycle

13. Multispectral and Hyperspectral images

14. Building shapefile with polygons (field blocks, pest damage, soil differences, etc)

15. Making plots

16. Saving output files

Orthomosaic using the open source software OpenDroneMap

Parallel and loop to evaluate multiple images (e.g. images from roots, leaves, ears, seed, damaged area, etc.)

Quick tips (memory limits, splitting shapefile, using shapefile from other software, etc)

Contact

<div id="instal" />

Installation

If desired, one can build a rocker/rstudio based Docker image with all the requirements already installed by using the Dockerfile in this repository.

<div id="Instal_no_docker" />

With RStudio

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.

<br />

Now install R/FIELDimageR using the install_github function 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:

  • docker is the Docker command itself
  • build tells Docker that we want to build an image
  • -t indicates that we will be specifying then tag (name) of the created image
  • fieldimager is the tag (name) of the image and can be any acceptable name; this needs to immediately follow the -t parameter
  • -f indicates that we will be providing the name of the Dockerfile containing the instructions for building the image
  • ./Dockerfile is the full path to the Dockerfile containing the instructions (in this case, it's in the current folder); this needs to immediately follow the -f parameter
  • ./ 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 substitute rocker/tidyverse in the first line of Dockerfile with rocker/rstudio for a RStudio environment without the tidyverse package.

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

Open a web browser window and enter http://localhost:8787 to access the running container. To log into the instance use the username and password of rstudio and yourpasswordhere.

<br />

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 />

Menu

<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)

Menu

<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>

Menu

<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>

Menu

<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

View on GitHub
GitHub Stars264
CategoryEducation
Updated20d ago
Forks96

Languages

R

Security Score

95/100

Audited on Mar 8, 2026

No findings