Title: | Automatic Detection of Experimental Unit in Precision Agriculture |
---|---|
Description: | A part of precision agriculture is linked to the spectral image obtained from the cameras. With the image information of the agricultural experiment, the included functions facilitate the collection of spectral data associated with the experimental units. Some designs generated in R are linked to the images, which allows the use of the information of each pixel of the image in the experimental unit and the treatment. Tables and images are generated for the analysis of the precision agriculture experiment during the entire vegetative period of the crop. |
Authors: | Felipe de Mendiburu [aut, cre], David Mauricio [aut], Rodrigo Morales [aut], Roberto Quiroz [aut] |
Maintainer: | Felipe de Mendiburu <[email protected]> |
License: | GPL |
Version: | 1.0.5 |
Built: | 2024-11-26 06:33:29 UTC |
Source: | CRAN |
Generates the spectral information of the edge of the EUs for analysis of the border effect, it requires the spectral image, the distance of the border and the segmentation of the EUs generated by imageField.
borderPoint(r,Rbook,distance,plotting=TRUE,...)
borderPoint(r,Rbook,distance,plotting=TRUE,...)
r |
spectral image |
Rbook |
Object generated by imageField |
distance |
distance defining the border of the exterior to the experimental plot |
plotting |
Logic value to display the image of the border effect around the EUs |
... |
plot parameter to document the image as main, axis, etc |
Set the border in terms of distance in units measured in the field
Qborder |
Border bounds matrix |
border |
dataframe spectral border and that is expressed in the image. |
Felipe de Mendiburu
cassava
, fourPoint
, imageField
# use cassava crop information library(rPAex) data(cassava) r <- terra::rast(cassava,type="xyz") # cassava area # Apply: x11() terra::image(r,axes=FALSE) # p <- locator(3) to generate 3 points in the area p<-list(x=c(287689.4, 287702.8, 287706.2),y=c(8664210, 8664214, 8664179)) # Generate the fourth points of the area q<-fourPoint(p) op<-par(mfrow=c(1,3),mar=c(0,0,0,0)) terra::image(r,axes=FALSE) text(287693.3,8664215,"Image crop",cex=1.5) r <- terra::rast(cassava,type="xyz") # cassava area # Apply: p <- locator(3) to generate 3 points in the area p<-list(x=c(287689.4, 287702.8, 287706.2),y=c(8664210, 8664214, 8664179)) # Generate the fourth points of the area q<-fourPoint(p) op<-par(mfrow=c(1,3),mar=c(0,0,0,0)) terra::image(r,axes=FALSE) text(287693.3,8664215,"Image crop",cex=1.5) # The area is divided into 3x2 plots of 11x6 meters per experimental unit Rbook<-imageField(r,q,3,2,11,6,plotting=TRUE) out<-borderPoint(r,Rbook,distance=1,axes=FALSE) text(287693.4, 8664214, "Border",cex=1.5) # NDVI in border ndvi<-with(out$Border, (L1-L2)/(L1+L2)) # NDVI > 0.5 more probability of vegetation plt<-out$Border[ndvi>0.5,1:2] w<-terra::rast(out$Border) text(287693.3,8664215,"Border",cex=1,5) terra::image(w,axes=FALSE) text(287693.3,8664215,"Vegetation",cex=1.5) points(plt,cex=0.2,col=colors()[51],pch=20) par(op)
# use cassava crop information library(rPAex) data(cassava) r <- terra::rast(cassava,type="xyz") # cassava area # Apply: x11() terra::image(r,axes=FALSE) # p <- locator(3) to generate 3 points in the area p<-list(x=c(287689.4, 287702.8, 287706.2),y=c(8664210, 8664214, 8664179)) # Generate the fourth points of the area q<-fourPoint(p) op<-par(mfrow=c(1,3),mar=c(0,0,0,0)) terra::image(r,axes=FALSE) text(287693.3,8664215,"Image crop",cex=1.5) r <- terra::rast(cassava,type="xyz") # cassava area # Apply: p <- locator(3) to generate 3 points in the area p<-list(x=c(287689.4, 287702.8, 287706.2),y=c(8664210, 8664214, 8664179)) # Generate the fourth points of the area q<-fourPoint(p) op<-par(mfrow=c(1,3),mar=c(0,0,0,0)) terra::image(r,axes=FALSE) text(287693.3,8664215,"Image crop",cex=1.5) # The area is divided into 3x2 plots of 11x6 meters per experimental unit Rbook<-imageField(r,q,3,2,11,6,plotting=TRUE) out<-borderPoint(r,Rbook,distance=1,axes=FALSE) text(287693.4, 8664214, "Border",cex=1.5) # NDVI in border ndvi<-with(out$Border, (L1-L2)/(L1+L2)) # NDVI > 0.5 more probability of vegetation plt<-out$Border[ndvi>0.5,1:2] w<-terra::rast(out$Border) text(287693.3,8664215,"Border",cex=1,5) terra::image(w,axes=FALSE) text(287693.3,8664215,"Vegetation",cex=1.5) points(plt,cex=0.2,col=colors()[51],pch=20) par(op)
The image of the cassava crop corresponds to flight 11 recorded by the drone on February 26, 2015 at the International Potato Center, with a multispectral camera. The cultivation area includes 6 plots of 11 x 6 meters. Due to the size of the images, only image 11 was used in rPAex.
data("cassava")
data("cassava")
A data frame with 262056 observations on the following 5 variables.
x
coordinate X, a numeric vector
y
coordinate Y, a numeric vector
L1
Near-Infrared Light (NIR), a numeric vector
L2
Red band, a numeric vector
L3
Green band, a numeric vector
The cassava crop data was built with the TTC_0559_georeferenced.tif image (Loayza, 2018) and the terra package (Hijmans, 2023).
International Potato Center. CIP - Lima Peru. Dataverse CIP.
Loayza, Hildo; Silva, Luis; Palacios, Susan; Balcazar, Mario; Quiroz, Roberto, 2018, "Dataset for: Modelling crops using high resolution multispectral images", <doi: 10.21223/P3/UVWVLA>, International Potato Center, V1
Hijmans R (2023). _terra: Spatial Data Analysis. https://CRAN.R-project.org/package=terra
cropTime
, EUsPoint
, imageField
, borderPoint
library(rPAex) # Generation of cassava data # download the TTC_0559_georeferenced.tif image from CIP DATAVERSE repository # library(terra) # img = "TTC_0559_georeferenced.tif" # r<-rast(img) # e = ext(287688, 287709, 8664174, 8664217) # rc = crop(r, e) # terra::image(rc) # Image cassava # to use locator(), fourPoint() and imageField() to generate the cassava data data(cassava) # Contains 262056 pixels of 5 centimeters each with multispectral data r<-terra::rast(cassava,type="xyz") terra::image(r) # Image cassava
library(rPAex) # Generation of cassava data # download the TTC_0559_georeferenced.tif image from CIP DATAVERSE repository # library(terra) # img = "TTC_0559_georeferenced.tif" # r<-rast(img) # e = ext(287688, 287709, 8664174, 8664217) # rc = crop(r, e) # terra::image(rc) # Image cassava # to use locator(), fourPoint() and imageField() to generate the cassava data data(cassava) # Contains 262056 pixels of 5 centimeters each with multispectral data r<-terra::rast(cassava,type="xyz") terra::image(r) # Image cassava
Spectral data of the cassava crop during its development, of the 38 spectral images of the data repository of the International Potato Center, plot number 3 of 6 cultivated, is described in 9 moments of its development, obtaining near-infrared, red responses and green
data("cropTime")
data("cropTime")
A data frame with 172263 observations on the following 6 variables.
Flight
a numeric vector
x
coordinate X, a numeric vector
y
coordinate Y, a numeric vector
L1
Near-Infrared Light (NIR), a numeric vector
L2
Red band, a numeric vector
L3
Green band, a numeric vector
The images were read with the rast function (Hijmans, 2023), plot 3 was located and the information of the 38 images was obtained with the rPAex imageField function. Due to the size of the images, only 9 images were used as part of the rPAex data. The images were captured with a Remotely Piloted Aircraft System (RPAS), the system included an OKtokoter platform and an multiespectral camera (MicroADC-Tetracam). The multiespectral images are composed of information in the NIR, Red and Green bands. The images were acquired at 95 meteres average flight altitude. drone flight date, began on December 18, 2014, and ended on November 4, 2015 (Loayza, 2018). The cropTime data table was built from the "tif" images and the terra package (Himans, 2023). The R code instructions for reading the images were similar to the "cassava data" construction, in which the rPAex function imageField() was added, to then select plot-3 of 9 images separated in time.
International Potato Center. CIP - Lima Peru. Dataverse CIP.
Loayza, Hildo; Silva, Luis; Palacios, Susan; Balcazar, Mario; Quiroz, Roberto, 2018, "Dataset for: Modelling crops using high resolution multispectral images", doi: 10.21223/P3/UVWVLA, International Potato Center, V1
Hijmans R (2023). _terra: Spatial Data Analysis_. https://CRAN.R-project.org/package=terra.
cassava
, EUsPoint
, imageField
,
borderPoint
library(rPAex) data(cropTime) ndvi<-with(cropTime,(L1-L2)/(L1+L2)) ndviTime<-data.frame(cropTime,ndvi) fly<-c(1, 2, 6, 11, 20, 23, 30, 36, 38) dates<-c("2014-12-18","2015-01-06","2015-01-29","2015-02-26","2015-04-22", "2015-05-15", "2015-07-03","2015-08-13","2015-08-28") #x11() op<-par(mfrow=c(3,3),mar=c(0,0,1,0),cex=0.8) for(i in 1:9){ P<-ndviTime[ndviTime$Flight==fly[i],] P$ndvi<-(P$L1-P$L2)/(P$L1+P$L2) I<-terra::rast(P[,c(2,3,7)],type="xyz") terra::image(I,col= hcl.colors(12, "Greens 3", rev = TRUE),axes=FALSE, main=paste("fligth:", fly[i])) } par(op)
library(rPAex) data(cropTime) ndvi<-with(cropTime,(L1-L2)/(L1+L2)) ndviTime<-data.frame(cropTime,ndvi) fly<-c(1, 2, 6, 11, 20, 23, 30, 36, 38) dates<-c("2014-12-18","2015-01-06","2015-01-29","2015-02-26","2015-04-22", "2015-05-15", "2015-07-03","2015-08-13","2015-08-28") #x11() op<-par(mfrow=c(3,3),mar=c(0,0,1,0),cex=0.8) for(i in 1:9){ P<-ndviTime[ndviTime$Flight==fly[i],] P$ndvi<-(P$L1-P$L2)/(P$L1+P$L2) I<-terra::rast(P[,c(2,3,7)],type="xyz") terra::image(I,col= hcl.colors(12, "Greens 3", rev = TRUE),axes=FALSE, main=paste("fligth:", fly[i])) } par(op)
It uses a design generated by the agricolae package in a raster image.
designRaster(R,book)
designRaster(R,book)
R |
output object imageField |
book |
function output field book design.* agricolae |
The R object contains the following information: pixel coordinates and image layer information.
The outDesign object is generated by the design functions of the agricolae package
design |
The matrix R of the image with the experimental design information |
rasterField |
the R matrix of the image with the information of the bands and the characteristics of the experimental design |
Felipe de Mendiburu
Felipe de Mendiburu (2019). agricolae: Statistical Procedures for Agricultural Research. R package version 1.3-1. http://tarwi.lamolina.edu.pe/~fmendiburu\
Kwanchai A. Gomez, Arturo A. Gomez (1984). Statistical Procedures for Agricultural Research. John Wiley & Sons, new York.
# alpha design with 12 treatments library(rPAex) # r = simulated raster image data prg1 <- system.file("examples/Ex-01.R", package="rPAex") source(prg1) r<-data1() # Alpha design, r-raster image trt<-1:12 t <- length(trt) # size block k k<-3 # Blocks s s<-t/k # replications r =2 outdesign<- agricolae::design.alpha(trt,k=3,r=2,serie=1) r1<-subset(outdesign$book, replication==1) r2<-subset(outdesign$book, replication==2) #-------- #x11() op<-par(mar=c(2,2,3,2),cex=0.8) terra::image(r,main="alpha design in the image with the distribution of treatments",col=col2rgb(10),axes=FALSE) axis(1); axis(2,seq(0,100,20)) #P<-locator(3) p1<-list(x=c(4.27, 35.42, 47.49),y=c(68.12, 70.82, 23.63)) q1<-fourPoint(p1) p2<-list(x=c(50.27, 81.42, 93.49),y=c(68.12, 70.82, 23.63)) q2<-fourPoint(p2) polygon(q1,lwd=3,lty=2,border=colors()[51]) polygon(q2,lwd=3,lty=2,border=colors()[51]) R1<-imageField(r, Q=q1, ny=4, nx=3, dy=10, dx=9,col=colors()[18]) R2<-imageField(r, Q=q2, ny=4, nx=3, dy=10, dx=9,col=colors()[18]) q1<-designRaster(R=R1$Qbase,book=r1)$design q2<-designRaster(R=R2$Qbase,book=r2)$design text(q1[,6],q1[,7],q1[,4]) text(q2[,6],q2[,7],q2[,4]) par(op)
# alpha design with 12 treatments library(rPAex) # r = simulated raster image data prg1 <- system.file("examples/Ex-01.R", package="rPAex") source(prg1) r<-data1() # Alpha design, r-raster image trt<-1:12 t <- length(trt) # size block k k<-3 # Blocks s s<-t/k # replications r =2 outdesign<- agricolae::design.alpha(trt,k=3,r=2,serie=1) r1<-subset(outdesign$book, replication==1) r2<-subset(outdesign$book, replication==2) #-------- #x11() op<-par(mar=c(2,2,3,2),cex=0.8) terra::image(r,main="alpha design in the image with the distribution of treatments",col=col2rgb(10),axes=FALSE) axis(1); axis(2,seq(0,100,20)) #P<-locator(3) p1<-list(x=c(4.27, 35.42, 47.49),y=c(68.12, 70.82, 23.63)) q1<-fourPoint(p1) p2<-list(x=c(50.27, 81.42, 93.49),y=c(68.12, 70.82, 23.63)) q2<-fourPoint(p2) polygon(q1,lwd=3,lty=2,border=colors()[51]) polygon(q2,lwd=3,lty=2,border=colors()[51]) R1<-imageField(r, Q=q1, ny=4, nx=3, dy=10, dx=9,col=colors()[18]) R2<-imageField(r, Q=q2, ny=4, nx=3, dy=10, dx=9,col=colors()[18]) q1<-designRaster(R=R1$Qbase,book=r1)$design q2<-designRaster(R=R2$Qbase,book=r2)$design text(q1[,6],q1[,7],q1[,4]) text(q2[,6],q2[,7],q2[,4]) par(op)
The Q matrix is formed by 4 points that limits the Experimental unit, this matrix is used by the imageField function to generate the units, by obtaining the Q matrix of an unit, it is possible to generate subplots of the units.
EUsPoint(Rbook,EU)
EUsPoint(Rbook,EU)
Rbook |
object imagenField |
EU |
constant. number of experimental unit |
Q |
matrix, four points |
library(rPAex) data(cassava) s <- terra::rast(cassava,type="xyz") # Use image and locator(2) #x11() op<-par(mar=c(2,2,3,2),cex=0.8) # terra::image(s) # p<-locator(2) # e<-terra::ext(unlist(p)) e <- terra::ext(287691.9, 287708.6, 8664188, 8664203) r <- terra::crop(s,e) #----- # Define the border of the plot # p<-locator(3) p<-list(x=c(287698.21, 287700.99, 287702.39), y=c(8664200.68, 8664201.57,8664190.63)) q<-fourPoint(p) #----- # Define a subarea of 11x3 units by 1x0.9 meters ny<-11; nx<-3; dy=1; dx=0.9 terra::image(r,main="Cassava crop\nnear infrared image",bty="l") Rbook<-imageField(r, q, ny, nx, dy, dx, plotting = TRUE, border="blue",lwd=1) # identify unit 11 with the spectral information Q<-EUsPoint(Rbook,EU=11) polygon(Q,col="black") pol <- terra::vect(Q, "polygons") R <- terra::extract(r, pol, xy = TRUE) head(R) par(op)
library(rPAex) data(cassava) s <- terra::rast(cassava,type="xyz") # Use image and locator(2) #x11() op<-par(mar=c(2,2,3,2),cex=0.8) # terra::image(s) # p<-locator(2) # e<-terra::ext(unlist(p)) e <- terra::ext(287691.9, 287708.6, 8664188, 8664203) r <- terra::crop(s,e) #----- # Define the border of the plot # p<-locator(3) p<-list(x=c(287698.21, 287700.99, 287702.39), y=c(8664200.68, 8664201.57,8664190.63)) q<-fourPoint(p) #----- # Define a subarea of 11x3 units by 1x0.9 meters ny<-11; nx<-3; dy=1; dx=0.9 terra::image(r,main="Cassava crop\nnear infrared image",bty="l") Rbook<-imageField(r, q, ny, nx, dy, dx, plotting = TRUE, border="blue",lwd=1) # identify unit 11 with the spectral information Q<-EUsPoint(Rbook,EU=11) polygon(Q,col="black") pol <- terra::vect(Q, "polygons") R <- terra::extract(r, pol, xy = TRUE) head(R) par(op)
Generates a number of equidistant spatial points in an area. Fixed a couple of points in the image and the number of segments included, the function determines the position of the segments according to the length of the segment. The function relates the real dimension of the segment measurement to the image dimension. The function is useful for sizing plot sizes in the field, it also facilitates the generation of experimental units in the field.
fixedPoint(start, end, segments, length)
fixedPoint(start, end, segments, length)
start |
Starting point |
end |
Point at the end |
segments |
Number of segments |
length |
Segment length |
This function is used by imageField.
xy |
Data vector with the coordinate of the points |
library(rPAex) prg1 <- system.file("examples/Ex-01.R", package="rPAex") source(prg1) r<-data1() #x11() op<-par(mar=c(2,2,4,2),cex=0.8) terra::image(r,col=col2rgb(10),main="Orientation, position and length of the experimental unit\nstart = P1, end = P2, segments=4 and segment length = 10",bty="l") P<-list(x=c(20,80),y=c(40,80)) # or P<-locator(2) P<-cbind(x=P$x,y=P$y) Q<-fixedPoint(start = P[1,],end = P[2,],4,length = 10) x <- Q[,1]; y <- Q[,2] s <- seq(length(x)-1) # one shorter than data segments(x[s], y[s], x[s+1], y[s+1], col= c(1,0),lwd=2) # Description: text(Q,cex=2,col="red") text(20,80,"Total length = 72.11 units") text(20,70,"total segments = 4") text(60,40," Free space = 10.7037 units") text(60,30,"Segment length = 10 units") text(50,10,"fixedPoint(start ,end ,segments = 4,length = 10)") text(20,35,"start",cex=1.5) text(80,75,"end",cex=1.5) par(op)
library(rPAex) prg1 <- system.file("examples/Ex-01.R", package="rPAex") source(prg1) r<-data1() #x11() op<-par(mar=c(2,2,4,2),cex=0.8) terra::image(r,col=col2rgb(10),main="Orientation, position and length of the experimental unit\nstart = P1, end = P2, segments=4 and segment length = 10",bty="l") P<-list(x=c(20,80),y=c(40,80)) # or P<-locator(2) P<-cbind(x=P$x,y=P$y) Q<-fixedPoint(start = P[1,],end = P[2,],4,length = 10) x <- Q[,1]; y <- Q[,2] s <- seq(length(x)-1) # one shorter than data segments(x[s], y[s], x[s+1], y[s+1], col= c(1,0),lwd=2) # Description: text(Q,cex=2,col="red") text(20,80,"Total length = 72.11 units") text(20,70,"total segments = 4") text(60,40," Free space = 10.7037 units") text(60,30,"Segment length = 10 units") text(50,10,"fixedPoint(start ,end ,segments = 4,length = 10)") text(20,35,"start",cex=1.5) text(80,75,"end",cex=1.5) par(op)
Generate the fourth reference point of the plot according to three defined geo-referential points. This function is important for the correct use of all the functions of the rPAex package. In the image the plot is a parallelogram, the first assigned point must be located in the upper left and continue the second point in the upper right side and the third point in the lower right, always in a clockwise direction.
fourPoint(P)
fourPoint(P)
P |
the three points list |
P |
matrix, four points |
library(rPAex) prg1 <- system.file("examples/Ex-01.R", package="rPAex") source(prg1) r<-data1() # x11() op<-par(mar=c(2,2,4,2),cex=0.8) terra::image(r,main="Generating the fourth point of the study plot",col=col2rgb(10), xlim=c(20,101), ylim=c(0,101),axes=FALSE) # p<-locator(3) p<-list(x=c(40, 88, 80) , y=c(83, 82, 19)) q<-fourPoint(p) polygon(q,lty=2,lwd=2) text(q,cex=2) points(q[4,1],q[4,2],cex=6,col=2,lwd=2) d<-dist(q) text(64,86,round(d[1],1),cex=1.5) text(90,52,round(d[3],1),cex=1.5) text(29,53,round(d[4],1),cex=1.5) text(58,15,round(d[6],1),cex=1.5) par(op) # x11() op <-par(mar=c(2,2,4,2),cex=0.8) # An irregular area, use 4 points with p<-locator(4) and apply q<-fourPoint(p) to form the matrix terra::image(r,bty="l",main="An irregular area") #p<-locator(4) p<-list(x=c(40, 88, 80, 29) , y=c(83, 82, 19, 20)) q<-fourPoint(p) d<-dist(q) polygon(q) text(64,86,round(d[1],1),cex=1.5) text(90,52,round(d[3],1),cex=1.5) text(29,53,round(d[4],1),cex=1.5) text(56,15,round(d[6],1),cex=1.5) nx<-2;ny<-3 dy=d[3]/ny;dx=d[1]/nx # EU area= dx*dy out<-imageField(r,q,ny,nx,dy,dx) par(op) # number of pixels per EU table(out$Qbase$EU)
library(rPAex) prg1 <- system.file("examples/Ex-01.R", package="rPAex") source(prg1) r<-data1() # x11() op<-par(mar=c(2,2,4,2),cex=0.8) terra::image(r,main="Generating the fourth point of the study plot",col=col2rgb(10), xlim=c(20,101), ylim=c(0,101),axes=FALSE) # p<-locator(3) p<-list(x=c(40, 88, 80) , y=c(83, 82, 19)) q<-fourPoint(p) polygon(q,lty=2,lwd=2) text(q,cex=2) points(q[4,1],q[4,2],cex=6,col=2,lwd=2) d<-dist(q) text(64,86,round(d[1],1),cex=1.5) text(90,52,round(d[3],1),cex=1.5) text(29,53,round(d[4],1),cex=1.5) text(58,15,round(d[6],1),cex=1.5) par(op) # x11() op <-par(mar=c(2,2,4,2),cex=0.8) # An irregular area, use 4 points with p<-locator(4) and apply q<-fourPoint(p) to form the matrix terra::image(r,bty="l",main="An irregular area") #p<-locator(4) p<-list(x=c(40, 88, 80, 29) , y=c(83, 82, 19, 20)) q<-fourPoint(p) d<-dist(q) polygon(q) text(64,86,round(d[1],1),cex=1.5) text(90,52,round(d[3],1),cex=1.5) text(29,53,round(d[4],1),cex=1.5) text(56,15,round(d[6],1),cex=1.5) nx<-2;ny<-3 dy=d[3]/ny;dx=d[1]/nx # EU area= dx*dy out<-imageField(r,q,ny,nx,dy,dx) par(op) # number of pixels per EU table(out$Qbase$EU)
The function uses the raster image of all bands. It generates the limits of the unit and extracts the values of each pixel of the plot n x m units (n, m = 1,2, ...). The function requires the dimensions of the unit observed and the number of units per row (width) and column (length). The result is a table with image information and the characteristics of the experimental unit.
imageField(r, Q, ny, nx, dy, dx, start=1, plotting = TRUE, ...)
imageField(r, Q, ny, nx, dy, dx, start=1, plotting = TRUE, ...)
r |
raster image |
Q |
References points of de area |
ny |
Number of experimental units along the plot (y axis) |
nx |
Number of experimental units across the plot (x axis) |
dy |
Wide of unit plots |
dx |
Length of unit plots |
start |
Number of the first experimental unit |
plotting |
Overlap the units in the area, TRUE or FALSE |
... |
Other parameters the plot |
parameters |
Parameters of experimental design in precision agriculture |
Qbase |
Image data frame with location in field |
coordinates.EU |
The limits of each experimental unit |
EUsPoint
, fixedPoint
,
fourPoint
, designRaster
, cassava
library(rPAex) data(cassava) r <- terra::rast(cassava, type="xyz") # x11() # terra::image(r) # p<-locator(2) # e<-terra::ext(unlist(p)) e <- terra::ext(287691.9, 287708.6, 8664188, 8664203) rc <- terra::crop(r,e) # Selection of experimental units, p1 and p2 in terra::image(r) p1<-list(x=c(287698.34, 287701.14, 287702.33), y=c(8664200.89, 8664201.65, 8664190.67)) p2<-list(x=c(287701.56, 287704.37, 287705.24), y=c(8664198.68, 8664199.44, 8664191.46)) q1<-fourPoint(p1) q2<-fourPoint(p2) # dimension of the experimental unit dy=1; dx=0.9 op<-par(mar=c(0,0,3,0)) terra::image(rc,main="Selection of experimental units\nCassava crop",axes=FALSE) img1<-imageField(rc, q1, ny=11, nx=3, dy, dx, plotting = TRUE, border="blue",lwd=1) img2<-imageField(rc, q2, ny=8, nx=3, dy, dx, start=34,plotting = TRUE, border="blue",lwd=1) # Spectral data of selected units R<-rbind(img1$Qbase,img2$Qbase) head(R) Q<-agricolae::tapply.stat(R[,2:3],R[,1],mean) text(Q[,2],Q[,3],Q[,1],cex=1) par(op)
library(rPAex) data(cassava) r <- terra::rast(cassava, type="xyz") # x11() # terra::image(r) # p<-locator(2) # e<-terra::ext(unlist(p)) e <- terra::ext(287691.9, 287708.6, 8664188, 8664203) rc <- terra::crop(r,e) # Selection of experimental units, p1 and p2 in terra::image(r) p1<-list(x=c(287698.34, 287701.14, 287702.33), y=c(8664200.89, 8664201.65, 8664190.67)) p2<-list(x=c(287701.56, 287704.37, 287705.24), y=c(8664198.68, 8664199.44, 8664191.46)) q1<-fourPoint(p1) q2<-fourPoint(p2) # dimension of the experimental unit dy=1; dx=0.9 op<-par(mar=c(0,0,3,0)) terra::image(rc,main="Selection of experimental units\nCassava crop",axes=FALSE) img1<-imageField(rc, q1, ny=11, nx=3, dy, dx, plotting = TRUE, border="blue",lwd=1) img2<-imageField(rc, q2, ny=8, nx=3, dy, dx, start=34,plotting = TRUE, border="blue",lwd=1) # Spectral data of selected units R<-rbind(img1$Qbase,img2$Qbase) head(R) Q<-agricolae::tapply.stat(R[,2:3],R[,1],mean) text(Q[,2],Q[,3],Q[,1],cex=1) par(op)
The coordinates of the plot generated with the locate() and fourPoint() functions define the experimental units with the field dimensions, In the successive images in time, these may have some difference in position and it is necessary to adapt the experimental units to obtain exactly the information within the unit.
movePlot(Q,q)
movePlot(Q,q)
Q |
matrix. Four points of the plot as described by the fourPoint function |
q |
matrix or list. Two points, the first one sets the position and the second the orientation |
The matrix Q has the points organized according to the fourPoint function. To know the numbering in the plane, execute text(Q). The first must be the upper left and numbered clockwise.
q |
matrix. Four points of the new plot as described by the fourPoint function |
Felipe de Mendiburu
library(rPAex) op<-par(mfrow=c(1,3),mar=c(0,0,0,0)) # Coordinates during initial flight plot(0,0,xlim=c(0.08,0.9),ylim=c(0.1,0.9),axes=FALSE) # x11(); p0<-locator(3) p0<-list(x=c(0.20, 0.64, 0.81),y=c(0.71, 0.83, 0.40)) Q0<-fourPoint(p0) dp<-dist(Q0) text(Q0[,1],Q0[,2],paste("(",Q0[,1],",",Q0[,2], ")",sep=""),cex=1.2) polygon(Q0,border="blue",lwd=1.5) centro<-apply(Q0,2,mean) areaEU<-round(dp[1]*dp[2],4) text(centro[1],centro[2],paste("Area=",areaEU),col="blue") text(0.50,0.2,"old plot",cex=1.5) #------- # Change of coordinates effect of flight, correction to initial flight plot(0,0,xlim=c(0.08,0.9),ylim=c(0.1,0.9),axes=FALSE) polygon(Q0,border="blue",lwd=1.5) text(Q0,cex=1.5) # x11(); s <-locator(3) s<-list(x=c(0.2,0.62),y=c(0.71,0.73)) Qs<-movePlot(Q0,s) centro<-apply(Qs,2,mean) polygon(Qs,border="red",lty=2,lwd=1.5) text(Qs,cex=1.5) text(centro[1],centro[2]+0.05,paste("Area=",areaEU),col="red") text(centro[1],0.9,"Change position\n of the new images",cex=1.5) text(0.50,0.2,"change position",cex=1.5) #-------- # correction result plot(0,0,xlim=c(0.08,0.9),ylim=c(0.1,0.9),axes=FALSE) polygon(Qs,border="red",lwd=1.5) text(Qs,cex=1.5) text(centro[1],centro[2],paste("Area=",areaEU),col="red") text(0.50,0.2,"new plot",cex=1.5) par(op)
library(rPAex) op<-par(mfrow=c(1,3),mar=c(0,0,0,0)) # Coordinates during initial flight plot(0,0,xlim=c(0.08,0.9),ylim=c(0.1,0.9),axes=FALSE) # x11(); p0<-locator(3) p0<-list(x=c(0.20, 0.64, 0.81),y=c(0.71, 0.83, 0.40)) Q0<-fourPoint(p0) dp<-dist(Q0) text(Q0[,1],Q0[,2],paste("(",Q0[,1],",",Q0[,2], ")",sep=""),cex=1.2) polygon(Q0,border="blue",lwd=1.5) centro<-apply(Q0,2,mean) areaEU<-round(dp[1]*dp[2],4) text(centro[1],centro[2],paste("Area=",areaEU),col="blue") text(0.50,0.2,"old plot",cex=1.5) #------- # Change of coordinates effect of flight, correction to initial flight plot(0,0,xlim=c(0.08,0.9),ylim=c(0.1,0.9),axes=FALSE) polygon(Q0,border="blue",lwd=1.5) text(Q0,cex=1.5) # x11(); s <-locator(3) s<-list(x=c(0.2,0.62),y=c(0.71,0.73)) Qs<-movePlot(Q0,s) centro<-apply(Qs,2,mean) polygon(Qs,border="red",lty=2,lwd=1.5) text(Qs,cex=1.5) text(centro[1],centro[2]+0.05,paste("Area=",areaEU),col="red") text(centro[1],0.9,"Change position\n of the new images",cex=1.5) text(0.50,0.2,"change position",cex=1.5) #-------- # correction result plot(0,0,xlim=c(0.08,0.9),ylim=c(0.1,0.9),axes=FALSE) polygon(Qs,border="red",lwd=1.5) text(Qs,cex=1.5) text(centro[1],centro[2],paste("Area=",areaEU),col="red") text(0.50,0.2,"new plot",cex=1.5) par(op)
The package contains functions to manage images obtained by remote sensing of the experimental fields. In the field the characteristics of the plot are defined (number of units per row and column and dimensions in meters or other dimension measures). The program uses the information to generate the limits and record the content of the different layers, as well as the coordinates of the pixels and the identification of the observation units in the field. It also allows to extract the experimental designs generated in agricolae package and distribute the treatments in the image according to the distribution of the generated plan. The images used in the examples were obtained from the repository of (Loayza et al. 2018) International Potato Center, V1.
Package: | rPAex |
Type: | Package |
Version: | 1.0.5 |
Date: | 2023-11-01 |
License: | GPL |
Professor Felipe de Mendiburu
Systems Engineer.
Universidad Nacional de Ingenieria Lima-Peru.
Professor Applied Statistics
Universidad Nacional Agraria La Molina, Lima-Peru.
Professor David Mauricio.
Department of Computer Science.
Universidad Nacional Mayor de San Marcos, Lima-Peru
Rodrigo A. Morales A. PhD
Phytopathologist-Sustainable Agriculture
Agricultural Research Institute of Panama (IDIAP)
Professor Roberto Quiroz.
Centro Agronomico Tropical de Investigacion.
CATIE.
Loayza, Hildo; Silva, Luis; Palacios, Susan; Balcazar, Mario; Quiroz, Roberto, 2018, "Dataset for: Modelling crops using high resolution multispectral images", doi: 10.21223/P3/UVWVLA, International Potato Center, V1.
M. Montalvo, G. Pajares, J. M. Guerrero, J. Romeo, M. Guijarro, A. Ribeiro, J. J. Ruz, and J. Cruz. Automatic detection of crop rows in maize fields with high weeds pressure. Expert Systems with Applications, 39(15):11889-11897, 2012.
X. Zhang, X. Li, B. Zhang, J. Zhou, G. Tian, Y. Xiong, and B. Gu. Automated robust crop-row detection in maize fields based on position clustering algorithm and shortest path method. Computers and electronics in agriculture, 154:165-175, 2018.
F. de Mendiburu. A statistical analisys tool for agricultural research. Masters thesis, Universidad Nacional de Ingenieria. Lima-Peru, 8 2009. Degree in systems engineering.
Richards, J. A. Remote sensing digital image analysis: An introduction. 2012
EUsPoint
, fixedPoint
, fourPoint
,
imageField
, borderPoint
, designRaster
,
movePlot
,cassava
,cropTime
# Simple examples of the most important functions library(rPAex) # Graeco - latin square design T1<-c("a","b","c","d") T2<-c("v","w","x","y") outdesign <- agricolae::design.graeco(T1,T2,serie=1) book<-outdesign$book prg1 <- system.file("examples/Ex-01.R", package="rPAex") source(prg1) r<-data1() # x11() op<-par(mar=c(2,2,4,2),cex=0.9) terra::image(r,main="Graeco - latin square design\n Treatments T1 (a, b, c, d) and T2 (v, w, x, y)",col=col2rgb(2),axes=FALSE,xlim=c(0,101)) axis(1);axis(2) # 3 points are set in the image, to generate the experimental area # P<-locator(3) P<-list(x=c(20,90,80),y=c(80,90,20)) # and complete the fourth point to close the polygon. Q<-fourPoint(P) polygon(Q,lwd=3) R<-imageField(r, Q, ny=4, nx=4, dy=12, dx=12,col=colors()[18]) q<-designRaster(R$Qbase,book)$design text(q[,6],q[,7]+2,q[,1]) text(q[,6],q[,7]-2,paste(q[,4],q[,5],sep=" - ")) par(op) # An irregular area, use 4 points with p<-locator(4) and apply q<-fourPoint(p) to form the matrix # x11() op<-par(mar=c(2,2,2,2),cex=0.9) terra::image(r,xlim=c(20,100),ylim=c(10,100),axes=FALSE,main="An irregular area",col=col2rgb(3)) axis(1);axis(2) # p<-locator(4) p<-list(x=c(40, 88, 80, 29) , y=c(83, 82, 19, 20)) q<-fourPoint(p) dist(q) dx=10;dy=12 nx<-4; ny<-5 S<-imageField(r,q,ny,nx,dy,dx,col=colors()[20]) points(q,cex=4,pch=20,col="white") text(q,cex=1.5) M<-agricolae::tapply.stat(S$Qbase[,2:3],S$Qbase$EU) # identifying EU text(M[,2],M[,3],M[,1],cex=1) par(op)
# Simple examples of the most important functions library(rPAex) # Graeco - latin square design T1<-c("a","b","c","d") T2<-c("v","w","x","y") outdesign <- agricolae::design.graeco(T1,T2,serie=1) book<-outdesign$book prg1 <- system.file("examples/Ex-01.R", package="rPAex") source(prg1) r<-data1() # x11() op<-par(mar=c(2,2,4,2),cex=0.9) terra::image(r,main="Graeco - latin square design\n Treatments T1 (a, b, c, d) and T2 (v, w, x, y)",col=col2rgb(2),axes=FALSE,xlim=c(0,101)) axis(1);axis(2) # 3 points are set in the image, to generate the experimental area # P<-locator(3) P<-list(x=c(20,90,80),y=c(80,90,20)) # and complete the fourth point to close the polygon. Q<-fourPoint(P) polygon(Q,lwd=3) R<-imageField(r, Q, ny=4, nx=4, dy=12, dx=12,col=colors()[18]) q<-designRaster(R$Qbase,book)$design text(q[,6],q[,7]+2,q[,1]) text(q[,6],q[,7]-2,paste(q[,4],q[,5],sep=" - ")) par(op) # An irregular area, use 4 points with p<-locator(4) and apply q<-fourPoint(p) to form the matrix # x11() op<-par(mar=c(2,2,2,2),cex=0.9) terra::image(r,xlim=c(20,100),ylim=c(10,100),axes=FALSE,main="An irregular area",col=col2rgb(3)) axis(1);axis(2) # p<-locator(4) p<-list(x=c(40, 88, 80, 29) , y=c(83, 82, 19, 20)) q<-fourPoint(p) dist(q) dx=10;dy=12 nx<-4; ny<-5 S<-imageField(r,q,ny,nx,dy,dx,col=colors()[20]) points(q,cex=4,pch=20,col="white") text(q,cex=1.5) M<-agricolae::tapply.stat(S$Qbase[,2:3],S$Qbase$EU) # identifying EU text(M[,2],M[,3],M[,1],cex=1) par(op)