removing black bacground color and use external shp file

141 views
Skip to first unread message

Alper Adak

unread,
Dec 19, 2020, 12:08:49 PM12/19/20
to FIELDimageR: A R package to analyze orthomosaic images from field trials.
Hello,

First, thank you for this wonderful R package. 

I have two questions.
fieldRotate code takes so much time (overnight) even thought I used almost the same size field area what Field image R tutorial used. Is it because of black background color of my tiff flie below ?  IF so, how can I remove this black background color from my tif file ?  


My second question is that I have a shape file, I created using different R package (UAStools).  But I do not know how I can integrate this external shape file to FieldImageR. I saw a suggestion in the tutorial but it was not clear to me. Or I could not figure it out. 

Did anyone use any external shp file in FIELDimageR package instead of using fieldshape step ?

Thanks,
Alper.
 

fmatias

unread,
Dec 20, 2020, 10:25:33 AM12/20/20
to FIELDimageR: A R package to analyze orthomosaic images from field trials.
Hi Alper,
Thank you for asking.

About the first question I am not sure why the function is taking so long for you. You can try reducing the mosaic size/resolution with the function aggregate(). This is only to figure out if it is something related with the mosaic or with the function. You also can crop the image and try to rotate one part of the field per time and combine them back in one mosaic later. Removing the background before rotating also helps to speed the image analyses pipeline. To understand how remove background, please follow this steps https://github.com/OpenDroneMap/FIELDimageR#P4 or the second part about choosing the index to remove the back ground here https://github.com/OpenDroneMap/FIELDimageR#P6.

To use an external shape file in R you need to install the package "rgdal". Normally, when you save a shapefile object you will have many files with different extensions (e.g., .shp, .txt, .lib, and etc). It is important to keep all of them together in the same folder. The code to import for R is this:

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

Let me know if it helps you,
All the best
Filipe

Alper Adak

unread,
Dec 28, 2020, 9:35:24 PM12/28/20
to FIELDimageR: A R package to analyze orthomosaic images from field trials.
Thank you. 

Basically, all extentions (.shp, .shx, .prj, .dbf) exist in the folder. I can read an open it. there is no problem in that.

However I do not know how I can integrate this external shp file t the code. My is code below. I just want to remove the ncol and nrow part in "fieldShape" step, and I would like to use my shp file.
I would be happy if you can show that .

my another questing is that my both external shp file and tiff file are cross and have same coordinate (they match perfectly). In this case can I skip the fieldRotate steps in the code ?
Thanks,
Alper.

 

Alper Adak

unread,
Dec 28, 2020, 9:38:49 PM12/28/20
to FIELDimageR: A R package to analyze orthomosaic images from field trials.

Thank you. (I updated my previous message and I attached my code.)

Basically, all extentions (.shp, .shx, .prj, .dbf) exist in the folder. I can read an open it. there is no problem in that.

However I do not know how I can integrate this external shp file t the code. My is code below. I just want to remove the ncol and nrow part in "fieldShape" step, and I would like to use my shp file.
I would be happy if you can show that .

my another questing is that my both external shp file and tiff file are cross and have same coordinate (they match perfectly). In this case can I skip the fieldRotate steps in the code ?
Thanks,
Alper.
IHOT.jpg

fmatias

unread,
Dec 29, 2020, 10:47:12 AM12/29/20
to FIELDimageR: A R package to analyze orthomosaic images from field trials.

Hi Alper,

You can edit the steps in this pipeline and choose only the important ones for you. In your case, because you already have the shapefile, you do not need to rotate. Also, you need to change the code from “EX1.Shape$fieldShape” to “EX1.Shape”. Please, could you try the code below to see if it is working for you?

 

EX1<-stack("071619_25m_ihot_0.tif")

EX1.Shape<-readOGR("IHOT_IHOT_buff.shp")

plotRGB(EX1)

plot(EX1.Shape, add=T)

EX1.RemSoil<- fieldMask(mosaic = EX1)

EX1.Indices<- fieldIndex(mosaic = EX1.RemSoil$newMosaic,index = c("BI","NGRDI","BGI"))

EX1.Info<- fieldInfo(mosaic = EX1.Indices,fieldShape = EX1.Shape)

EX1.Info$fieldShape@data

 

Let me know if you have more questions.

All the best and happy new year,

Filipe

Alper Adak

unread,
Dec 29, 2020, 3:23:52 PM12/29/20
to FIELDimageR: A R package to analyze orthomosaic images from field trials.
Thank you so much Filipe, your suggestions worked very well. Thanks to addition of aggregate() and projection() function, my script is working more accurate and by far faster than what I run previously. 

I have one last question. Can I use more than one "myIndex" option in the  fieldIndex() step ? 

My aim is to generate many vegetative indices that are not available in FIELDimageR. 

In other words, "myIndex" allows me to generate just one more index, however I would like to generate many more (6 to 10 different vegetative indices) at ones by writing their own equations. I tried myIndex_2 but I got error.

Thanks,
Alper.
   




###################################################### EXTERNAL SHP FILE#################################
library(FIELDimageR)
library(raster)

library("sp")
library("raster")
library("rgdal")
library('lidR')




library("devtools")
devtools::install_github("andersst91/UAStools")
library("UAStools")


A_cords<-c(746230.48,3382204.50)
B_cords<-c(746165.36,3382129.15)
setwd("D://Flights_2019//G2F//25m//071619_25m")

plots.shp<-plotshpcreate(A=A_cords, #Point A c(Easting_0.0,Northing_0.0)
                         B=B_cords, #Point B c(Easting_1.0,Northing_1.0)
                         infile=read.csv("D://Flights_2019//G2F//25m//071619_25m//Fieldmap.csv",header=T),
                         outfile="IHOT",
                         nrowplot=1,
                         field="CS19",
                         rowspc = 2.5, rowbuf = 0.1,
                         rangespc = 25, rangebuf = 2,unit = "feet",
                         UTMzone = "14", Hemisphere = "N")


######################################################FIELDimageR for VEGETATIVE INDICES EXTRACTIONS#########################

setwd("D://Flights_2019//G2F//25m//072619_25m")

EX1<-stack("072619_25m_ihot_0.tif")

EX11<-aggregate(EX1, fact=4)

EX1.Shape<-readOGR("CS19_IHOT_buff.shp")



plotRGB(EX11)

plot(EX1.Shape, add=T, col= "red")

EX1.RemSoil<- fieldMask(mosaic = EX11,
                        Red = 1, 
                        Green = 2, 
                        Blue = 3, 
                        index = "HUE")

RGBVI = c("((Green*Green)-(Red*Blue))/((Green*Green)+(Red*Blue))")

EX1.Indices<- fieldIndex(mosaic = EX1.RemSoil$newMosaic,
                         index = c("BI","GLI","NGRDI", "VARI","BGI"), 
                         myIndex = c("((Green*Green)-(Red*Blue))/((Green*Green)+(Red*Blue))"),
                         myIndex_2 = c("(2*Green-Red-Blue)")
                         )

?fieldIndex()



projection(EX1.Shape) <- projection(EX1.Indices)

EX1.Info<- fieldInfo(mosaic = EX1.Indices,
                     fieldShape = EX1.Shape,
                     n.core = 16)

EX1.Info$fieldShape@data


write.csv(EX1.Info$fieldShape@data,
          "D://Flights_2019//G2F//25m//072619_25m//IHOT_VIs_072619.csv", 
          row.names = FALSE)


hist(EX1.Info$fieldShape$NGRDI)

fmatias

unread,
Dec 29, 2020, 3:40:33 PM12/29/20
to FIELDimageR: A R package to analyze orthomosaic images from field trials.
Hi Alper,

I am glad to hear that it worked for you...!
The function fieldIndex() was upgraded to allow more than 1 myindex since version 0.2.5. Could you check your FIELDimageR version, please? 

The way to type is:  myIndex = c("Index1","Index2","Index3")

EX1.Indices<- fieldIndex(mosaic = EX1.RemSoil$newMosaic,
                         index = c("BI","GLI","NGRDI", "VARI","BGI"), 
                         myIndex = c("Index1","Index2","Index3")
                         )

All the best,
Filipe
Reply all
Reply to author
Forward
0 new messages