load an image to R.

638 views
Skip to first unread message

maryam tabatabaei

unread,
Jan 21, 2021, 4:29:56 PM1/21/21
to FIELDimageR: A R package to analyze orthomosaic images from field trials.
Hi, 
I am a first time R user that wants to utilize the FieldRimage. I am trying to load orthomosaic image into R. Here is the error message that I get.

EX1<-stack("C:/Users/maryam.tabatabaei/Desktop/UAV_Brandi/Atlanta_Ortho.tif")
Error in data.frame(values = unlist(unname(x)), ind, stringsAsFactors = FALSE) : 
  arguments imply differing number of rows: 1, 0

Also, how do you collect the data for table1? Is that collected manually or automatically?

Thanks,
Maryam

Stuart Marshall

unread,
Jan 22, 2021, 6:59:20 PM1/22/21
to FIELDimageR: A R package to analyze orthomosaic images from field trials.
Welcome!

Things I would check/try:

Make sure to load the necessary dependencies before you try your import with
library(FIELDimageR)
library(raster)  

Check to see if you have any packages that need to be updated (I'm assuming you're using RStudio where this is relatively easy?)
Also check that all the dependencies are installed.

To avoid entering such a long path name and to avoid errors that might arise set your working directory to your UAV_Brandi folder. It will make it much easier when you go to save extracted data and images.


I'm not sure about your question on "table1", are you asking if you have to manually create the plot shapefile?

-Stuart

fmatias

unread,
Jan 22, 2021, 7:42:02 PM1/22/21
to FIELDimageR: A R package to analyze orthomosaic images from field trials.
Hi Maryam, thank you for asking...!

Stuart is right, you need to load the dependencies first:

library(FIELDimageR)
library(raster) 
EX1<-stack("C:/Users/maryam.tabatabaei/Desktop/UAV_Brandi/Atlanta_Ortho.tif") 
 
Stuart, thank you for helping... That's awesome.

I didn't found "table 1" on the main tutorial. Could you share what tutorial are you following?

Thank you,
Filipe

maryam tabatabaei

unread,
Jan 25, 2021, 10:53:35 AM1/25/21
to FIELDimageR: A R package to analyze orthomosaic images from field trials.
I uploaded all the dependencies. I don't know how to upload the orthomosaic image.  You used this line to upload the tif file. How did you get to that image or directory? EX1<-stack("EX1_RGB.tif")  plotRGB(EX1, r = 1, g = 2, b = 3)  
For example for data, I can import data from, but I don't know how to upload the image to analyze.
I was talking about Table 1 that Filipe showed in his video. I am wondering if he enters the data manually or he get the data automatically from FieldImageR.


Thanks


FieldimageR.png

maryam tabatabaei

unread,
Jan 25, 2021, 10:55:32 AM1/25/21
to FIELDimageR: A R package to analyze orthomosaic images from field trials.
Stuart, 

Where is the extracted data and images in Rstudio to avoid having a long directoy?

Thanks,
Maryam

maryam tabatabaei

unread,
Jan 25, 2021, 11:27:25 AM1/25/21
to FIELDimageR: A R package to analyze orthomosaic images from field trials.
Here is what I installed so far:  
install.packages("devtools")
install.packages("sp")
install.packages("raster")
install.packages("rgdal")
install.packages("scales")
install.packages("xml2")
install.packages("git2r")
install.packages("usethis")
install.packages("fftwtools")
devtools::install_github("filipematias23/FIELDimageR")
library(FIELDimageR)
library(raster)
EX1<-stack('C:/Users/maryam.tabatabaei/Desktop/UAV_Brandi/Atlanta_Ortho.tif')
plotRGB(EX1, r = 1, g = 2, b = 3)

 get an error message about sp package even though that is installed, when I want to use FIELDimageR and raster library.

Stuart Marshall

unread,
Jan 25, 2021, 1:54:06 PM1/25/21
to FIELDimageR: A R package to analyze orthomosaic images from field trials.
If you are using RStudio you can use the "files" tab on the lower right, navigate to the folder with your images in it (in your case /UAV_Brandi/), then hit the little blue gear on the top of the "files" section and hit "set as working directory".

You'll see the command that R uses to set the working directory down in the Console on the bottom left. I'll be "setwd" and then a path. You can even copy that command and paste it into your script and use it that way from then on.

Stuart Marshall

unread,
Jan 25, 2021, 2:03:31 PM1/25/21
to FIELDimageR: A R package to analyze orthomosaic images from field trials.
Also, what's the error that you're getting from sp?

In RStudio if you open the "Packages" tab on the lower right and scroll down through the user library do you find sp and does it have a checkmark on it after you press ctrl+enter on the library(raster) and library(FIELDimageR) commands?

fmatias

unread,
Jan 25, 2021, 2:21:32 PM1/25/21
to FIELDimageR: A R package to analyze orthomosaic images from field trials.

Hi Maryam and Stuart,

 

Thank you for helping each other.


Do you guys this that maybe the error is related to the image path? Maryam, did you try to save your image (Atlanta_Ortho.tif) on the same directory of your script and run the code below to see if it works?

 

library(FIELDimageR)

library(raster)

EX1<-stack("Atlanta_Ortho.tif")

plotRGB(EX1)

plotRGB(RGB.rescale(r, num.band = 3))

 

About the "table" question:

 

(1) If you are looking only for image data extraction, with no intention to compare the results with traits collected manually in the field (e.g., yield, maturity, etc.), the answer is YES. FIELDimageR can make the table by itself. The data ID (PlotName) will be organized from left to right and top to bottom (https://github.com/OpenDroneMap/FIELDimageR#P5).

 

(2) However, if you want to have the same sequence or plot identification from your field and combine the image data with the traits collected manually in the field (e.g., yield, maturity, etc.), the answer is NO. In this case, you must provide a MAP (matrix object in R) with the right plot identification. Also, you need to provide a data table with one column that matches the MAP identification ID. For example, input table with (Plot, Row, Range and a sequence of field traits collected manually) like in this example: https://drive.google.com/file/d/18YE4dlSY1Czk2nKeHgwd9xBX8Yu6RCl7/view.

 

I tried to explain what the function fieldShape does here: https://github.com/OpenDroneMap/FIELDimageR#P5

Let me know if it makes sense,

Filipe

maryam tabatabaei

unread,
Jan 26, 2021, 8:46:27 AM1/26/21
to FIELDimageR: A R package to analyze orthomosaic images from field trials.
Thank you Filipe. I will try it. I am getting an error with stack since I only have one orthomosaic image to work with so far.
EX1<-stack("Atlanta_Ortho.tif")
Error in data.frame(values = unlist(unname(x)), ind, stringsAsFactors = FALSE) : 
  arguments imply differing number of rows: 1, 0

It also does not like plotrgb command eventhough that I installed raster.

Thanks, 
Maryam


fmatias

unread,
Jan 26, 2021, 11:10:17 AM1/26/21
to FIELDimageR: A R package to analyze orthomosaic images from field trials.
Maryam,

If you have only one layer, try to use the code:


library(FIELDimageR)

library(raster)

EX1<-raster("Atlanta_Ortho.tif")

plot(EX1)

 

Let me know if it works.

Best,

Filipe

maryam tabatabaei

unread,
Jan 26, 2021, 12:42:34 PM1/26/21
to FIELDimageR: A R package to analyze orthomosaic images from field trials.
Thank you very much, it worked! Hallelujah! I am off to analyzing it next. 

On Friday, January 22, 2021 at 6:42:02 PM UTC-6 fmatias wrote:

fmatias

unread,
Jan 26, 2021, 1:07:12 PM1/26/21
to FIELDimageR: A R package to analyze orthomosaic images from field trials.
Hey, you did it... That's great.

Let us know if you have more questions.

Cheers,
Filipe

maryam tabatabaei

unread,
Jan 27, 2021, 12:42:08 PM1/27/21
to FIELDimageR: A R package to analyze orthomosaic images from field trials.
Hi, 

I am getting an error that my image only includes 1 layer. I don't understand it fully. I saw that you defined Red=1, Green=2, Blue=3 , index=hue. Does that changes from one image to another? Could my image only 1 layer. I get most of my ortho images from drone images that are RGB visible. But every time that I go through an image same error occurs with applying the soil mask.

My second question is how to zoom in the image like your example, so I can pick a better line where the crops are aligned.

Thanks,
Maryam
Screenshot_Rerror.png
Message has been deleted

maryam tabatabaei

unread,
Jan 27, 2021, 5:17:10 PM1/27/21
to FIELDimageR: A R package to analyze orthomosaic images from field trials.
I figured out the first part of my question. If I use stack in front of the file. It will read the image in 3 layers. I still don't know how to zoom in the image so I can pick a better number of columns and rows for the shape file.

fmatias

unread,
Jan 27, 2021, 11:24:53 PM1/27/21
to FIELDimageR: A R package to analyze orthomosaic images from field trials.
Hi Maryam,

It is great that you understood the difference between raster() and stack(). To use fieldIndex() and fieldMask() you need to have more than one layer to calculate the indices. 

Unfortunately, I don't know a better way to zoom the plot area yet to facilitate using fieldShape(). An alternative idea is, if you are using a Windows machine, you can run the function x11() to open a secondary plot window from where you can see better the image.

x11()
fieldShape()

Hope someone gives us a better solution soon.

All the best,
Filipe

maryam tabatabaei

unread,
Feb 1, 2021, 3:54:18 PM2/1/21
to FIELDimageR: A R package to analyze orthomosaic images from field trials.
 Filipe,

Thank you for all your help. When we create a fieldshape using columns and rows in the selected plot, can we instead pick the area around the rows and columns? Is there anyway to automatically detect where preexisting grid is and correlate them back to our grid (the one that was created through the shape files)?

Thanks,
Maryam

fmatias

unread,
Feb 2, 2021, 10:37:20 AM2/2/21
to FIELDimageR: A R package to analyze orthomosaic images from field trials.
Hi Maryam,

I am not sure if I understood your question. But unfortunately, there is no automatic way to detect lines from ground shapes in the field yet. 
As soon as I have more time I will work on better ways to do the shapefile, but right now you have some other options:

If you have GCPs you can use UAStools package on R to make the shapefiles: https://doi.org/10.3389/fpls.2020.511768

Also, there are some different ways to do shapefile on QGIS (e.g., http://www.ga.gov.au/webtemp/image_cache/GA20950.pdf)

After this, you can use the package rgdal to upload the shapefile in R and continue with FIELDimageR pipeline: https://github.com/OpenDroneMap/FIELDimageR#P21

library(rgdal) 
ShapeFile <- readOGR("Other_Software_ShapeFile.shp")

Please, let me know if it makes sense.

All the best,
Filipe

maryam tabatabaei

unread,
Feb 2, 2021, 2:01:50 PM2/2/21
to FIELDimageR: A R package to analyze orthomosaic images from field trials.
Thank you Filipe.  I was looking into line intersection automation packages to automatically pick a plot. That will be a great addition to very practical R package that you have created. In the code below, you picked numbers of rows and columns, but I want to pick the perimeter around every few rows and columns.

Joining all information in one "fieldShape" file: EX1.Shape<-fieldShape(mosaic = EX1.RemSoil, ncols = 14, nrows = 9, fieldMap = fieldMap, fieldData = DataTable, ID = "Plot")  

Best,
Maryam

fmatias

unread,
Feb 2, 2021, 2:09:26 PM2/2/21
to FIELDimageR: A R package to analyze orthomosaic images from field trials.
Hi Maryam,

Unfortunately, I don't know how to help you if this question yet. 
But, maybe this post can help you to have some ideas: https://groups.google.com/g/fieldimager/c/5Wa1IVmhsyk/m/Y0UouedNBwAJ 

Best,
Filipe

maryam tabatabaei

unread,
Feb 2, 2021, 2:28:57 PM2/2/21
to FIELDimageR: A R package to analyze orthomosaic images from field trials.
Thank you very much. I have orthomosaic images that are stitched together. I keep working on plot autodetection and will share the results.

Best,
Maryam

Reply all
Reply to author
Forward
0 new messages