3dgeo-heidelberg / py4dgeo

py4dgeo - A Python library for change analysis in 4D point clouds
https://py4dgeo.readthedocs.io
MIT License
78 stars 12 forks source link

Downsampling interface for Epoch objects #347

Closed Antzyx closed 2 months ago

Antzyx commented 2 months ago

Hello. Thank you very much for your work on this package.

I tried to perform what I assume to be a common operation : I wanted to run icp_with_stable_areas on a point cloud and ran out of memory, so I wanted to downsample my epoch. Here is what I had to do :

indices = np.random.choice(epoch.cloud.shape[0], int(epoch.cloud.shape[0] / factor), replace=False)
 xyz = epoch.cloud[indices]
 xyz = "\n".join([" ".join(map(str, point)) for point in xyz])
 try:
     with open("temp.txt", "w", encoding='utf8') as f:
         f.write(xyz)
     new_epoch = py4dgeo.read_from_xyz("temp.txt")
 except Exception as e:
      if os.path.exists("temp.txt"):
          os.remove("temp.txt")
      raise e

I am not sure if I missed some feature which would have allowed me to do this faster, but this looks like an overly complicated way of downsampling an Epoch. I tried simply epoch.cloud = epoch.cloud[indices] but this creates a segmentation error. Here are some suggestions to support this at different levels :

Keep up the good work and thank you again !

dokempf commented 2 months ago

Hey, thanks for reporting this! This should be absolutely something easily done within py4dgeo and I will bring it up at the next developer meeting. Here is my analysis of what happens:

To conclude, I think two things should be done:

Antzyx commented 2 months ago

Thank you for your answer. For now, then, I will go with downsampled = py4dgeo.Epoch(epoch.cloud[indices]) which is much more convenient :)

dokempf commented 2 months ago

I will keep this open as a reminder to properly address this.

dokempf commented 2 months ago

@Antzyx This can now (on main) also be achieved as epoch[indices] which returns exactly what py4dgeo.Epoch(epoch.cloud[indices]) did, but also normals and additional dimensions are handled correctly.