Let’s play with mapping tools on non-maps data ! {rayshader} is nice on raster maps, but what about using it on segmentized plant cell?
Use of cartography tools out of context
This won’t be the first time I use mapping tools for non-cartography purposes. In my blog post on the Shiny App for expert image comparison, I spoke about a paper written with Marion Louveaux, a bio-image data analyst working on microscopy images from plants tissues. In this paper, we used tools for mesuring spatial autocorrelation on pixel colour intensities of images from confocal microscope.
Our collaboration continues through different R-packages, in development on Marion’s github account. In this blog post, I will use outputs of 3D images issued from a cell segmentation realised by Marion with MorphoGraphX software and imported as a 3D-mesh in R thanks {mgx2r} package (here is its {pkgdown} documentation page).
I wanted to find a good reason to play with Tyler Morgan-Wall packages for 3D visualisation of raster data: {rayshader} and {rayfocus}. Using cell segmentation images in combination with {rayshader} is the challenge of the day !
library(mgx2r)
library(rgl)
library(dplyr)
library(sf)
library(ggplot2)
library(raster)
library(rayshader)
library(magick)
# extraWD <- tempdir()
Get cell segmentation dataset
We use the example data of {mgx2r} vignette. This dataset is issued from MorphoGraphX. This is a 3D surface segmentation of a 3D image. It is read and transformed as a mesh with {mgx2r} to be used with {rgl}.
By the way, I really like the new functions added to {rgl}, like this rglwidget
to include {rgl} outputs in Rmarkdown HTML documents or in Shiny Apps.
This image is an interactive rgl widget
filePly <- system.file("extdata", "full/mesh/mesh_meristem_full_T0.ply", package = "mgx2r")
myMesh <- read_mgxPly(
file = filePly, ShowSpecimen = FALSE, addNormals = TRUE,
MatCol = 1, header_max = 30)
## [1] "Object has 7763 faces and 4158 vertices."
try(rgl.close(), silent = TRUE)
plot3d(myMesh)
aspect3d("iso")
# Change view
view3d(theta = 30, phi = -40, zoom = 0.5)
rglwidget()