pkgdown/custom.css

Skip to contents pkgdown/home.html

Here is a short example to guide you step by step through the orthomosaic generating process and their alignment with the functions generate_Mosa() and align_Mosa(). These functions required, arosics(AROSICS), the Metashape python API and a valid Metashape license.

  • First you will need to download the test data and unzip it. Test data contains, 2 sets of drones images from the same area obtained from 2 differents dates and a CHM canopy height model from the area which is the reference.

  • Then run the following code, more details about the functions generate_Mosa() and align_Mosa().

library(canObsR)
library(reticulate)

use_condaenv('canObsR_env')

my_path <- 'XXXX/test_data'

generate_Mosa(path_in = file.path(my_path, 'my_drone_data'),
          out_dir_ortho = file.path(my_path, 'outputs_TS'),
          data_type = "RGB",
          resol_ref = 0.5,
          site_name = "Bouamir",
          crs = "EPSG::32633",
) 

align_Mosa(path_in = file.path(my_path, 'outputs_TS'),
        ref_filepath = file.path(my_path, 'Bouamir_LiDAR_ref.tif'),
        out_dir_path = file.path(my_path, 'outputs_arosics'),
        corr_type = "global",
        #grid_res = 200,
        window_size = 500,
        window_pos = list(258131, 352973),
        apply_matrix = TRUE,
        save_data = FALSE
)
Generate orthomosaics

Generate orthomosaics

When aligning a long time serie of mosaics, you may want to dynamically register each mosaic to the previous one instead of keeping one reference for the whole serie, in order to limit the time difference between a mosaic and its reference.

Here follows a snippet of code that allows you to do just that : the first image is aligned using the specified reference file, and then each subsequent image N uses the aligned version of the image N-1 as a reference.

dir_mosa = file.path(my_path, 'outputs_TS')
out_dir_path = file.path(my_path, 'outputs_arosics')

PATHs.df = dir(dir_mosa, full.names = T)
PATHs.df = PATHs.df[which(grepl(PATHs.df, pattern=".tif"))]
PATHs.df = data.frame(path_in = PATHs.df)
PATHs.df$output_mosa_name = NA

PATHs.df$path_ref = file.path(my_path, 'outputs_arosics')
for(i in 1:nrow(PATHs.df))                      
{
  # name of the ouput mosaic
  tmp = PATHs.df$path_in[i]
  tmp = strsplit(tmp, "/")[[1]]
  PATHs.df$output_mosa_name[i] = filename_out = tmp[4]
  if (i!=1){
     PATHs.df$path_ref[i] = paste0(out_dir_path, PATHs.df$output_mosa_name[i-1]) 
  }
}

for(i in 1:nrow(PATHs.df)) 
{
  path_in = PATHs.df$path_in[i]
  ref_filepath = PATHs.df$path_ref[i]
  
  arosics(path_in = path_in,
        ref_filepath = ref_filepath,
        out_dir_path = out_dir_path,
        corr_type = "local",
        grid_res = 200,
        window_size = 500,
        apply_matrix = FALSE,
        save_data = TRUE
        )
 
  print("<!> DONE <!>")
  print("######################################")
}

Note : in this case, both the input and reference images are potentially heavy mosaics. Depending on their size, it may be useful to downgrade their resolution to get a faster result without much impact on quality.

pkgdown/footer.html