pointtree 1.0.0__tar.gz → 2.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (154) hide show
  1. {pointtree-1.0.0 → pointtree-2.0.0}/PKG-INFO +16 -4
  2. {pointtree-1.0.0 → pointtree-2.0.0}/README.md +12 -2
  3. {pointtree-1.0.0 → pointtree-2.0.0}/pyproject.toml +5 -3
  4. {pointtree-1.0.0 → pointtree-2.0.0}/src/pointtree/evaluation/_instance_segmentation_metrics.py +96 -7
  5. {pointtree-1.0.0 → pointtree-2.0.0}/src/pointtree/evaluation/_match_instances.py +61 -29
  6. {pointtree-1.0.0 → pointtree-2.0.0}/src/pointtree/instance_segmentation/_coarse_to_fine_algorithm.py +12 -9
  7. {pointtree-1.0.0 → pointtree-2.0.0}/src/pointtree/instance_segmentation/_tree_x_algorithm.py +194 -299
  8. pointtree-2.0.0/src/pointtree/operations/_no_stdout.py +33 -0
  9. {pointtree-1.0.0 → pointtree-2.0.0}/src/pointtree/operations/_statistical_outlier_removal.py +3 -6
  10. pointtree-2.0.0/src/pointtree/tree_attributes/__init__.py +5 -0
  11. pointtree-2.0.0/src/pointtree/tree_attributes/_tree_attributes.py +663 -0
  12. pointtree-2.0.0/src/pointtree/tree_attributes/stem_diameter/__init__.py +9 -0
  13. pointtree-2.0.0/src/pointtree/tree_attributes/stem_diameter/_allometric_model.py +222 -0
  14. pointtree-2.0.0/src/pointtree/tree_attributes/stem_diameter/_estimate_stem_diameter.py +100 -0
  15. pointtree-2.0.0/src/pointtree/tree_attributes/stem_diameter/_estimate_stem_diameter_gam.py +96 -0
  16. pointtree-2.0.0/src/pointtree/tree_attributes/stem_diameter/_fit_circles_and_ellipses_to_stem_layers.py +152 -0
  17. pointtree-2.0.0/src/pointtree/tree_attributes/stem_diameter/_select_best_stem_layer_combination.py +87 -0
  18. {pointtree-1.0.0 → pointtree-2.0.0}/src/pointtree/visualization/_color_point_cloud.py +31 -5
  19. {pointtree-1.0.0 → pointtree-2.0.0}/src/pointtree/visualization/_plot_fitted_shape.py +4 -4
  20. {pointtree-1.0.0 → pointtree-2.0.0}/test/evaluation/test_instance_segmentation_metrics.py +71 -0
  21. {pointtree-1.0.0 → pointtree-2.0.0}/test/evaluation/test_match_instances.py +21 -3
  22. {pointtree-1.0.0 → pointtree-2.0.0}/test/instance_segmentation/test_tree_x_algorithm.py +58 -50
  23. {pointtree-1.0.0 → pointtree-2.0.0}/test/operations/test_cloth_simulation_filtering.py +1 -1
  24. pointtree-2.0.0/test/operations/test_no_stdout.py +45 -0
  25. pointtree-2.0.0/test/tree_attributes/stem_diameter/__init__.py +0 -0
  26. pointtree-2.0.0/test/tree_attributes/stem_diameter/test_allometric_model.py +121 -0
  27. pointtree-2.0.0/test/tree_attributes/stem_diameter/test_estimate_stem_diameter.py +99 -0
  28. pointtree-2.0.0/test/tree_attributes/stem_diameter/test_estimate_stem_diameter_gam.py +95 -0
  29. pointtree-2.0.0/test/tree_attributes/stem_diameter/test_fit_circles_and_ellipses_to_stem_layers.py +107 -0
  30. pointtree-2.0.0/test/tree_attributes/stem_diameter/test_select_best_stem_layer_combination.py +84 -0
  31. pointtree-2.0.0/test/tree_attributes/test_tree_attributes.py +764 -0
  32. pointtree-2.0.0/test/visualization/__init__.py +0 -0
  33. pointtree-1.0.0/src/pointtree/operations/_no_stdout.py +0 -22
  34. {pointtree-1.0.0 → pointtree-2.0.0}/.clang-format +0 -0
  35. {pointtree-1.0.0 → pointtree-2.0.0}/.coveragerc +0 -0
  36. {pointtree-1.0.0 → pointtree-2.0.0}/.github/workflows/build-docker-image.yml +0 -0
  37. {pointtree-1.0.0 → pointtree-2.0.0}/.github/workflows/clean-up-pull-requests.yml +0 -0
  38. {pointtree-1.0.0 → pointtree-2.0.0}/.github/workflows/code-quality-main.yml +0 -0
  39. {pointtree-1.0.0 → pointtree-2.0.0}/.github/workflows/code-quality-pull-requests.yml +0 -0
  40. {pointtree-1.0.0 → pointtree-2.0.0}/.github/workflows/code-quality.yml +0 -0
  41. {pointtree-1.0.0 → pointtree-2.0.0}/.github/workflows/conventional-commits-pull-requests.yml +0 -0
  42. {pointtree-1.0.0 → pointtree-2.0.0}/.github/workflows/deploy-docs.yml +0 -0
  43. {pointtree-1.0.0 → pointtree-2.0.0}/.github/workflows/generate-docs.yml +0 -0
  44. {pointtree-1.0.0 → pointtree-2.0.0}/.github/workflows/release-package.yml +0 -0
  45. {pointtree-1.0.0 → pointtree-2.0.0}/.gitignore +0 -0
  46. {pointtree-1.0.0 → pointtree-2.0.0}/.mypy.ini +0 -0
  47. {pointtree-1.0.0 → pointtree-2.0.0}/.pre-commit-config.yaml +0 -0
  48. {pointtree-1.0.0 → pointtree-2.0.0}/.rcfile +0 -0
  49. {pointtree-1.0.0 → pointtree-2.0.0}/CHANGELOG.md +0 -0
  50. {pointtree-1.0.0 → pointtree-2.0.0}/CMakeLists.txt +0 -0
  51. {pointtree-1.0.0 → pointtree-2.0.0}/Dockerfile +0 -0
  52. {pointtree-1.0.0 → pointtree-2.0.0}/LICENSE +0 -0
  53. {pointtree-1.0.0 → pointtree-2.0.0}/citation.cff +0 -0
  54. {pointtree-1.0.0 → pointtree-2.0.0}/csrc/include/PointTree/evaluation/instance_segmentation_metrics.h +0 -0
  55. {pointtree-1.0.0 → pointtree-2.0.0}/csrc/include/PointTree/instance_segmentation/coarse_to_fine_algorithm.h +0 -0
  56. {pointtree-1.0.0 → pointtree-2.0.0}/csrc/include/PointTree/instance_segmentation/tree_x_algorithm.h +0 -0
  57. {pointtree-1.0.0 → pointtree-2.0.0}/csrc/include/PointTree/operations/distance_to_dtm.h +0 -0
  58. {pointtree-1.0.0 → pointtree-2.0.0}/csrc/include/PointTree/operations/fit_ellipse.h +0 -0
  59. {pointtree-1.0.0 → pointtree-2.0.0}/csrc/include/PointTree/operations/points_in_ellipse.h +0 -0
  60. {pointtree-1.0.0 → pointtree-2.0.0}/csrc/include/PointTree/operations/stddev.h +0 -0
  61. {pointtree-1.0.0 → pointtree-2.0.0}/csrc/include/PointTree/type_aliases.h +0 -0
  62. {pointtree-1.0.0 → pointtree-2.0.0}/csrc/pybind/evaluation_pybind.cpp +0 -0
  63. {pointtree-1.0.0 → pointtree-2.0.0}/csrc/pybind/instance_segmentation/coarse_to_fine_algorithm_pybind.cpp +0 -0
  64. {pointtree-1.0.0 → pointtree-2.0.0}/csrc/pybind/instance_segmentation/tree_x_algorithm_pybind.cpp +0 -0
  65. {pointtree-1.0.0 → pointtree-2.0.0}/csrc/pybind/operations_pybind.cpp +0 -0
  66. {pointtree-1.0.0 → pointtree-2.0.0}/docs/Makefile +0 -0
  67. {pointtree-1.0.0 → pointtree-2.0.0}/docs/_templates/module.rst_t +0 -0
  68. {pointtree-1.0.0 → pointtree-2.0.0}/docs/_templates/package.rst_t +0 -0
  69. {pointtree-1.0.0 → pointtree-2.0.0}/docs/_templates/toc.rst_t +0 -0
  70. {pointtree-1.0.0 → pointtree-2.0.0}/docs/make.bat +0 -0
  71. {pointtree-1.0.0 → pointtree-2.0.0}/docs/source/_static/autoclass.css +0 -0
  72. {pointtree-1.0.0 → pointtree-2.0.0}/docs/source/_templates/404.html +0 -0
  73. {pointtree-1.0.0 → pointtree-2.0.0}/docs/source/_templates/index.html +0 -0
  74. {pointtree-1.0.0 → pointtree-2.0.0}/docs/source/_templates/module.rst_t +0 -0
  75. {pointtree-1.0.0 → pointtree-2.0.0}/docs/source/_templates/package.rst_t +0 -0
  76. {pointtree-1.0.0 → pointtree-2.0.0}/docs/source/_templates/toc.rst_t +0 -0
  77. {pointtree-1.0.0 → pointtree-2.0.0}/docs/source/_templates/version.html +0 -0
  78. {pointtree-1.0.0 → pointtree-2.0.0}/docs/source/_templates/versions.html +0 -0
  79. {pointtree-1.0.0 → pointtree-2.0.0}/docs/source/changelog/index.rst +0 -0
  80. {pointtree-1.0.0 → pointtree-2.0.0}/docs/source/conf.py +0 -0
  81. {pointtree-1.0.0 → pointtree-2.0.0}/docs/source/develop/index.rst +0 -0
  82. {pointtree-1.0.0 → pointtree-2.0.0}/docs/source/how-to/install/includes/clone.sh +0 -0
  83. {pointtree-1.0.0 → pointtree-2.0.0}/docs/source/how-to/install/includes/install.sh +0 -0
  84. {pointtree-1.0.0 → pointtree-2.0.0}/docs/source/index.rst +0 -0
  85. {pointtree-1.0.0 → pointtree-2.0.0}/docs/source/modules.rst +0 -0
  86. {pointtree-1.0.0 → pointtree-2.0.0}/docs/source/pointtree.config.rst +0 -0
  87. {pointtree-1.0.0 → pointtree-2.0.0}/docs/source/pointtree.evaluation.rst +0 -0
  88. {pointtree-1.0.0 → pointtree-2.0.0}/docs/source/pointtree.instance_segmentation.rst +0 -0
  89. {pointtree-1.0.0 → pointtree-2.0.0}/docs/source/pointtree.operations.rst +0 -0
  90. {pointtree-1.0.0 → pointtree-2.0.0}/docs/source/pointtree.rst +0 -0
  91. {pointtree-1.0.0 → pointtree-2.0.0}/docs/source/pointtree.visualization.rst +0 -0
  92. {pointtree-1.0.0 → pointtree-2.0.0}/docs/source/robots.txt +0 -0
  93. {pointtree-1.0.0 → pointtree-2.0.0}/mypy_stubs/sklearn/__init__.pyi +0 -0
  94. {pointtree-1.0.0 → pointtree-2.0.0}/mypy_stubs/sklearn/cluster.pyi +0 -0
  95. {pointtree-1.0.0 → pointtree-2.0.0}/mypy_stubs/sklearn/decomposition.pyi +0 -0
  96. {pointtree-1.0.0 → pointtree-2.0.0}/mypy_stubs/sklearn/linear_model.pyi +0 -0
  97. {pointtree-1.0.0 → pointtree-2.0.0}/mypy_stubs/torch_scatter/__init__.py +0 -0
  98. {pointtree-1.0.0 → pointtree-2.0.0}/mypy_stubs/torch_scatter/scatter_max.pyi +0 -0
  99. {pointtree-1.0.0 → pointtree-2.0.0}/mypy_stubs/torch_scatter/segment_csr.pyi +0 -0
  100. {pointtree-1.0.0 → pointtree-2.0.0}/notebooks/0_evaluate_semantic_segmentation_old.ipynb +0 -0
  101. {pointtree-1.0.0 → pointtree-2.0.0}/notebooks/0_preprocess_semantic_segmentation.ipynb +0 -0
  102. {pointtree-1.0.0 → pointtree-2.0.0}/notebooks/1_evaluate_semantic_segmentation.ipynb +0 -0
  103. {pointtree-1.0.0 → pointtree-2.0.0}/notebooks/2_color_semantic_segmentation.ipynb +0 -0
  104. {pointtree-1.0.0 → pointtree-2.0.0}/notebooks/3_evaluate_instance_segmentation.ipynb +0 -0
  105. {pointtree-1.0.0 → pointtree-2.0.0}/notebooks/4_color_instance_segmentation.ipynb +0 -0
  106. {pointtree-1.0.0 → pointtree-2.0.0}/notebooks/4_evaluate_instance_segmentation_old.ipynb +0 -0
  107. {pointtree-1.0.0 → pointtree-2.0.0}/setup.py +0 -0
  108. {pointtree-1.0.0 → pointtree-2.0.0}/src/pointtree/__init__.py +0 -0
  109. {pointtree-1.0.0 → pointtree-2.0.0}/src/pointtree/config/__init__.py +0 -0
  110. {pointtree-1.0.0 → pointtree-2.0.0}/src/pointtree/config/_config.py +0 -0
  111. {pointtree-1.0.0 → pointtree-2.0.0}/src/pointtree/evaluation/__init__.py +0 -0
  112. {pointtree-1.0.0 → pointtree-2.0.0}/src/pointtree/evaluation/_performance_tracker.py +0 -0
  113. {pointtree-1.0.0 → pointtree-2.0.0}/src/pointtree/evaluation/_profiler.py +0 -0
  114. {pointtree-1.0.0 → pointtree-2.0.0}/src/pointtree/evaluation/_semantic_segmentation_metrics.py +0 -0
  115. {pointtree-1.0.0 → pointtree-2.0.0}/src/pointtree/instance_segmentation/__init__.py +0 -0
  116. {pointtree-1.0.0 → pointtree-2.0.0}/src/pointtree/instance_segmentation/_instance_segmentation_algorithm.py +0 -0
  117. {pointtree-1.0.0 → pointtree-2.0.0}/src/pointtree/instance_segmentation/filters.py +0 -0
  118. {pointtree-1.0.0 → pointtree-2.0.0}/src/pointtree/instance_segmentation/tree_x_presets.py +0 -0
  119. {pointtree-1.0.0 → pointtree-2.0.0}/src/pointtree/operations/__init__.py +0 -0
  120. {pointtree-1.0.0 → pointtree-2.0.0}/src/pointtree/operations/_cloth_simulation_filtering.py +0 -0
  121. {pointtree-1.0.0 → pointtree-2.0.0}/src/pointtree/operations/_create_digital_terrain_model.py +0 -0
  122. {pointtree-1.0.0 → pointtree-2.0.0}/src/pointtree/operations/_distance_to_dtm.py +0 -0
  123. {pointtree-1.0.0 → pointtree-2.0.0}/src/pointtree/operations/_estimate_with_linear_model.py +0 -0
  124. {pointtree-1.0.0 → pointtree-2.0.0}/src/pointtree/operations/_fit_ellipse.py +0 -0
  125. {pointtree-1.0.0 → pointtree-2.0.0}/src/pointtree/operations/_points_in_ellipse.py +0 -0
  126. {pointtree-1.0.0 → pointtree-2.0.0}/src/pointtree/operations/_polygon_area.py +0 -0
  127. {pointtree-1.0.0 → pointtree-2.0.0}/src/pointtree/py.typed +0 -0
  128. {pointtree-1.0.0 → pointtree-2.0.0}/src/pointtree/type_aliases.py +0 -0
  129. {pointtree-1.0.0 → pointtree-2.0.0}/src/pointtree/visualization/__init__.py +0 -0
  130. {pointtree-1.0.0 → pointtree-2.0.0}/src/pointtree/visualization/_color_palette.py +0 -0
  131. {pointtree-1.0.0 → pointtree-2.0.0}/src/pointtree/visualization/_hex_to_rgb.py +0 -0
  132. {pointtree-1.0.0 → pointtree-2.0.0}/src/pointtree/visualization/_save_tree_map.py +0 -0
  133. {pointtree-1.0.0 → pointtree-2.0.0}/test/__init__.py +0 -0
  134. {pointtree-1.0.0 → pointtree-2.0.0}/test/evaluation/__init__.py +0 -0
  135. {pointtree-1.0.0 → pointtree-2.0.0}/test/evaluation/test_performance_tracker.py +0 -0
  136. {pointtree-1.0.0 → pointtree-2.0.0}/test/evaluation/test_profiler.py +0 -0
  137. {pointtree-1.0.0 → pointtree-2.0.0}/test/evaluation/test_semantic_segmentation_metrics.py +0 -0
  138. {pointtree-1.0.0 → pointtree-2.0.0}/test/instance_segmentation/__init__.py +0 -0
  139. {pointtree-1.0.0 → pointtree-2.0.0}/test/instance_segmentation/test_coarse_to_fine_algorithm.py +0 -0
  140. {pointtree-1.0.0 → pointtree-2.0.0}/test/instance_segmentation/test_filters.py +0 -0
  141. {pointtree-1.0.0 → pointtree-2.0.0}/test/instance_segmentation/test_tree_x_presets.py +0 -0
  142. {pointtree-1.0.0 → pointtree-2.0.0}/test/operations/__init__.py +0 -0
  143. {pointtree-1.0.0 → pointtree-2.0.0}/test/operations/test_create_digital_terrain_model.py +0 -0
  144. {pointtree-1.0.0 → pointtree-2.0.0}/test/operations/test_distance_to_dtm.py +0 -0
  145. {pointtree-1.0.0 → pointtree-2.0.0}/test/operations/test_estimate_with_linear_model.py +0 -0
  146. {pointtree-1.0.0 → pointtree-2.0.0}/test/operations/test_fit_ellipse.py +0 -0
  147. {pointtree-1.0.0 → pointtree-2.0.0}/test/operations/test_points_in_ellipse.py +0 -0
  148. {pointtree-1.0.0 → pointtree-2.0.0}/test/operations/test_polygon_area.py +0 -0
  149. {pointtree-1.0.0 → pointtree-2.0.0}/test/operations/test_statistical_outlier_removal.py +0 -0
  150. {pointtree-1.0.0/test/visualization → pointtree-2.0.0/test/tree_attributes}/__init__.py +0 -0
  151. {pointtree-1.0.0 → pointtree-2.0.0}/test/utils/__init__.py +0 -0
  152. {pointtree-1.0.0 → pointtree-2.0.0}/test/utils/_generate_points.py +0 -0
  153. {pointtree-1.0.0 → pointtree-2.0.0}/test/utils/_generate_tree_point_cloud.py +0 -0
  154. {pointtree-1.0.0 → pointtree-2.0.0}/test/visualization/test_plot_fitted_shape.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: pointtree
3
- Version: 1.0.0
3
+ Version: 2.0.0
4
4
  Summary: A Python Package for Tree Instance Segmentation in 3D Point Clouds.
5
5
  Keywords: tree,point cloud,segmentation
6
6
  Author-Email: Josafat-Mattias Burmeister <burmeister@uni-potsdam.de>
@@ -49,7 +49,7 @@ Requires-Dist: laspy<3.0.0,>=2.0.0
49
49
  Requires-Dist: numba<1.0.0,>=0.64.0
50
50
  Requires-Dist: numpy<3.0.0,>=2.3.0
51
51
  Requires-Dist: pandas<3.0.0,>=2.0.0
52
- Requires-Dist: pointtorch<2.0.0,>=1.0.1
52
+ Requires-Dist: pointtorch<2.0.0,>=1.0.3
53
53
  Requires-Dist: psutil<7.0.0,>=5.9.0
54
54
  Requires-Dist: pyclesperanto-prototype<1.0.0,>=0.22.0
55
55
  Requires-Dist: pygam<1.0.0,>=0.9.0
@@ -57,6 +57,7 @@ Requires-Dist: rasterio<2.0.0,>=1.3.9
57
57
  Requires-Dist: scipy<2.0.0,>=1.8.0
58
58
  Requires-Dist: scikit-image<1.0.0,>=0.25.0
59
59
  Requires-Dist: scikit-learn<2.0.0,>=1.2.0
60
+ Requires-Dist: shapely<3.0.0,>=2.0.0
60
61
  Provides-Extra: dev
61
62
  Requires-Dist: black; extra == "dev"
62
63
  Requires-Dist: mypy; extra == "dev"
@@ -66,6 +67,7 @@ Requires-Dist: pylint; extra == "dev"
66
67
  Requires-Dist: pytest; extra == "dev"
67
68
  Requires-Dist: pytest-cov; extra == "dev"
68
69
  Requires-Dist: scipy-stubs; extra == "dev"
70
+ Requires-Dist: types-shapely; extra == "dev"
69
71
  Requires-Dist: types-Pillow; extra == "dev"
70
72
  Requires-Dist: types-psutil; extra == "dev"
71
73
  Provides-Extra: docs
@@ -106,9 +108,19 @@ It contains the official source code of the following papers:
106
108
 
107
109
  The documentation of our package is available [here](https://ai4trees.github.io/pointtree/stable).
108
110
 
109
- ### Project Setup
111
+ ### Installation
110
112
 
111
- The setup of our package is described in the [documentation](https://ai4trees.github.io/pointtree/stable#get-started).
113
+ The installation steps are detailed in the [documentation](https://ai4trees.github.io/pointtree/stable#get-started). A minimal example is shown below:
114
+
115
+ ```bash
116
+ python -m pip install torch==2.10.0
117
+ ```
118
+ ```bash
119
+ python -m pip install torch-scatter torch-cluster -f https://data.pyg.org/whl/torch-2.10.0+cpu.html
120
+ ```
121
+ ```bash
122
+ python -m pip install pointtree
123
+ ```
112
124
 
113
125
  ### How To Use the Package
114
126
 
@@ -22,9 +22,19 @@ It contains the official source code of the following papers:
22
22
 
23
23
  The documentation of our package is available [here](https://ai4trees.github.io/pointtree/stable).
24
24
 
25
- ### Project Setup
25
+ ### Installation
26
26
 
27
- The setup of our package is described in the [documentation](https://ai4trees.github.io/pointtree/stable#get-started).
27
+ The installation steps are detailed in the [documentation](https://ai4trees.github.io/pointtree/stable#get-started). A minimal example is shown below:
28
+
29
+ ```bash
30
+ python -m pip install torch==2.10.0
31
+ ```
32
+ ```bash
33
+ python -m pip install torch-scatter torch-cluster -f https://data.pyg.org/whl/torch-2.10.0+cpu.html
34
+ ```
35
+ ```bash
36
+ python -m pip install pointtree
37
+ ```
28
38
 
29
39
  ### How To Use the Package
30
40
 
@@ -4,7 +4,7 @@ build-backend = "scikit_build_core.build"
4
4
 
5
5
  [project]
6
6
  name = "pointtree"
7
- version = "1.0.0"
7
+ version = "2.0.0"
8
8
  authors = [
9
9
  {name = "Josafat-Mattias Burmeister", email = "burmeister@uni-potsdam.de"},
10
10
  ]
@@ -35,14 +35,15 @@ dependencies = [
35
35
  "numba>=0.64.0, <1.0.0",
36
36
  "numpy>=2.3.0, <3.0.0",
37
37
  "pandas>=2.0.0, <3.0.0",
38
- "pointtorch>=1.0.1, <2.0.0",
38
+ "pointtorch>=1.0.3, <2.0.0",
39
39
  "psutil>=5.9.0, < 7.0.0",
40
40
  "pyclesperanto-prototype>=0.22.0, <1.0.0",
41
41
  "pygam>=0.9.0, <1.0.0",
42
42
  "rasterio>=1.3.9, <2.0.0",
43
43
  "scipy>=1.8.0, <2.0.0",
44
44
  "scikit-image>=0.25.0, <1.0.0",
45
- "scikit-learn>=1.2.0, <2.0.0"
45
+ "scikit-learn>=1.2.0, <2.0.0",
46
+ "shapely>=2.0.0, <3.0.0"
46
47
  ]
47
48
  [project.optional-dependencies]
48
49
  dev = [
@@ -54,6 +55,7 @@ dev = [
54
55
  "pytest",
55
56
  "pytest-cov",
56
57
  "scipy-stubs",
58
+ "types-shapely",
57
59
  "types-Pillow",
58
60
  "types-psutil",
59
61
  ]
@@ -21,6 +21,53 @@ from pointtree._evaluation_cpp import ( # type: ignore[import-untyped] # pylint
21
21
  from ._match_instances import match_instances
22
22
 
23
23
 
24
+ def _count_false_positives_matched_with_false_negatives(
25
+ matched_predicted_ids: LongArray,
26
+ matched_target_ids: LongArray,
27
+ best_target_ids_per_prediction: LongArray,
28
+ best_predicted_ids_per_target: LongArray,
29
+ invalid_instance_id: int,
30
+ ) -> int:
31
+ """
32
+ Counts unmatched predictions that are mutual best-score matches of unmatched targets.
33
+
34
+ Args:
35
+ matched_predicted_ids: ID of the matched predicted instance for each ground-truth instance.
36
+ matched_target_ids: ID of the matched ground-truth instance for each predicted instance.
37
+ best_target_ids_per_prediction: Best target instance ID for each predicted instance according to the matching
38
+ score.
39
+ best_predicted_ids_per_target: Best predicted instance ID for each target instance according to the matching
40
+ score.
41
+ invalid_instance_id: ID that is assigned to instances that could not be matched and are considered to be
42
+ false negative or false positive instances.
43
+
44
+ Returns:
45
+ Number of false positive predicted instances that are the mutual best-score match of a false negative target
46
+ instance.
47
+ """
48
+
49
+ false_negative_target_idxs = np.flatnonzero(matched_predicted_ids == invalid_instance_id)
50
+ false_positive_prediction_idxs = np.flatnonzero(matched_target_ids == invalid_instance_id)
51
+
52
+ if len(false_negative_target_idxs) == 0 or len(false_positive_prediction_idxs) == 0:
53
+ return 0
54
+
55
+ start_instance_id = invalid_instance_id + 1
56
+
57
+ best_prediction_ids = best_predicted_ids_per_target[false_negative_target_idxs]
58
+ has_best_prediction = best_prediction_ids != invalid_instance_id
59
+
60
+ false_negative_target_idxs = false_negative_target_idxs[has_best_prediction]
61
+ best_prediction_idxs = best_prediction_ids[has_best_prediction] - start_instance_id
62
+
63
+ is_false_positive = matched_target_ids[best_prediction_idxs] == invalid_instance_id
64
+ is_mutual_best_match = (
65
+ best_target_ids_per_prediction[best_prediction_idxs] == false_negative_target_idxs + start_instance_id
66
+ )
67
+
68
+ return int(np.count_nonzero(is_false_positive & is_mutual_best_match))
69
+
70
+
24
71
  def instance_detection_metrics( # pylint: disable=too-many-locals
25
72
  target: LongArray,
26
73
  prediction: LongArray,
@@ -29,6 +76,9 @@ def instance_detection_metrics( # pylint: disable=too-many-locals
29
76
  *,
30
77
  invalid_instance_id: int = -1,
31
78
  uncertain_instance_id: int = -2,
79
+ count_fp_if_matched_with_fn: bool = True,
80
+ best_target_ids_per_prediction: Optional[LongArray] = None,
81
+ best_predicted_ids_per_target: Optional[LongArray] = None,
32
82
  ):
33
83
  r"""
34
84
  Computes metrics to measure the instance detection quality. Based on a given matching of ground-truth
@@ -68,6 +118,12 @@ def instance_detection_metrics( # pylint: disable=too-many-locals
68
118
  uncertain_instance_id: ID that is assigned to predicted instances that could not be matched to any target
69
119
  instance but still should not be counted as false positive instances. Must be equal to or smaller than
70
120
  :code:`invalid_instance_id`.
121
+ count_fp_if_matched_with_fn: Whether unmatched predicted instances should be counted as false positives even if
122
+ they are the mutual best-IoU match of an unmatched target instance.
123
+ best_target_ids_per_prediction: Best target instance ID for each predicted instance according to the matching
124
+ score. Required if :code:`count_fp_if_matched_with_fn` is :code:`False`.
125
+ best_predicted_ids_per_target: Best predicted instance ID for each target instance according to the matching
126
+ score. Required if :code:`count_fp_if_matched_with_fn` is :code:`False`.
71
127
 
72
128
  Raises:
73
129
  - ValueError: If :code:`uncertain_instance_id` is larger than :code:`invalid_instance_id`.
@@ -125,6 +181,19 @@ def instance_detection_metrics( # pylint: disable=too-many-locals
125
181
  tp = (np.logical_not(np.isin(matched_predicted_ids, (invalid_instance_id, uncertain_instance_id)))).sum()
126
182
  fn = (matched_predicted_ids == invalid_instance_id).sum()
127
183
  fp = (matched_target_ids == invalid_instance_id).sum()
184
+ if not count_fp_if_matched_with_fn:
185
+ if best_target_ids_per_prediction is None or best_predicted_ids_per_target is None:
186
+ raise ValueError(
187
+ "best_target_ids_per_prediction and best_predicted_ids_per_target must be provided if "
188
+ "count_fp_if_matched_with_fn is False."
189
+ )
190
+ fp -= _count_false_positives_matched_with_false_negatives(
191
+ matched_predicted_ids,
192
+ matched_target_ids,
193
+ best_target_ids_per_prediction,
194
+ best_predicted_ids_per_target,
195
+ invalid_instance_id,
196
+ )
128
197
 
129
198
  metrics = {
130
199
  "TP": tp,
@@ -490,6 +559,7 @@ def evaluate_instance_segmentation( # pylint: disable=too-many-branches, too-ma
490
559
  include_unmatched_instances_in_seg_metrics: bool = True,
491
560
  invalid_instance_id: int = -1,
492
561
  uncertain_instance_id: int = -2,
562
+ count_fp_if_matched_with_fn: bool = True,
493
563
  compute_partition_metrics: bool = True,
494
564
  num_partitions: int = 10,
495
565
  ) -> Tuple[
@@ -534,6 +604,8 @@ def evaluate_instance_segmentation( # pylint: disable=too-many-branches, too-ma
534
604
  uncertain_instance_id: ID that is assigned to predicted instances that could not be matched to any target
535
605
  instance but still should not be counted as false positive instances. Must be equal to or smaller than
536
606
  :code:`invalid_instance_id`.
607
+ count_fp_if_matched_with_fn: Whether unmatched predicted instances should be counted as false positives even if
608
+ they are the mutual best-IoU match of an unmatched target instance.
537
609
  compute_partition_metrics: Whether the metrics per partition should be computed.
538
610
  num_partitions: Number of partitions for the computation of instance segmentation metrics per partition.
539
611
 
@@ -554,13 +626,24 @@ def evaluate_instance_segmentation( # pylint: disable=too-many-branches, too-ma
554
626
  set to :code:`False`.
555
627
  """
556
628
 
557
- matched_target_ids, matched_predicted_ids, _ = match_instances(
629
+ detection_matching_results = match_instances(
558
630
  target,
559
631
  prediction,
560
632
  xyz,
561
633
  method=detection_metrics_matching_method,
562
634
  invalid_instance_id=invalid_instance_id,
635
+ return_best_matches=not count_fp_if_matched_with_fn,
636
+ )
637
+ detection_matching_results_with_best_matches = cast(
638
+ Tuple[LongArray, LongArray, Dict[str, LongArray], LongArray, LongArray],
639
+ detection_matching_results,
563
640
  )
641
+ matched_target_ids, matched_predicted_ids = detection_matching_results[:2]
642
+ best_target_ids_per_prediction: Optional[LongArray] = None
643
+ best_predicted_ids_per_target: Optional[LongArray] = None
644
+ if not count_fp_if_matched_with_fn:
645
+ best_target_ids_per_prediction = detection_matching_results_with_best_matches[3]
646
+ best_predicted_ids_per_target = detection_matching_results_with_best_matches[4]
564
647
 
565
648
  instance_detect_metrics = instance_detection_metrics(
566
649
  target,
@@ -569,14 +652,20 @@ def evaluate_instance_segmentation( # pylint: disable=too-many-branches, too-ma
569
652
  matched_target_ids,
570
653
  invalid_instance_id=invalid_instance_id,
571
654
  uncertain_instance_id=uncertain_instance_id,
655
+ count_fp_if_matched_with_fn=count_fp_if_matched_with_fn,
656
+ best_target_ids_per_prediction=best_target_ids_per_prediction,
657
+ best_predicted_ids_per_target=best_predicted_ids_per_target,
572
658
  )
573
659
 
574
- matched_target_ids, matched_predicted_ids, segmentation_metrics = match_instances(
575
- target,
576
- prediction,
577
- xyz,
578
- method=segmentation_metrics_matching_method,
579
- invalid_instance_id=invalid_instance_id,
660
+ matched_target_ids, matched_predicted_ids, segmentation_metrics = cast(
661
+ Tuple[LongArray, LongArray, Dict[str, LongArray]],
662
+ match_instances(
663
+ target,
664
+ prediction,
665
+ xyz,
666
+ method=segmentation_metrics_matching_method,
667
+ invalid_instance_id=invalid_instance_id,
668
+ ),
580
669
  )
581
670
 
582
671
  start_instance_id = target[target != invalid_instance_id].min()
@@ -2,15 +2,19 @@
2
2
 
3
3
  __all__ = ["match_instances"]
4
4
 
5
- from typing import Dict, Literal, Optional, Tuple
5
+ from typing import Dict, Literal, Optional, Tuple, Union, cast
6
6
 
7
7
  import numpy as np
8
+ import numpy.typing as npt
8
9
  from pointtorch.metrics.instance_segmentation import match_instances as match_instances_pointtorch
9
10
  import torch
10
11
 
11
12
  from pointtree.operations import cloth_simulation_filtering, create_digital_terrain_model, distance_to_dtm
12
13
  from pointtree.type_aliases import FloatArray, LongArray
13
14
 
15
+ MatchingResults = Tuple[LongArray, LongArray, Dict[str, LongArray]]
16
+ MatchingResultsWithBestMatches = Tuple[LongArray, LongArray, Dict[str, LongArray], LongArray, LongArray]
17
+
14
18
 
15
19
  def match_instances( # pylint: disable=too-many-locals
16
20
  target: LongArray,
@@ -30,13 +34,14 @@ def match_instances( # pylint: disable=too-many-locals
30
34
  min_tree_height_fp: float = 0.0,
31
35
  min_precision_fp: float = 0.0,
32
36
  labeled_mask: Optional[np.ndarray] = None,
33
- ) -> Tuple[LongArray, LongArray, Dict[str, LongArray]]:
37
+ return_best_matches: bool = False,
38
+ ) -> Union[MatchingResults, MatchingResultsWithBestMatches]:
34
39
  r"""
35
40
  This method implements the instance matching methods proposed in the following works:
36
41
 
37
42
  - :code:`panoptic_segmentation`: `Kirillov, Alexander, et al. "Panoptic segmentation." Proceedings of the IEEE/CVF \
38
43
  Conference on Computer Vision and Pattern Recognition. 2019. <https://doi.org/10.1109/CVPR.2019.00963>`__
39
-
44
+
40
45
  This method matches predicted and target instances if their IoU is striclty greater than 0.5, which results
41
46
  in an unambigous matching. This method is also used in `Wielgosz, Maciej, et al. "SegmentAnyTree: A Sensor and \
42
47
  Platform Agnostic Deep Learning Model for Tree Segmentation Using Laser Scanning Data." Remote Sensing of \
@@ -72,7 +77,7 @@ def match_instances( # pylint: disable=too-many-locals
72
77
  means that predicted instances can be matched with multiple target instances. Such a matching approach is useful
73
78
  for the calculation of segmentation metrics (e.g., coverage) that should be independent from the instance
74
79
  detection rate.
75
-
80
+
76
81
  - :code:`tree_learn`: `Henrich, Jonathan, et al. "TreeLearn: A Deep Learning Method for Segmenting Individual Trees
77
82
  from Ground-Based LiDAR Forest Point Clouds." Ecological Informatics 84 (2024): 102888.
78
83
  <https://doi.org/10.1016/j.ecoinf.2024.102888>`__
@@ -109,6 +114,9 @@ def match_instances( # pylint: disable=too-many-locals
109
114
  matched instance ID is set to :code:`uncertain_instance_id`.
110
115
  labeled_mask: Boolean mask indicating which points are labeled. This mask is used to mark false positive
111
116
  instances that mainly consist of unlabeled points.
117
+ return_best_matches: Whether to additionally return the best predicted instance for each target instance and
118
+ the best target instance for each predicted instance according to the matching score used by the selected
119
+ method.
112
120
 
113
121
  Returns: A tuple with the following elements:
114
122
  - :code:`matched_target_ids`: IDs of the matched target instance for each predicted instance. If the predicted
@@ -121,6 +129,10 @@ def match_instances( # pylint: disable=too-many-locals
121
129
  false positive, and false negative points between the matched instances. For target instances not matched to
122
130
  any prediction, the true and false posiitves are set to zero and the false negatives to the number of target
123
131
  points.
132
+ - :code:`best_target_ids_per_prediction`: Best target instance ID for each predicted instance. Only returned if
133
+ :code:`return_best_matches` is :code:`True`.
134
+ - :code:`best_predicted_ids_per_target`: Best predicted instance ID for each target instance. Only returned if
135
+ :code:`return_best_matches` is :code:`True`.
124
136
 
125
137
  Shape:
126
138
  - :code:`xyz`: :math:`(N, 3)`
@@ -130,6 +142,8 @@ def match_instances( # pylint: disable=too-many-locals
130
142
  - :code:`matched_target_ids`: :math:`(P)`
131
143
  - :code:`matched_predicted_ids`: :math:`(T)`
132
144
  - :code:`metrics`: Dictionary whose values are tensors of length :math:`(T)`
145
+ - :code:`best_target_ids_per_prediction`: :math:`(P)`
146
+ - :code:`best_predicted_ids_per_target`: :math:`(T)`
133
147
 
134
148
  | where
135
149
  |
@@ -138,17 +152,28 @@ def match_instances( # pylint: disable=too-many-locals
138
152
  | :math:`T` = number of target instances
139
153
  """
140
154
 
141
- matched_target_ids_torch, matched_predicted_ids_torch, segmentation_metrics_torch = match_instances_pointtorch(
155
+ matching_results_torch = match_instances_pointtorch(
142
156
  torch.from_numpy(target),
143
157
  torch.from_numpy(prediction),
144
158
  xyz=torch.from_numpy(xyz),
145
159
  method=method,
146
160
  invalid_instance_id=invalid_instance_id,
161
+ return_best_matches=return_best_matches,
147
162
  )
148
163
 
164
+ matched_target_ids_torch, matched_predicted_ids_torch, segmentation_metrics_torch = matching_results_torch[:3]
149
165
  matched_target_ids = matched_target_ids_torch.numpy()
150
166
  matched_predicted_ids = matched_predicted_ids_torch.numpy()
151
167
  segmentation_metrics = {key: metric.numpy() for key, metric in segmentation_metrics_torch.items()}
168
+ best_target_ids_per_prediction: Optional[LongArray] = None
169
+ best_predicted_ids_per_target: Optional[LongArray] = None
170
+ if return_best_matches:
171
+ matching_results_torch_with_best_matches = cast(
172
+ Tuple[torch.Tensor, torch.Tensor, Dict[str, torch.Tensor], torch.Tensor, torch.Tensor],
173
+ matching_results_torch,
174
+ )
175
+ best_target_ids_per_prediction = matching_results_torch_with_best_matches[3].numpy()
176
+ best_predicted_ids_per_target = matching_results_torch_with_best_matches[4].numpy()
152
177
 
153
178
  if len(matched_target_ids) > 0:
154
179
  start_instance_id = prediction[prediction != invalid_instance_id].min()
@@ -169,29 +194,36 @@ def match_instances( # pylint: disable=too-many-locals
169
194
  )
170
195
  dists_to_dtm = distance_to_dtm(xyz, dtm, dtm_offset, dtm_resolution=dtm_resolution)
171
196
 
172
- if min_precision_fp <= 0 and min_tree_height_fp <= 0:
173
- return matched_target_ids, matched_predicted_ids, segmentation_metrics
174
-
175
- if min_precision_fp > 0 and labeled_mask is None:
176
- labeled_mask = target != invalid_instance_id
177
-
178
- for predicted_idx, matched_target_id in enumerate(matched_target_ids):
179
- if matched_target_id == invalid_instance_id:
180
- predicted_id = start_instance_id + predicted_idx
181
- if min_precision_fp > 0:
182
- # count percentage of points belonging to labeled ground-truth instances
183
- intersection = np.logical_and(
184
- labeled_mask, prediction == predicted_id # type: ignore[arg-type]
185
- ).sum()
186
- precision = intersection / (prediction == predicted_id).sum()
187
- else:
188
- precision = 1.0
189
-
190
- tree_height = np.inf
191
- if dists_to_dtm is not None:
192
- tree_height = max(0, dists_to_dtm[prediction == predicted_id].max())
193
-
194
- if precision < min_precision_fp or tree_height < min_tree_height_fp:
195
- matched_target_ids[predicted_idx] = uncertain_instance_id
197
+ if min_precision_fp > 0 or min_tree_height_fp > 0:
198
+ if min_precision_fp > 0 and labeled_mask is None:
199
+ labeled_mask = target != invalid_instance_id
200
+
201
+ for predicted_idx, matched_target_id in enumerate(matched_target_ids):
202
+ if matched_target_id == invalid_instance_id:
203
+ predicted_id = start_instance_id + predicted_idx
204
+ if min_precision_fp > 0:
205
+ # count percentage of points belonging to labeled ground-truth instances
206
+ intersection = np.logical_and(
207
+ labeled_mask, prediction == predicted_id # type: ignore[arg-type]
208
+ ).sum()
209
+ precision = intersection / (prediction == predicted_id).sum()
210
+ else:
211
+ precision = 1.0
212
+
213
+ tree_height = np.inf
214
+ if dists_to_dtm is not None:
215
+ tree_height = max(0, dists_to_dtm[prediction == predicted_id].max())
216
+
217
+ if precision < min_precision_fp or tree_height < min_tree_height_fp:
218
+ matched_target_ids[predicted_idx] = uncertain_instance_id
219
+
220
+ if return_best_matches:
221
+ return (
222
+ matched_target_ids,
223
+ matched_predicted_ids,
224
+ segmentation_metrics,
225
+ cast(npt.NDArray, best_target_ids_per_prediction),
226
+ cast(npt.NDArray, best_predicted_ids_per_target),
227
+ )
196
228
 
197
229
  return matched_target_ids, matched_predicted_ids, segmentation_metrics
@@ -8,7 +8,6 @@ from typing import Literal, Optional, Tuple, Union, cast
8
8
 
9
9
  from scipy.spatial import KDTree
10
10
  import numpy as np
11
- import numpy.typing as npt
12
11
  from pointtorch.operations.numpy import make_labels_consecutive, voxel_downsampling
13
12
  import scipy.ndimage as ndi
14
13
  from skimage.morphology import diamond, disk, footprint_rectangle, dilation, erosion
@@ -422,7 +421,7 @@ class CoarseToFineAlgorithm(InstanceSegmentationAlgorithm): # pylint: disable=t
422
421
  return np.empty((0, 0), dtype=np.float64), np.empty((0, 0), dtype=np.float64), np.empty(0, dtype=np.float64)
423
422
 
424
423
  if bounding_box is None:
425
- bounding_box = np.row_stack([xyz[:, :2].min(axis=0), xyz[:, :2].max(axis=0)])
424
+ bounding_box = np.vstack([xyz[:, :2].min(axis=0), xyz[:, :2].max(axis=0)])
426
425
 
427
426
  xyz = xyz.copy()
428
427
  xyz = xyz[(xyz[:, :2] <= bounding_box[1]).all(axis=-1)]
@@ -511,7 +510,7 @@ class CoarseToFineAlgorithm(InstanceSegmentationAlgorithm): # pylint: disable=t
511
510
  with Profiler("Height map computation", self._performance_tracker):
512
511
  bounding_box = None
513
512
  if self._algorithm != "watershed_crown_top_positions":
514
- bounding_box = np.row_stack([tree_xyz[:, :2].min(axis=0), tree_xyz[:, :2].max(axis=0)])
513
+ bounding_box = np.vstack([tree_xyz[:, :2].min(axis=0), tree_xyz[:, :2].max(axis=0)])
515
514
  tree_xyz = tree_xyz[classification == self._crown_class_id]
516
515
  canopy_height_model, count_map, grid_origin = self.create_height_map(
517
516
  tree_xyz, grid_size=self._grid_size_canopy_height_model, bounding_box=bounding_box
@@ -579,13 +578,17 @@ class CoarseToFineAlgorithm(InstanceSegmentationAlgorithm): # pylint: disable=t
579
578
  if len(crown_top_positions) == 0:
580
579
  return trunk_positions
581
580
 
582
- crown_distances, crown_indices = KDTree(crown_top_positions).query(trunk_positions, k=1)
583
- crown_distances = cast(np.ndarray, crown_distances).flatten()
584
- crown_indices = cast(np.ndarray, crown_indices).flatten()
581
+ crown_distances, crown_indices = cast(
582
+ Tuple[np.ndarray, np.ndarray], KDTree(crown_top_positions).query(trunk_positions, k=1)
583
+ )
584
+ crown_distances = crown_distances.flatten()
585
+ crown_indices = crown_indices.flatten()
585
586
 
586
- trunk_distances, trunk_indices = KDTree(trunk_positions).query(crown_top_positions, k=1)
587
- trunk_distances = cast(npt.NDArray, trunk_distances).flatten()
588
- trunk_indices = cast(npt.NDArray, trunk_indices).flatten()
587
+ trunk_distances, trunk_indices = cast(
588
+ Tuple[np.ndarray, np.ndarray], KDTree(trunk_positions).query(crown_top_positions, k=1)
589
+ )
590
+ trunk_distances = trunk_distances.flatten()
591
+ trunk_indices = trunk_indices.flatten()
589
592
 
590
593
  tree_positions = []
591
594
  matched_crown_positions = []