This weeks lab will be completed in Windows as we will be using a new piece of software called Cloud Compare that does not work with our Linux file system.

You will find the data for this lab in /data/compare_clouds

Create a new project in Metashape and add all the photos in the sub-directory RGBI_resize to your project. These photos have been resized from their original 600 MegaPixels so that our workstations can handle them.

Once the photos are loaded you need to open the reference pane (bottom left corner)

Next import a reference

The file you are looking for is /data/15-122_25-40.csv

The coordinate system of the file is WGS 84 / UTM zone 11N
Instead of Yaw Pitch and Roll, we are using Omega, Phi, and Kappa to measure angles, Delimiter is Comma.
You will also need to tell Metashape which columns contain which information see screenshot below.

There are two photos missing from the set, Metashape will tell you it Can’t find match for, when it asks if you want to create a new marker choose no.

Save your project as compare_clouds.psx in the GEOG457 folder. (You may use a different name or folder folder as long as you account for it in scripts later in this lab).

We have loaded more photos than we need for this lab, for the sake of processing, lets disable some of them. Use the selection tool and disable photos similar to below.

In Metashape, you need to:

1. Align Photos (Use High Quality) (These photos have much less distortion than last weeks lab, as such we can benefit from requiring more precision from our tie points).

2. Build a Dense Cloud (Use High Quality Again)

3. Classify Ground Points

4. Create a DTM, DSM and Orthomosaic

5. Export your products

We are going to align our point cloud against a LiDAR point cloud collected in the same area (in the same time period). Now for the alignment of point clouds to work we need the clouds to have a very high percentage overlap. The LiDAR las you will be using has already been clipped, so now we are going to clip the SFM data to be similar. To do this in Metashape we need to define a processing region. View your dense cloud and turn off the camera footprints so you can see the point cloud in colour.

Resize you region to be similar to screenshot below, we need to do this step by eye, as any shape we were to import would not be placed correctly on our unregistered data.

With the region defined we can now export our point cloud as a las file. Making sure to export in UTM 11N.

Now its time to switch gears to us the Cloud Compare software. You can launch it by typing CloudCompare in a Linux terminal.

Drag an drop Clipped_Lidar_Ground_decimated.las onto the blue background. You can go ahead an apply default settings on the first window that pops up.

Next you will notice a window that says Coordinates are too big, this is fine just accept the defaults here as well, but notice how much the cloud is being shifted, the purpose of this is to keep the numbers small enough that the computer doesn’t remove the decimal points.

You can go ahead and play with navigating the point cloud, use the left mouse button to pan, the right button to tilt / rotate, and the scroll wheel to zoom.

When you are ready drag and drop the cloud you exported from Metashape, again you want the default settings, but when the window Coordinates are too big appears, double check that it is set to Last input, it is essential that both clouds have the same shift applied.

You should now see both clouds stacked on top of each other.

These clouds happen to be very close together to start with, but we still need to manually adjust one of the clouds before fine tuning. To manually adjust a cloud, select the cloud you want to move in the DB Tree and use the ‘translate / rotate’ tool. In this case we are referencing the SFM cloud to the LiDAR, so we will adjust the cloud we exported from Metashape.

When the Translate/Rotate tool is open navigation with the mouse will edit the cloud instead of your point of view. If you want to adjust your point of view while aligning clouds you can use the pause button. There is also an undo button if you make as mistake, when you are happy with your edits press the check to close the tool.

For our purposes we do not want to rotate the cloud, so don’t use the left mouse button, it’s a hard habit to break, but this is the joys of 3D space. Also note that you can turn the translation (Tx Ty Tz) direction on or off. My recommendation is to turn on only z get the height close, then switch to only x and y, to set the horizontal alignment.

Once you are happy the clouds are reasonably close press the check to finish.

Now use [CTRL] Click to select both clouds in the DB Tree.

And open the Fine Registration Tool

This tool works by paring up the nearest points between the clouds, and calculating their average distance in 3D vector space. The average is represented as RMS or (Root Mean Squared) a type of average that handles having both positive and negative distances at the same time. The software will continually tweak the clouds position and test the RMS until it is no longer able to achieve a lower RMS. This algorithm solve for a local maximum, as opposed to a global maximum, the purpose of manual adjustment was to make sure that the maximum of the local area we are in will be the correct solution.

Make sure that you have the LiDAR set as the reference cloud (yellow), also you will need to adjust the final overlap percentage, try to do a rough visual estimate of how much your clouds overlap and enter this in, favoring being on the slightly low side. Too low percentage reduces the precision that can be achieved, too high will cause strange artifacts as it tries to make things fit, so think Price is Right rules.

You can now see the progress window, showing the distance the clouds are apart, the number in square brackets shows how much the previous ‘tweak’ moved them closer together.

At the end you will see a transform matrix, if you have taken Linear Algebra this should be a familiar concept to you, and is the mathematical definition of the movement that happened to the cloud.

Now that is not the matrix we want, as that only represents the fine adjustment. Select the exported cloud in the DB Tree, and scroll down in the properties, copy this matrix and paste it into your text editor of choice (for instance gedit).

We need to reformat this matrix into a single line, given the matrix

1-1 1-2 1-3 1-4
2-1 2-2 2-3 2-4
3-1 3-2 3-3 3-4
4-1 4-2 4-3 4-4

We would get

[[1-1, 1-2, 1-3, 1-4], [2-1, 2-2, 2-3, 2-4], [3-1, 3-2, 3-3, 3-4], [4-1, 4-2, 4-3, 4-4]]

Your matrix should look something like this.
HINT: You can copy out the code from the web page below to get the formatting and replace your values.

[[0.999998, -0.002237, -0.000519, 5.735043], [0.002238, 0.999998, 0.000181, -4.781383], [0.000519, -0.000182, 0.999999, -26.234409], [0.000000, 0.000000, 0.000000, 1.000000]]

Now open Metashape, but don’t open your project right away.

Open the console

Now we will start by initializing the python API enter these commands

import Metashape
doc =

Next we will open the project we saved previously"C:/GEOG457/compare_clouds.psx")

You should see it appear in the GUI.

Now it’s time for some Linear Algebra. Metashape already has a transform matrix applied to our project so we are going to add the transform from cloud compare to this. For those of you familiar with Linear Algebra you may know what the identity matrix is, for those that don’t it looks something like this

1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1

This will need to be changed to the single line format to use below.

We define this in python with the command below. You will cut and paste the single line matrix you have created in your text editor.

I = Metashape.Matrix([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]])

We will define our matrix from cloud compare as T

T = Metashape.Matrix([[0.999998, -0.002237, -0.000519, 5.735043], [0.002238, 0.999998, 0.000181, -4.781383], [0.000519, -0.000182, 0.999999, -26.234409], [0.000000, 0.000000, 0.000000, 1.000000]])

Finally we will keep a copy of the default transform as S in case we make a mistake on the next step.

chunk = doc.chunk 
S = chunk.transform.matrix

Applying this translation is easy

chunk.transform.matrix = S + T - I

Note that since both S and T already had the Identity we had to remove it so we only have it once.

Now export your transformed point cloud as a .las file again and add it into Cloud Compare. You will notice that it is very close to your adjusted point cloud (not exactly due to rounding errors).

If you load a fresh copy of your pre-alignment point cloud, you will be able to clearly see the difference between before and after.

Now that our adjustments are complete we need to reset the region in Agisoft, so that our processing uses the full dataset and not just the area of the subset of the lidar.

With this newly transformed point cloud, produce a DTM, DSM and orthomasaic in Metashape. Your products will be registered to the LiDAR data.


In QGIS, use the Whitebox Tools to generate a DEM from the LiDAR las file. You can create a DEM in Cloud Compare as well (if you are so inclined).

Compare your results.

Categories: GEOG 457Labs