home   >   tutorials   >   stereomorph user guide   >   8 reconstruction   >   8.1 reconstructing landmarks

8.1 Reconstructing landmarks

Once you have landmarks or curves digitized in two or more views you can reconstruct them into 3D. This section will explain how to do this using the reconstructStereoSets() function. Before preceding, load the StereoMorph library, if it itsn't already loaded.

# Load the StereoMorph package
library(StereoMorph)

If you've only digitized landmarks and do not have multiple aspects per object, you can use reconstructStereoSets() to reconstruct all the landmarks for a set of digitized images. If you'd like to try this with an example you can download this stereo landmark set (10 KB), previously used in the digitizing video frames section. Unzip the folder's contents into your current R working directory.

1. Call reconstructStereoSets() with the following three parameters.

# Reconstruct all digitized landmarks in Shapes 2D folder
reconstructStereoSets(shapes.2d='Shapes 2D', shapes.3d='Shapes 3D', 
   cal.file='calibration.txt')

These parameters refer to:

  • shapes.2d: A folder containing digitized (2D) shape data, separated into different folders by view. This is the same folder of shape files you used with the digitizing application (see digitizing photographs).
  • shapes.3d: A folder where the reconstructed data should be saved. If this folder doesn't exist, it will be created.
  • cal.file: The calibration file produced by calibrateCameras().

The reconstructStereoSets() function will reconstruct all the landmarks digitized in at least two views and save these into the "shapes.3d" folder using the same name as the corresponding 2D shape files. The reconstructed landmarks will be in the same units used in the calibration step (for the example above this is mm).

2. StereoMorph saves these files in a special xml-format that can be read using the StereoMorph function readShapes(). Use readShapes() to read these reconstructed landmarks from the 3D shapes folder.

# Read all digitized landmarks in Shapes 3D folder
shapes <- readShapes(file='Shapes 3D')

# Print all the recontructed landmarks as an array
shapes$landmarks

If there are multiple files in the "Shapes 3D" folder then the landmarks will be returned as an array in which the first dimension is the landmarks, the second dimension is the xyz-coordinates, and the third dimension is every image or frame. Note that when reading all landmarks from several files in this way, if a landmark is not digitized in every image it will be NA for those images. Thus, this landmark array will always be as long as all of the unique landmarks digitized in the entire image set.

3. For example, you can use the following code to access different landmarks of interest.

# Access a landmark from the first image
shapes$landmarks['caudal_fin_fork', , 1]

# Access a landmark from all images
shapes$landmarks['caudal_fin_fork', , ]

# Access all landmarks from the first image
shapes$landmarks[ , , 1]