embed_png <- function(path, dpi = NULL) { meta <- attr(png::readPNG(path, native = TRUE, info = TRUE), "info") if (!is.null(dpi)) meta$dpi <- rep(dpi, 2) knitr::asis_output(paste0( "<img src='", path, "'", " width=", round(meta$dim[1] / (meta$dpi[1] / 96)), " height=", round(meta$dim[2] / (meta$dpi[2] / 96)), " />" )) } knitr::opts_chunk$set(comment = "#>", collapse = TRUE)
This vigenette is a short tutorial showing how to apply the BUnwarpJ plugin for performing image registration to digital elevation models (DEMs). An image registration maps the transformation of each pixel from a source image to a target image. In this example, we are mapping the sufrace displacement patterns of an active rock glacier using high-resolution (0.50 m x 0.50 m) DEMs.
Start by downloading and installing the open-source image processing software Fiji https://fiji.sc/, which already includes the BUnwarpJ plugin installed.
We will use hillshade models derived from the DEMs to perform the registration. By using hillshade models, it is much easier for us to identify landmarks (i.e. boulders) that can help assist in the registration process.
In Fiji, go to File > Open
to load the hillshade models.
We need to remember the order the hillshade models were opened. The images need to be opened in this order when re-opening Fiji to continue working on a project. We will first open rock_glacier_hillshade_2012_50cm.tif
and then ock_glacier_hillshade_2017_50cm.tif
.
Note: Fiji may have trouble opening a GEOTIFF. It may appear as a blank (i.e. black) image when opened. To get around this, we can convert it to a PNG image format. We can use IrfanView to do this, just make sure to save with no compression. As long as the row and columns are consistent with the original GEOTIFF, we will have no problem transforming the resulting displacement map to local coordinate reference system.
embed_png("Fiji-toolbar.png")
embed_png("open_hillshade_2012.png")
embed_png("open_hillshade_2017.png")
Now we will will open the bUnwarpJ plugin for performing non-rigid image registration using b-splines,
Plugins > Registration > bUnwarpJ
Similar to georeferencing images in a GIS, we will map landmarks in the 2012 and 2017 hillshade models to help with the registration process. For the rock glaicer, we will map landmarks in active and stable areas of the scene.
embed_png("bunwarpj_toolbar.png")
embed_png("landmark_all_hillshade_2012.png")
embed_png("landmark_all_hillshade_2017.png")
Don't forget to save the landmarks we just mapped,
I/O Menu > Save Landmarks As…
We should use a filename to remember the direction of mapping, e.g., Landmarks_source2012_to_target2017.txt
.
embed_png("bunwarpj_io_menu.png")
Note: When loading landmarks, make sure that source image is the 2012 hillshade and the target image is the 2017 hillshade, otherwise the landmarks will not be positioned correctly.
Now we can run the registration. We can use the following settings. By mapping/loading landmarks, they will be automatically used for the registration.
embed_png("bunwarpj_settings.png")
A Save transformation task
will pop up when registration is complete.
This transformation file can be opened in R.
Select I/O Menu > Convert Transformation to RAW
embed_png("convert_direct_to_raw_select_elastic.png")
embed_png("convert_direct_to_raw_output_filename.png")
Now we can use R for transforming the image registration to a local CRS and visualizing the mapped surface displacement results.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.