File Exchange

image thumbnail

CSF (Cloth Simulation Filter)

version 1.2.2.2 (2.68 MB) by wpqjbzwm wpqjbzwm
LiDAR point cloud ground filtering / segmentation (bare earth extraction) method based on cloth simulation.

23 Downloads

Updated 31 May 2019

GitHub view license on GitHub

Separating point clouds into ground and non-ground measurements is an essential step to generate digital terrain models (DTMs) from LiDAR (light detection and ranging) data. Many filtering algorithms have been developed. However, even state-of-the-art filtering algorithms need to set up a number of complicated parameters carefully to achieve high accuracy.
For the purpose of reducing the parameters users to set, and promoting the filtering algorithms, we present a new filtering method which only needs a few easy-to-set integer and Boolean parameters. This method is based on cloth simulation which is a 3D computer graphics algorithm and is used for simulating cloth within a computer program. So our filtering algorithm is called cloth simulation filtering, CSF.
More information of CSF and its parameters can be found at http://www.cloudcompare.org/doc/wiki/index.php?title=CSF_(plugin).
CSF implemented the algorithm proposed by the paper "Zhang W, Qi J, Wan P, Wang H, Xie D, Wang X, Yan G. An Easy-to-Use Airborne LiDAR Data Filtering Method Based on Cloth Simulation. Remote Sensing. 2016; 8(6):501.",which can be downloaded from https://www.researchgate.net/profile/Wuming_Zhang2. Please cite this paper, if you use this software in your work.
The usage is very simple. [groundIndex,nonGroundIndex] = csf_filtering(pointcloud,typeofscene,postprocessing,gridsize); Sometime, only the type of the scene is needed to be set by the user. More details can be found in demos.
CSF has been integrated into two free softwares for point cloud processing. If you want to use it with a graphical user interface (GUI), you can download CloudCompare from http://www.cloudcompare.org/ or Point Cloud Magic from http://lidar.radi.ac.cn (In Chinese).

Cite As

wpqjbzwm wpqjbzwm (2019). CSF (Cloth Simulation Filter) (https://www.github.com/jianboqi/CSF), GitHub. Retrieved .

Zhang W, Qi J, Wan P, Wang H, Xie D, Wang X, Yan G. An Easy-to-Use Airborne LiDAR Data Filtering Method Based on Cloth Simulation. Remote Sensing. 2016; 8(6):501.

Comments and Ratings (34)

Hi,
You list is correct. The 7th is time step. Generally, first five parameters are enough. Please refer to demo m files.

Hi,

I have a question regarding the input parameters. In MATLAB, there are 7 inputs (including data input), however, in this "http://ramm.bnu.edu.cn/projects/CSF/document/ " document, there are only 5 of them. Can you tell me which one is which and what are the extra inputs? As far as I know and correct me if I'm wrong (numbered according to the input order):
1. point cloud input
2. Scene 1,2,3?
3. Slope post processing: true/false?
4. Cloth resolution?
5. Classification threshold?
6. max iterations?
7. ??????

Hi haha,
You can find explanation of parameters at http://ramm.bnu.edu.cn/projects/CSF/document/
About your problem, could you upload your data and we may test it.

hana

Hi wpqjbzwm wpqjbzwm,
Thank you!
I just run your Matlab demo (demo_without_toolbox) after demo_mex on the data you provide in sample.txt and it working fine!
But when I run it on my points (XYZ) which I read from Lidar, Matlab crashed and gave me this exception:
Segmentation violation detected!
Any idea how to solve this? and use your code?
Another question, for the parameter you provide in the demo for calling (csf_filtering), how to choose appropriate values for them?
I am using Ubuntu 16.04, Matlab 2018a

Thank you in advance

Thanks for the update, wpqjbzwm wpqjbzwm. Everything seems to work perfectly now in Matlab r2019a and Octave 5.1.0.

Hi Matthew Parkan,
Please try new version 1.2.2.0, it should work.

Hi wpqjbzwm wpqjbzwm,

Thanks for this nice contribution.

Do you know if it is possible to compile csf_filtering with Octave Octave 5.1.0 and Matlab r2019a? I've tried compiling it in Matlab r2019a (with Microsoft Visual C++ 2017 compiler) and Octave 5.1.0 (with Mingw64) on Windows with: "mex csf_filtering.cpp c2cdist.cpp Cloth.cpp CSF.cpp Particle.cpp point_cloud.cpp Rasterization.cpp XYZReader.cpp". Both of the builds are successfully, but fail on execution ("What() is:bad allocation" error message in Matlab and crash in Octave). Any suggestions?

Hi Rebecca Brown,

As the error message, the version of compiler is not correct. ('_MSC_VER': value '1800' doesn't match value '1900')
You may download a precompiled mex file. https://github.com/jianboqi/CSF/blob/master/matlab_all_params/csf_filtering.mexw64

I'm having trouble getting this to work... First, I couldn't get the code to compile with 'mex'.
Error using mex
csf.lib(CSF.obj) : MSIL .netmodule or module compiled with /GL found; restarting link with /LTCG; add /LTCG to the link command
line to improve linker performance
csf.lib(CSF.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1800' doesn't match value '1900' in csf_filtering.obj
csf.lib(c2cdist.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1800' doesn't match value '1900' in
csf_filtering.obj
csf.lib(XYZReader.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1800' doesn't match value '1900' in
csf_filtering.obj
etc...

I moved the source files to the folder and got it to compile with "mex csf_filtering.cpp c2cdist.cpp cloth.cpp CSF.cpp Particle.cpp point_cloud.cpp Rasterization.cpp XYZReader.cpp" Now I can't get the csf_filter function to work, I have a "Unexpected Standard exception from MEX file.What() is:bad allocation". Any suggestions?

Hi Carlos Cabo.
Currently cloth mesh can not be exported. You can use CSF plugin of Cloudcompare instead, which can export cloth mesh. Or you can construct mesh using the filtered point cloud. These commands may be useful: triangulation, delaunay, trisurf.

Carlos Cabo

Great algorithm!
How could we get the mesh or cloth points (rather than the points that are within a distance from the cloth)?
Thanks!

Neal Cou

tao zhang

Hi Tucker Whitesides,
The CSF.lib was built from VS2013, thus you can not build it directly under linux. If you want to do that, you can build it from source code, it should be no problem. Go to https://github.com/jianboqi/CSF, download the whole project, go to the folder "matlab_all_params", and run the following command "mex csf_filtering.cpp ../CSFDLL/c2cdist.cpp ../CSFDLL/Cloth.cpp ../CSFDLL/CSF.cpp ../CSFDLL/Particle.cpp ../CSFDLL/point_cloud.cpp ../CSFDLL/Rasterization.cpp ../CSFDLL/XYZReader.cpp" in matlab. Since I do not have matlab under linux rightnow, I do not try it immediately, but it should work because CSF has been compiled under linux before. you can try this, if you have problem, let me know.

Hey wpqjbzwm wpqjbzwm,

I was wondering if you had compiled this function in linux? I am attempting that right now and have not been able to succeed.

Using gcc-4.7 compiler in Matlab R2016a. I get multiple 'undefined reference' errors which makes em think the header or library isn't loading. I also see that the #pragma comment is ignored.

Errors:
In function `csf_filtering(double*, int, bool, double, double, int, double, int,
std::vector<int, std::allocator<int> >&, std::vector<int, std::allocator<int> >&, int&, int&)':
csf_filtering.cpp:(.text+0x54): undefined reference to `CSF::CSF()'
csf_filtering.cpp:(.text+0x67): undefined reference to `CSF::setPointCloud(double*, int)'

Warnings:
warning: ignoring #pragma comment [-Wunknown-pragmas]

Any assistance would be appreciated!

Elias Kazan

Hi wpqjbzwm wpqjbzwm,

That's great. Thank you very much. I think it is better this way.

Hi, Elias Kazan,

CSF mex is updated from V1.0 to V1.1.Three more options are available as input parameters.

[groundIndex,nonGroundIndex]=csf_filtering(PointCloudMatrix,rigidness,isSmooth,clothResolution,class_threshold,iterations,time_step)

class_threshold refers to a threshold to classify the original point cloud into ground and non-ground parts based on the distances between original point cloud and the simulated terrain. 0.5 is adapted to most of scenes.
iterations refers to the maximum iteration times of terrain simulation. 500 is enough for most of scenes.
time_step controls the displacement of particles from gravity during each iteration. 0.65 is optimized for most of scenes.

A precompiled mex file can be downloaded at https://github.com/jianboqi/CSF/blob/master/matlab_all_params/csf_filtering.mexw64

Elias Kazan

Hi wpqjbzwm wpqjbzwm,

I don't have a parameter set right now. I was just asking out of curiosity. I just expect that when the data is coming from a drone a different "class_threshold" will be needed. Thank you very much again :)

Hi, Elias Kazan,
We would like to improve it. But it needs time to try different compilers.
Before that, we may compile a new mex file for you. Which parameters (class_threshold or interations) do you want to change in the .cpp file?

Elias Kazan

Hi wpqjbzwm wpqjbzwm,
It works fine now. Thank you very much.
I would like to ask you if you are planning to fix the compiling version. I am asking because it would be nice to be able to change the parameters in the .cpp file cause right now with the precompiled version, only the default values are available.

In any case good job. Thank you for uploading.

Elias Kazan

Hi, Elias Kazan,
I just found the link of the precompiled mex file was change to https://github.com/jianboqi/CSF/blob/master/matlab/csf_filtering.mexw64
Please download it and try again.
Hope it can work this time.

Elias Kazan

Hi wpqjbzwm wpqjbzwm,
I have sent you an e-mail as you asked. I am commenting here in case that you haven't checked :)

Elias Kazan

Hi, Elias Kazan,
That is really strange. I just ran demo_without_toolbox and it worked well.
Could you please capture the screen of error message and save workspace to a mat file, then send these files to wpqjbzwm@126.com?

Elias Kazan

Hi wpqjbzwm wpqjbzwm,
Thanks for the reply. The precompiled version seems to work but I get this error when I am trying to run the demo_without_toolbox version:
One or more output arguments not assigned during call to "csf_filtering".

Error in demo_without_toolbox (line 44)
[groundIndex,nonGroundIndex] = csf_filtering(ptCloud,3,true,1);

Hi, Elias Kazan,
There is a precompiled mex file (https://github.com/jianboqi/CSF/raw/master/csf_filtering.mexw64). You may try it first.

Elias Kazan

Hi wpqjbzwm wpqjbzwm,
Thanks for the reply. I get this error when I run demo_mex.m.
Compiler: MinGW-w64 compiler for Windows (GCC version 4.9.2)
Matlab version: R2016a
Let me know if I can provide some more info.
Thank you
Elias

Hi, Elias Kazan,
We never met this problem, which step produced this error. And pls provide more information, such as what compiler version of mex in matlab was comfigured. And what matlab version are you using. Actually, the CSF.lib we provided was compiled with visual studio 2013.

Elias Kazan

Hi wpqjbzwm wpqjbzwm,
Thanks for the upload. However, I get this error when I am running the mex file:

\AppData\Local\Temp\mex_38351935561148_12080\csf_filtering.obj:csf_filtering.cpp:(.text+0x32):
undefined reference to `CSF::CSF()'
\AppData\Local\Temp\mex_38351935561148_12080\csf_filtering.obj:csf_filtering.cpp:(.text+0x41):
undefined reference to `CSF::setPointCloud(double*, int)'
\AppData\Local\Temp\mex_38351935561148_12080\csf_filtering.obj:csf_filtering.cpp:(.text+0x83):
undefined reference to `CSF::do_filtering(std::vector<int, std::allocator<int> >&, std::vector<int,
std::allocator<int> >&, bool)'
\AppData\Local\Temp\mex_38351935561148_12080\csf_filtering.obj:csf_filtering.cpp:(.text+0xb0):
undefined reference to `CSF::~CSF()'
\AppData\Local\Temp\mex_38351935561148_12080\csf_filtering.obj:csf_filtering.cpp:(.text+0xbe):
undefined reference to `CSF::~CSF()'
collect2.exe: error: ld returned 1 exit status

collect2.exe: error: ld returned 1 exit status

To Chuyen Nguyen
We ever used CSF to filter point cloud of Riegl VZ1000, and it worked well.

Hello,

Does the filter work for Terrestrial lidar? We use the Reigl Z400.
Thank you

Hi, abuzer.
To use CSF, you have to compile MEX file using demo_mex.m. After that, a file named csf_filtering.mexw64 (on Windows 64bit) will be generated. There is a precompiled mex file (https://github.com/jianboqi/CSF/raw/master/csf_filtering.mexw64). You may try it and then compile it by yourself.
Looking forward for more feedbacks or comments. Thank you.

abuzer

How to run it? Demos are not working

Undefined function or variable 'csf_filtering'.

Error in demo_without_toolbox (line 44)
[groundIndex,nonGroundIndex] = csf_filtering(ptCloud,3,true,1);

Help please..

kai yan

A very nice and novel algorithm! The best part of it is the "easy-to-use". Compared with other open or commercial codes, this one is more easy to use and its results are even better.

Updates

1.2.2.2

Minor changes to title and summary.

1.2.2.0

Fix some small bugs when using CSF with Matlab

1.2.1.0

we get a lot of feedbacks from different users around the world, the new version has been enhanced by:
1. improving accuracy for highly rugged terains
2. fixing some small bugs.

1.2.0.0

We get a lot of feedbacks from different users around the world, the new version has been enhanced by:
1. improving accuracy for highly rugged terrains.
2. Fixing some small bugs.

1.1.0.0

Three more options are added to input parameters.
[groundIndex,nonGroundIndex]=csf_filtering(PointCloudMatrix,rigidness,isSmooth,clothResolution,class_threshold,iterations,time_step)

MATLAB Release Compatibility
Created with R2012a
Compatible with any release
Platform Compatibility
Windows macOS Linux