Downsampling point clouds with CloudCompare in batch mode

Most laser scanners produce point clouds with irregular spacing – surfaces close to the laser scanner are scanned in much more detail than surfaces that are further away. This leads to huge point counts and file sizes, where a somewhat lower but regular spacing would be sufficient in many cases. This can be achieved by downsampling the point clouds.

This can be done with CloudCompare, and, thanks to its batch mode, it can be done on a larger number of point clouds in a single go. This is a suitable Windows batch program that does downsampling to 5mm spacing:

setlocal enabledelayedexpansion
set "pattern= "
set "replace=_"
mkdir downsampled
for %%I in (*.laz) do (
set "file=%%~nI"
cloudcompare -SILENT -AUTO_SAVE OFF -O -GLOBAL_SHIFT AUTO "%%I" -C_EXPORT_FMT LAS -SS SPATIAL 0.005 -SAVE_CLOUDS FILE "downsampled\!file:%pattern%=%replace%!.laz"

All spaces in file names are replaced by underscores (CloudCompare cannot deal with spaces), and the downsampled file is saved in LAZ format.

When your input files are in a text format, e.g. Leica’s PTS format, you will however not end up with the Intensity attribute filled correctly. This is because CloudCompare does not know that the attribute in the PTS file is the intensity. Additionally, the intensity may not conform to the LAS standard – in my test data, I encountered intensity values from -2047 to 2048, whereas LAS only supports intensity as unsigned integer, i.e. 0 or greater. Luckily, this can be dealt with by renaming the attribute field and shifting the intensity, which is done the following way:

cloudcompare -SILENT -AUTO_SAVE OFF -O -GLOBAL_SHIFT AUTO "%%I" -C_EXPORT_FMT LAS -RENAME_SF 0 Intensity -SF_OP 0 add 2047 -SS SPATIAL 0.005 -SAVE_CLOUDS FILE "downsampled\!file:%pattern%=%replace%!.laz"

Please note that this requires the latest version of CloudCompare (2.12 beta at the time of writing), as 2.11 does not support the RENAME_SF command.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert