User Tools

Site Tools


courses:msc:msc-phygeo-remote-sensing:worksheets:rs-ws-03-2

W03-2: Cross check tiles

This worksheet tackles the necessity that different raster images must be matched from a radiometric perspective in order to apply e.g. the same land-cover prediction model across all tiles. One appropriate method would be some kind of histogram matching technique. However, prior to applying such a method, one should check if it is really necessary. A visual or empirical check might be a time saver in this case.

After completing this worksheet, you should be able to cross check the radiometric alignment of images tiles using a self-developed strategy implemented as part of an R function.

Things you need for this worksheet

  • GIS — most commercial or open source GIS systems will be fine. For open source software running on Ubuntu Linux, the Ubuntu GIS package is a good choice. For Windows, it will be a good choice installing everything via the OSGeo4W environment and not individually. Actually both repositories make available a comprehensive bundle of GI -tools and software packages. We will focus on GRASS, QGIS and SAGA. On the commercial side, ArcGIS is one of the powerful options.

  • R — the interpreter can be installed on any operation system. For Linux, you should use the r-cran packages supplied for your Linux distribution. If you use Ubuntu, this is one of many starting points. If you use Windows, you could install R from the official CRAN web page.

  • R Studio — we recommend to use R Studio for (interactive) programming with R. You can download R Studio from the official web page.

  • Git environment for your operating system. For Windows users with little experience on the command line we recommend GitHub Windows.

  • your aerial images from W02-1: Aerial images I/O

Learning log assignments

8-) As always, please add these entries to your today's learning log in the beginning of your Rmd file you will use to push to your GitHub classroom.

  • Favorite aspect of the session (if any)
  • Superfluous aspect of the session (if any)
  • Eureka effect (if any)
  • Links to what I've learned so far (if any)
  • Questions (if any)

As today's special, please complete the following assignment:

In order to check the radiometric alignment, a visual inspection of the image tiles in a GIS might be all you need. So let's start with it.

:-\ Please make an eyeball verification to assess the radiometric alignment of the aerial image tiles.

While you might be quite confident that there is no mismatch in the alignment, let's cross check it using a more empirical approach just to be on the safe side.

:-\ Please design a strategy for checking the radiometric alignment of the aerial image tiles based on an empirical test and some descriptive statistics. Include this strategy as a short bullet point list in your delivery.

:-\ Please write a short R script which implements your strategy. The function below might be of some help. Since the overall computation time might be quite long, your script should save the very final data/information actually used for the descriptive analysis in an rde data file. This will be analyzed/visualized in the Rmd file (see next task).

:-\ Please copy the code of the above R script to an Rmd file with html output and make sure the code is just shown but not executed during the compilation (i.e. include eval=FALSE in the code block statement, see W02-2. Add a second but this time executable block where you read the descriptive statistics data saved above and compute/visualize the actual statistics in some manner (e.g. as numbers or as a figure). Push your submission to your GitHub classroom repository.

Helpful templates/functions

The first file can be used as template for your R script. It shows (i) how to load a function which is saved in another R script and (ii) how to easily save data stored in a variable in an R specific data file.

The second file is a function (which is loaded into the R script) that returns a list of neighboring filenames.

The third file is a template for the final Rmd file showing (i) how to create a bullet point list and (ii) how to read a rds datasets back into the session.

Template for the R script

"rs-ws-03-2.R"
# rs-ws-03-1
# MOC - Data Analysis (T. Nauss, C. Reudenbach)
# Check radiometric image alignment
 
# Set path ---------------------------------------------------------------------
if(Sys.info()["sysname"] == "Windows"){
  filepath_base <- "D:/active/moc/msc-phygeo-remote-sensing-2016/"
} else {
  filepath_base <- "/media/permanent/active/moc/msc-phygeo-remote-sensing-2016/"
}
 
path_data <- paste0(filepath_base, "data/")
path_aerial <- paste0(path_data, "aerial/")
path_aerial_merged <- paste0(path_data, "aerial_merged/")
path_aerial_croped <- paste0(path_data, "aerial_croped/")
path_rdata <- paste0(path_data, "RData/")
path_scripts <- paste0(filepath_base, "scripts/msc-phygeo-remote-sensing/src/functions/")
path_temp <- paste0(filepath_base, "temp/")
 
 
# Libraries --------------------------------------------------------------------
library(raster)
library(tools)
source(paste0(path_scripts, "fun_ngb_aerials.R")) # Load functions from scripts
 
rasterOptions(tmpdir = path_temp)
 
 
# Get filepath of aerial tiles -------------------------------------------------
# ...
 
# To use the function, just call it
neighbours <- ngb_aerials(...)
 
#...
 
# Save intermediate results which form the basis for the descriptive analysis  -
# This example assumes that the results are stored in the variable "results".
saveRDS(results, file = paste0(path_rdata, "rs-ws-03-2.rds"))
 
results <- readRDS(paste0(path_rdata, "rs-ws-03-2.RDS"))

Function returning names of neighboring image tiles

"fun_ngb_aerials.R"
# rs-ws-03-2
# MOC - Remote Sensing (T. Nauss, C. Reudenbach)
# 
#' Get names of neighbouring aerial image tiles
#' 
#' @description
#' Create filenames of neighbouring aerial files following the naming convention
#' of the Hessiche Landesvermessungsamt (i.e. easting_northing.tif).
#'
#' @param aerial_files A list of all filenames that should be considered
#' @param step The widht/height of the individual tile in m
#'
#' @return List of vectors containing the names of each neighbouring file for 
#' each file in aerial_files. The names of the individual list entries are the 
#' names of the central file. Each list entry contains a vector of length four 
#' which gives the neighbouring filenamesn in the order north-east-south-west.
#' If one or more of these files do not exist within aerial_files, NA is 
#' returned for that position.
#'
 
ngb_aerials <- function(aerial_files, step = 2000){
  require(tools)
  ngb_files <- lapply(basename(aerial_files), function(act_file){
 
    # Get names without path to compare names although path might be different
    act_ext <- file_ext(act_file)
    fnames <- basename(aerial_files)
 
    # Get x and y coordinates of actual file from filename
    act_file_x <- as.numeric(substr(act_file, 1, 6))
    act_file_y <- as.numeric(substr(act_file, 8, 14))
 
    # Set neighbours starting from north with clockwise rotation (N, E, S, W)
    pot_ngb <- c(paste0(act_file_x, "_", act_file_y + step, ".", act_ext),
                 paste0(act_file_x + step, "_", act_file_y, ".", act_ext),
                 paste0(act_file_x, "_", act_file_y - step, ".", act_ext),
                 paste0(act_file_x - step, "_", act_file_y, ".", act_ext))
 
    # Check if neighburs exist and create vector with full filepath
    act_ngb <- sapply(pot_ngb, function(f){
      pos <- grep(f, fnames)
      if(length(pos) > 0){
        return(aerial_files[pos])
      } else {
        return(NA)
      }
    })
    return(act_ngb)
  })
 
  names(ngb_files) <- aerial_files
  return(ngb_files)
 
}

Template for R markdown file

"rs-ws-03-2.Rmd"
>
---
title: "rs-ws-03-2"
author: "MOC - Data Analysis (T. Nauss, C. Reudenbach)"
date: "03. November 2016"
output: html_document
---
 
Strategy:
 
* step 1....
* Step 2....
 
 
```{r, eval=FALSE}
# Non-executable section: Include content of your R script here
 
```
 
 
```{r}
# Executable section
# Set path ---------------------------------------------------------------------
if(Sys.info()["sysname"] == "Windows"){
  filepath_base <- "D:/active/moc/msc-phygeo-remote-sensing-2016/"
} else {
  filepath_base <- "/media/permanent/active/moc/msc-phygeo-remote-sensing-2016/"
}
 
path_data <- paste0(filepath_base, "data/")
path_rdata <- paste0(path_data, "RData/")
 
# Load intermediate results which form the basis for the descriptive analysis --
results <- readRDS(file = paste0(path_rdata, "rs-ws-03-2.rds"))
 
 
# Perform final descriptive analysis -------------------------------------------
# ...
 
```
courses/msc/msc-phygeo-remote-sensing/worksheets/rs-ws-03-2.txt · Last modified: 2016/11/10 20:39 by tnauss