Disease index counting error

10 views
Skip to first unread message

Ahasanul Hoque

unread,
Aug 26, 2025, 1:29:13 AMAug 26
to FIELDimageR: A R package to analyze orthomosaic images from field trials.
Hi,
I am trying to count the disease index using the command and pictures available in fieldimageR github. But always getting the attached error message. 

Could anyone help me to solve this problem?

Thanks
Ahasan
Fieldimage_diseaseIndex.jpg

fmatias

unread,
Aug 26, 2025, 6:59:24 AMAug 26
to FIELDimageR: A R package to analyze orthomosaic images from field trials.
Hi Ahasan,

Maybe you are using a old script ... It changes a bit to adapt to new packages.

Now you need to use the function EX<-imgLAB(EX)


################
### Parallel ###
################

# Required packages
library(parallel)
library(foreach)
library(doParallel)

# Images names (folder directory: "./soybean/")
pics<-list.files("./soybean/")

# Number of cores
n.core<-2

# Starting parallel
cl <- makeCluster(n.core, output = "")
registerDoParallel(cl)
EX.Table.Parallel <- foreach(i = 1:length(pics), .packages = c("stars","sf","terra","FIELDimageR"),
                             .combine = rbind) %dopar% {
                               EX3<-rast(paste("./soybean/",pics[i],sep = ""))
                               EX3<-imgLAB(EX3)
                               # Removing the background
                               EX3.R<- fieldMask(mosaic = EX3, index = "BGI",
                                                 cropValue = 0.7,
                                                 cropAbove = T)
                               # Counting the total number of seeds
                               EX.P.Total<-fieldCount(mosaic = EX3.R$mask,plot = T)
                               Total=EX.P.Total[EX.P.Total$area>15000,]
                               # Selecting green seeds
                               EX3.R2<- fieldMask(mosaic = EX3.R$newMosaic,
                                                  index = "BI",
                                                  cropValue = 130,
                                                  cropAbove = T)
                               # Counting the number of green seeds
                               EX.Green<-fieldCount(mosaic = EX3.R2$mask,plot = T)
                               Green=EX.Green[EX.Green$area>10800,]
                               data.frame(Total=dim(Total)[1],
                                          Green=dim(Green)[1],
                                          Percentage=round(dim(Green)[1]/dim(Total)[1],2))
                             }
stopCluster(cl)
rownames(EX.Table.Parallel)<-pics
EX.Table.Parallel



Hope it helps,
Filipe

Ahasanul Hoque

unread,
Aug 27, 2025, 6:03:37 AMAug 27
to FIELD...@googlegroups.com
Hi  Filipe,
Thanks for your response. 
Actually I am trying to measure the diseased area of supplied files in fieldimaeR github (https://drive.google.com/file/d/1zgOZFd7KuTu4sERcG1wFoAWLCahIJIlu/view). but failed with the supplied error message (attached as figure). 

Could you please help me to solve this problem? I used imgLAB command but the same problem happened. 

--
You received this message because you are subscribed to the Google Groups "FIELDimageR: A R package to analyze orthomosaic images from field trials." group.
To unsubscribe from this group and stop receiving emails from it, send an email to FIELDimageR...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/FIELDimageR/89cb7c1d-2e03-42c6-8ba5-cac41ee6616dn%40googlegroups.com.


--
Regards
Ahasanul Hoque
     PhD (NDSU, USA)
Associate Professor
Dept. of Genetics & Plant Breeding
Bangladesh Agricultural University
Mymensingh-2202, Bangladesh
Skype: ahasan102
Fieldimage_diseaseIndex.jpg
Fieldimage_diseaseIndex_2.jpg

fmatias

unread,
Aug 27, 2025, 8:58:04 AMAug 27
to FIELDimageR: A R package to analyze orthomosaic images from field trials.
Hi Ahasanul,

Now days the code is a bit different from the one you are using. Try this:

##############
### Script ###
##############

library(FIELDimageR)
library(FIELDimageR.Extra)
library(terra)
library(sf)
library(mapview)
library(leafsync)

######################
### Example Images ###
######################

# List and set working directory for images
pics <- list.files("./images/")

# Define vegetation indices to be calculated
index <- c("BGI", "VARI", "SCI")

# Read and process each image
EX.L1 <- rast(paste("./images/", pics[1], sep = ""))
EX.L1 <- imgLAB(EX.L1)
plot(EX.L1)
fieldView(EX.L1)

# Image SHP
EX.L.Shape <- ext(EX.L1) %>% as.polygons() %>% st_as_sf()

# Select one index to identify leaves and remove background
EX.L2 <- fieldMask(mosaic=EX.L1, index="BGI", cropValue=0.8, cropAbove=T)

# Select one index to identify damaged area in leaves
EX.L3 <- fieldMask(mosaic=EX.L2$newMosaic, index="VARI", cropValue=0.1, cropAbove=T)

# Calculate indices
EX.L4 <- fieldIndex(mosaic=EX.L2$newMosaic, index=index)
rgb<-fieldView(EX.L4)
VARI<-fieldView(EX.L4$VARI)
sync(rgb,VARI)

# Combine layers
EX.L5 <- rast(list(1-EX.L2$mask,1-EX.L3$mask, EX.L4))
names(EX.L5)[c(1,2)]<-c("area_total","area_seg")

# Extract additional field information
EX.L.Info <- fieldInfo_extra(mosaic=EX.L5, fieldShape=EX.L.Shape)
View(EX.L.Info)
as.matrix(EX.L.Info)

###################
### Many Images ###
###################

# List and set working directory for images
pics <- list.files("./images/")

# Define vegetation indices to be calculated
index <- c("BGI", "VARI", "SCI")

# Load required packages
library(parallel)
library(foreach)
library(doParallel)

# Set up parallel processing
n.core <- 2

cl <- makeCluster(n.core, output = "")
registerDoParallel(cl)

# Process images in parallel
system.time({
  EX.Table.Parallel <- foreach(i = 1:length(pics), .packages = c("stars", "sf", "terra", "FIELDimageR", "FIELDimageR.Extra"),
                               .combine = rbind) %dopar% {
                                 
                                 # Read and process each image
                                 EX.L1 <- rast(paste("./images/", pics[i], sep = ""))
                                 EX.L1 <- imgLAB(EX.L1)
                                 EX.L.Shape <- ext(EX.L1) %>% as.polygons() %>% st_as_sf()
                                 
                                 # Select one index to identify leaves and remove background
                                 EX.L2 <- fieldMask(mosaic=EX.L1, index="BGI", cropValue=0.8, cropAbove=T, plot=F)
                                 
                                 # Select one index to identify damaged area in leaves
                                 EX.L3 <- fieldMask(mosaic=EX.L2$newMosaic, index="VARI", cropValue=0.1, cropAbove=T, plot=F)
                                 
                                 # Calculate indices
                                 EX.L4 <- fieldIndex(mosaic=EX.L2$newMosaic, index=index, plot=F)
                                 
                                 # Combine layers
                                 EX.L5 <- rast(list(1-EX.L2$mask,1-EX.L3$mask, EX.L4))
                                 names(EX.L5)[c(1,2)]<-c("area_total","area_seg")
                                 
                                 # Extract additional field information
                                 EX.L.Info <- fieldInfo_extra(mosaic=EX.L5, fieldShape=EX.L.Shape)
                                 
                                 # Return combined information
                                 as.matrix(EX.L.Info)
                               }
})

EX.Table.Parallel


### END ###

Ahasanul Hoque

unread,
Aug 28, 2025, 1:32:02 AM (14 days ago) Aug 28
to FIELD...@googlegroups.com
Hi  Filipe,
Thank you for providing the codes. It's working. 
I need little help in interpreting the data:
In commands:
 "# Select one index to identify leaves and remove background
EX.L2 <- fieldMask(mosaic=EX.L1, index="BGI", cropValue=0.8, cropAbove=T)

# Select one index to identify damaged area in leaves
EX.L3 <- fieldMask(mosaic=EX.L2$newMosaic, index="VARI", cropValue=0.1, cropAbove=T) "

Are the cropValue 0.8 and 0.1 always the same for all pictures?

After running, I get the attached result file. In this file which one is the disease index and which data should I used for GWAS?

Thanks
Ahasan



You received this message because you are subscribed to a topic in the Google Groups "FIELDimageR: A R package to analyze orthomosaic images from field trials." group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/FIELDimageR/yG_gC0GzjRM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to FIELDimageR...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/FIELDimageR/402e4189-7e98-441f-93e5-7a3986fac5cdn%40googlegroups.com.
Disease Index.csv
Reply all
Reply to author
Forward
0 new messages