In this article you’ll find out how to transfer colors (colorize) from an image or orthophoto to the points of a LIDAR cloud, using the LAStools toolbox in QGis to render LIDAR as if it were a photo. We’ll take a look at how to create .bat files using LAStools to process a set of files.
5-Colorize from an image with LAStools
The LASTOOLS toolbox comprises three types of tool:
- file -The basic tools that take a file as processing input.
- folder – Similar tools, but using a directory as processing input. All LAS or LAZ files in this directory are processed. The processing name ends with Pro.
- pipelines – tools that automatically chain together a series of previous tools.
In the grouper folder, you will find only some of the processes present in the file group. However, with very little effort, you can create a .bat file to run a file command on an entire directory. Here, we’ll take a look at the procedure with the LAScolor tool, which is only present in the file group.
LAScolor: colorizing a point cloud
Let’s take as an example a group of four unclassified IGN HD LIDAR point clouds and the corresponding BDOrtho image
LAStools can be run from the command line, outside QGis. Instead of searching for the necessary command line syntax, we can run the tool in QGis and retrieve the command line generated by the plugin from the execution log. With a few modifications, we’ll have the .bat file we want.
Running the tool through the QGis plugin
We run the LAScolor tool from the QGis LAStools toolbox:
For the tool, we select one of the point clouds, the orthophoto, and give it any name as output. We won’t be keeping the processing result, as we’ll be using the .bat file for all the clouds in the directory.
LAStools are supplied in two versions: 32-bit and 64-bit. By default, dialogs use the 32-bit version of the tool. The problem is that these versions are limited to managing 4GB of memory and, given the number of points present in LIDAR clouds, this limit is very often exceeded. To avoid memory allocation error messages, always check the 64-bit version box.
When you click Run, the window displays the Log tab:
Following “LAStools command line” you’ll find the command line we’re looking for.
C:/lidar/cantal/LAStools\bin\lascolor -cpu64 -i "C:\lidar\colorize\input\semis1.laz" -image "C:\lidar\colorize\ortho.tif" -o "C:/lidar/colorize/output/semis1.laz"
In this example:
C:/lidar/cantal/LAStools\bin\lascolor is the tool executable
-cpu64 corresponds to the request to run the 64-bit version of the tool
-i “C:\lidar\coloriser\input\semis1.laz” is the input cloud
-image “C:\lidar\colorizeortho.tif” is the image to be used to colorize the point cloud
-o “C:/lidar/colorize/output/semis1.laz” is the resulting colorized cloud.
We open an empty text file in editing mode to build our little batch program.
The first line of this file will be the line that creates the processing loop for all files in a directory.
This line will be
for /r directory_to_process %%i in (extension) do (
In plain language, the %%i variable is given the full name (including path) of each file with a given extension within a given directory.
In our example, this line would be
for /r "C:\lidar\colorize\input" %%i in (*.laz) do (
If your point clouds are in LAS format, change *.laz to *.las
The second line is the command that runs LAScolor, where we’ll modify the input and output.
For the input file of the command we replace -i “C:\lidar\coloriser\input\semis1.laz” by the variable of the for loop: -i %%i
For the output file, we need to use an unfamiliar variable. We can’t use the %%i variable as it is, because it contains the path of the input file and we want to create the output file in another directory. We therefore need to retrieve the name of the input file without the path. To do this, we use the %%~ni variable. The ~n retrieves the name of %%i without the path or extension.
Our output will therefore be:
We need to add the path of the output directory and the desired extension to the variable.
The final result of our .bat file will then be:
for /r "C:\lidar\coloriser\input" %%i in (*.laz) do (
To run it, open a terminal window (command window), go to the directory of the bat file you’ve just created and type .\nom_du_fichier.bat (1)
You’ll see your point clouds being processed (2):
In the figure, you’ll see the message due to lack of license. Above 3 million points, there will be minor distortions and a few fewer attributes.
The final result of the four new point clouds can now be loaded into the QGis window: