PartSegCore-compiled-backend 0.15.13__tar.gz → 0.15.14__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.
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/.pre-commit-config.yaml +3 -3
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/PKG-INFO +2 -1
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/pyproject.toml +2 -0
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/multiscale_opening/mso.h +136 -97
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/triangulation/debug_util.hpp +7 -7
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/triangulation/intersection.hpp +22 -22
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/triangulation/point.hpp +23 -23
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/triangulation/triangulate.hpp +82 -82
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/version.py +16 -3
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/tests/test_triangulate.py +1 -2
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/.gitignore +0 -0
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/CMakeLists.txt +0 -0
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/LICENSE.txt +0 -0
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/MANIFEST.in +0 -0
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/Readme.md +0 -0
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/docs/Makefile +0 -0
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/docs/calc_bounds.rst +0 -0
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/docs/conf.py +0 -0
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/docs/fast_unique.rst +0 -0
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/docs/index.rst +0 -0
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/docs/make.bat +0 -0
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/docs/napari_mapping.rst +0 -0
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/docs/sprawl_utils.rst +0 -0
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/__init__.py +0 -0
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/_fast_unique.pyi +0 -0
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/_fast_unique.pyx +0 -0
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/_napari_mapping.pyx +0 -0
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/calc_bounds.pyi +0 -0
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/calc_bounds.pyx +0 -0
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/color_image_cython.pyi +0 -0
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/color_image_cython.pyx +0 -0
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/fast_unique.py +0 -0
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/multiscale_opening/__init__.py +0 -0
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/multiscale_opening/mso_bind.pyi +0 -0
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/multiscale_opening/mso_bind.pyx +0 -0
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/multiscale_opening/my_queue.h +0 -0
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/napari_mapping.py +0 -0
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/sprawl_utils/__init__.py +0 -0
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/sprawl_utils/distance_utils.pxd +0 -0
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/sprawl_utils/euclidean_cython.pyi +0 -0
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/sprawl_utils/euclidean_cython.pyx +0 -0
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/sprawl_utils/find_split.py +0 -0
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/sprawl_utils/find_split.pyi +0 -0
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/sprawl_utils/fuzzy_distance.pyx +0 -0
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/sprawl_utils/global_consts.h +0 -0
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/sprawl_utils/my_queue.h +0 -0
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/sprawl_utils/path_sprawl_cython.pyi +0 -0
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/sprawl_utils/path_sprawl_cython.pyx +0 -0
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/sprawl_utils/put_borders_in_queue.pyx +0 -0
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/sprawl_utils/sprawl_utils.pyi +0 -0
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/sprawl_utils/sprawl_utils.pyx +0 -0
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/triangulate.pyx +0 -0
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/utils.py +0 -0
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/tests/test_calc_bounds.py +0 -0
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/tests/test_coloring.py +0 -0
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/tests/test_fast_unique.py +0 -0
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/tests/test_napari_mapping.py +0 -0
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/tests/test_sprawl_utils/__init__.py +0 -0
- {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/tests/test_sprawl_utils/test_euclidean.py +0 -0
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
repos:
|
|
2
2
|
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
3
3
|
# Ruff version.
|
|
4
|
-
rev: v0.
|
|
4
|
+
rev: v0.13.1
|
|
5
5
|
hooks:
|
|
6
6
|
# Run the linter.
|
|
7
7
|
- id: ruff
|
|
8
8
|
# Run the formatter.
|
|
9
9
|
- id: ruff-format
|
|
10
10
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
11
|
-
rev:
|
|
11
|
+
rev: v6.0.0
|
|
12
12
|
hooks:
|
|
13
13
|
- id: check-json
|
|
14
14
|
- id: check-yaml
|
|
@@ -33,7 +33,7 @@ repos:
|
|
|
33
33
|
additional_dependencies:
|
|
34
34
|
- tomli
|
|
35
35
|
- repo: https://github.com/pre-commit/mirrors-clang-format
|
|
36
|
-
rev:
|
|
36
|
+
rev: v21.1.1 # Use the sha / tag you want to point at
|
|
37
37
|
hooks:
|
|
38
38
|
- id: clang-format
|
|
39
39
|
args: ["-style=Google"]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.2
|
|
2
2
|
Name: PartSegCore_compiled_backend
|
|
3
|
-
Version: 0.15.
|
|
3
|
+
Version: 0.15.14
|
|
4
4
|
Summary: PartSegCore compiled backend,
|
|
5
5
|
Keywords: bioimaging
|
|
6
6
|
Author-Email: Grzegorz Bokota <g.bokota@cent.uw.edu.pl>
|
|
@@ -14,6 +14,7 @@ Classifier: Programming Language :: Python :: 3.9
|
|
|
14
14
|
Classifier: Programming Language :: Python :: 3.10
|
|
15
15
|
Classifier: Programming Language :: Python :: 3.11
|
|
16
16
|
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
18
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
18
19
|
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
|
|
19
20
|
Project-URL: Homepage, https://4dnucleome.cent.uw.edu.pl/PartSeg/
|
{partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/pyproject.toml
RENAMED
|
@@ -34,6 +34,7 @@ classifiers = [
|
|
|
34
34
|
"Programming Language :: Python :: 3.10",
|
|
35
35
|
"Programming Language :: Python :: 3.11",
|
|
36
36
|
"Programming Language :: Python :: 3.12",
|
|
37
|
+
"Programming Language :: Python :: 3.13",
|
|
37
38
|
"Programming Language :: Python :: Implementation :: CPython",
|
|
38
39
|
"Topic :: Scientific/Engineering :: Bio-Informatics",
|
|
39
40
|
]
|
|
@@ -129,6 +130,7 @@ test-command = "pytest {project}/src/tests"
|
|
|
129
130
|
test-extras = ["test"]
|
|
130
131
|
skip = "pp*macos* pp31* pp39-manylinux*"
|
|
131
132
|
build = "*64"
|
|
133
|
+
enable = ["pypy", "cpython-freethreading"]
|
|
132
134
|
|
|
133
135
|
[tool.cibuildwheel.macos]
|
|
134
136
|
before-all = [
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
|
|
2
|
+
#ifndef MSO_H
|
|
3
|
+
#define MSO_H
|
|
4
|
+
|
|
1
5
|
#include <array>
|
|
2
6
|
#include <cmath>
|
|
3
7
|
#include <cstdint>
|
|
@@ -44,8 +48,9 @@ template <size_t K>
|
|
|
44
48
|
std::ostream& operator<<(std::ostream& stream,
|
|
45
49
|
const std::array<char, K>& array) {
|
|
46
50
|
stream << "array(";
|
|
47
|
-
for (size_t i = 0; i < K - 1; i++)
|
|
48
|
-
|
|
51
|
+
for (size_t i = 0; i < K - 1; i++)
|
|
52
|
+
stream << static_cast<int>(array[i]) << ", ";
|
|
53
|
+
stream << static_cast<int>(array[K - 1]) << ")";
|
|
49
54
|
return stream;
|
|
50
55
|
}
|
|
51
56
|
|
|
@@ -62,15 +67,26 @@ template <>
|
|
|
62
67
|
std::ostream& operator<<(std::ostream& stream,
|
|
63
68
|
const std::vector<unsigned char>& array) {
|
|
64
69
|
stream << "vector(";
|
|
65
|
-
|
|
66
|
-
|
|
70
|
+
if (!array.empty()) {
|
|
71
|
+
for (size_t i = 0; i < array.size() - 1; i++) {
|
|
72
|
+
stream << static_cast<int>(array[i]) << ", ";
|
|
73
|
+
}
|
|
74
|
+
stream << static_cast<int>(array.back());
|
|
75
|
+
}
|
|
76
|
+
stream << ")";
|
|
67
77
|
return stream;
|
|
68
78
|
}
|
|
79
|
+
|
|
69
80
|
std::ostream& operator<<(std::ostream& stream,
|
|
70
81
|
const std::vector<signed char>& array) {
|
|
71
82
|
stream << "vector(";
|
|
72
|
-
|
|
73
|
-
|
|
83
|
+
if (!array.empty()) {
|
|
84
|
+
for (size_t i = 0; i < array.size() - 1; i++) {
|
|
85
|
+
stream << static_cast<int>(array[i]) << ", ";
|
|
86
|
+
}
|
|
87
|
+
stream << static_cast<int>(array.back());
|
|
88
|
+
}
|
|
89
|
+
stream << ")";
|
|
74
90
|
return stream;
|
|
75
91
|
}
|
|
76
92
|
#pragma GCC diagnostic pop
|
|
@@ -95,7 +111,7 @@ template <typename T, size_t K>
|
|
|
95
111
|
std::array<size_t, K> calculate_dimension_size(const std::array<T, K>& size) {
|
|
96
112
|
std::array<size_t, K> res;
|
|
97
113
|
res[K - 1] = 1;
|
|
98
|
-
for (size_t i = K - 1; i > 0; i
|
|
114
|
+
for (size_t i = K - 1; i > 0; --i) {
|
|
99
115
|
res[i - 1] = res[i] * size[i];
|
|
100
116
|
}
|
|
101
117
|
return res;
|
|
@@ -120,7 +136,9 @@ class ArrayLimits {
|
|
|
120
136
|
};
|
|
121
137
|
ArrayLimits(std::array<T, K> lower_bound_, std::array<T, K> upper_bound_)
|
|
122
138
|
: lower_bound(lower_bound_), upper_bound(upper_bound_) {};
|
|
123
|
-
|
|
139
|
+
|
|
140
|
+
explicit ArrayLimits(std::array<T, K> upper_bound_)
|
|
141
|
+
: upper_bound(upper_bound_) {
|
|
124
142
|
this->lower_bound.fill(0);
|
|
125
143
|
};
|
|
126
144
|
void set_bounds(std::array<T, K> lower_bound, std::array<T, K> upper_bound) {
|
|
@@ -161,10 +179,11 @@ class ArrayLimits {
|
|
|
161
179
|
this->state = state;
|
|
162
180
|
}
|
|
163
181
|
std::array<T, K> operator++() {
|
|
164
|
-
for (size_t i = K
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
182
|
+
for (size_t i = K; i > 0; --i) {
|
|
183
|
+
const size_t idx = i - 1;
|
|
184
|
+
++this->state[idx];
|
|
185
|
+
if (this->state[idx] >= this->upper_bound[idx])
|
|
186
|
+
this->state[idx] = this->lower_bound[idx];
|
|
168
187
|
else
|
|
169
188
|
break;
|
|
170
189
|
}
|
|
@@ -172,23 +191,24 @@ class ArrayLimits {
|
|
|
172
191
|
}
|
|
173
192
|
std::array<T, K> operator++(int) {
|
|
174
193
|
const auto res = this->state;
|
|
175
|
-
++this;
|
|
194
|
+
++(*this);
|
|
176
195
|
return res;
|
|
177
196
|
}
|
|
178
197
|
std::array<T, K> operator--() {
|
|
179
|
-
for (size_t i = K
|
|
180
|
-
|
|
181
|
-
|
|
198
|
+
for (size_t i = K; i > 0; --i) {
|
|
199
|
+
const size_t idx = i - 1;
|
|
200
|
+
if (this->state[idx] > this->lower_bound[idx]) {
|
|
201
|
+
--this->state[idx];
|
|
182
202
|
break;
|
|
183
203
|
} else {
|
|
184
|
-
this->state[
|
|
204
|
+
this->state[idx] = this->upper_bound[idx] - 1;
|
|
185
205
|
}
|
|
186
206
|
}
|
|
187
207
|
return this->state;
|
|
188
208
|
}
|
|
189
209
|
std::array<T, K> operator--(int) {
|
|
190
210
|
const auto res = this->state;
|
|
191
|
-
--this;
|
|
211
|
+
--(*this);
|
|
192
212
|
return res;
|
|
193
213
|
}
|
|
194
214
|
std::array<T, K> operator*() { return this->state; };
|
|
@@ -214,13 +234,16 @@ class ArrayLimits {
|
|
|
214
234
|
|
|
215
235
|
namespace MSO {
|
|
216
236
|
struct BadInitialization : public std::runtime_error {
|
|
217
|
-
BadInitialization(char const* const message)
|
|
218
|
-
|
|
237
|
+
explicit BadInitialization(char const* const message)
|
|
238
|
+
: std::runtime_error(message) {};
|
|
239
|
+
explicit BadInitialization(const std::string& message)
|
|
219
240
|
: std::runtime_error(message) {};
|
|
220
241
|
};
|
|
221
242
|
struct BadArgumentSize : public std::runtime_error {
|
|
222
|
-
BadArgumentSize(char const* const message)
|
|
223
|
-
|
|
243
|
+
explicit BadArgumentSize(char const* const message)
|
|
244
|
+
: std::runtime_error(message) {};
|
|
245
|
+
explicit BadArgumentSize(const std::string& message)
|
|
246
|
+
: std::runtime_error(message) {};
|
|
224
247
|
};
|
|
225
248
|
|
|
226
249
|
template <typename T, typename M = double, size_t N = 3>
|
|
@@ -255,8 +278,8 @@ class MSO {
|
|
|
255
278
|
|
|
256
279
|
void set_use_background(bool val) { this->use_background = val; }
|
|
257
280
|
|
|
258
|
-
void set_components_num(T
|
|
259
|
-
this->components_num =
|
|
281
|
+
void set_components_num(T components_num_) {
|
|
282
|
+
this->components_num = components_num_;
|
|
260
283
|
}
|
|
261
284
|
|
|
262
285
|
void erase_data() {
|
|
@@ -265,18 +288,20 @@ class MSO {
|
|
|
265
288
|
this->size.fill(0);
|
|
266
289
|
}
|
|
267
290
|
|
|
268
|
-
inline size_t get_length() const {
|
|
291
|
+
[[nodiscard]] inline size_t get_length() const {
|
|
292
|
+
return calculate_area_size(this->size);
|
|
293
|
+
}
|
|
269
294
|
|
|
270
295
|
inline std::array<size_t, ndim> dimension_size() const {
|
|
271
296
|
return calculate_dimension_size(this->size);
|
|
272
297
|
}
|
|
273
298
|
|
|
274
299
|
template <typename W>
|
|
275
|
-
void set_data(T*
|
|
276
|
-
this->components =
|
|
300
|
+
void set_data(T* components_, W size_) {
|
|
301
|
+
this->components = components_;
|
|
277
302
|
for (size_t i = 0; i < ndim; i++) {
|
|
278
|
-
this->size[i] =
|
|
279
|
-
this->upper_bound[i] =
|
|
303
|
+
this->size[i] = size_[i];
|
|
304
|
+
this->upper_bound[i] = size_[i];
|
|
280
305
|
this->lower_bound[i] = 0;
|
|
281
306
|
}
|
|
282
307
|
if (this->get_length() != this->mu_array.size()) this->mu_array.clear();
|
|
@@ -284,10 +309,15 @@ class MSO {
|
|
|
284
309
|
}
|
|
285
310
|
|
|
286
311
|
template <typename W>
|
|
287
|
-
void set_bounding_box(W
|
|
312
|
+
void set_bounding_box(W lower_bound_, W upper_bound_) {
|
|
288
313
|
for (size_t i = 0; i < ndim; i++) {
|
|
289
|
-
|
|
290
|
-
|
|
314
|
+
if (lower_bound_[i] > upper_bound_[i])
|
|
315
|
+
throw std::runtime_error(
|
|
316
|
+
"In index " + std::to_string(i) + "the lower bound " +
|
|
317
|
+
std::to_string(lower_bound_[i]) + " is greater than upper bound " +
|
|
318
|
+
std::to_string(upper_bound_[i]));
|
|
319
|
+
this->lower_bound[i] = lower_bound_[i];
|
|
320
|
+
this->upper_bound[i] = upper_bound_[i];
|
|
291
321
|
}
|
|
292
322
|
}
|
|
293
323
|
|
|
@@ -320,22 +350,22 @@ class MSO {
|
|
|
320
350
|
this->steps = 0;
|
|
321
351
|
}
|
|
322
352
|
|
|
323
|
-
void set_neighbourhood(std::vector<int8_t
|
|
324
|
-
std::vector<mu_type>
|
|
325
|
-
if (
|
|
326
|
-
throw std::length_error(
|
|
327
|
-
|
|
353
|
+
void set_neighbourhood(const std::vector<int8_t>& neighbourhood_,
|
|
354
|
+
std::vector<mu_type> distances_) {
|
|
355
|
+
if (neighbourhood_.size() != ndim * distances_.size()) {
|
|
356
|
+
throw std::length_error("Size of neighbourhood need to be " +
|
|
357
|
+
std::to_string(ndim) + "* Size of distances");
|
|
328
358
|
}
|
|
329
|
-
this->neighbourhood =
|
|
330
|
-
this->distances =
|
|
359
|
+
this->neighbourhood = neighbourhood_;
|
|
360
|
+
this->distances = distances_;
|
|
331
361
|
this->steps = 0;
|
|
332
362
|
}
|
|
333
363
|
|
|
334
|
-
void set_neighbourhood(int8_t*
|
|
364
|
+
void set_neighbourhood(int8_t* neighbourhood_, mu_type* distances_,
|
|
335
365
|
size_t neigh_size) {
|
|
336
366
|
this->neighbourhood =
|
|
337
|
-
std::vector<int8_t>(
|
|
338
|
-
this->distances = std::vector<
|
|
367
|
+
std::vector<int8_t>(neighbourhood_, neighbourhood_ + ndim * neigh_size);
|
|
368
|
+
this->distances = std::vector<mu_type>(distances_, distances_ + neigh_size);
|
|
339
369
|
this->steps = 0;
|
|
340
370
|
}
|
|
341
371
|
|
|
@@ -372,23 +402,23 @@ class MSO {
|
|
|
372
402
|
// "Distances: " << this->distances << std::endl;
|
|
373
403
|
auto bounds =
|
|
374
404
|
ArrayLimits<coord_type, ndim>(this->lower_bound, this->upper_bound);
|
|
375
|
-
for (auto
|
|
376
|
-
position = calculate_position(
|
|
405
|
+
for (auto coord_ : bounds) {
|
|
406
|
+
position = calculate_position(coord_, global_dimension_size);
|
|
377
407
|
array_position =
|
|
378
|
-
calculate_position(
|
|
408
|
+
calculate_position(coord_ - this->lower_bound, dimension_size);
|
|
379
409
|
array[array_position] = std::numeric_limits<mu_type>::max();
|
|
380
410
|
if (this->components[position] == this->background_component) {
|
|
381
|
-
array[
|
|
382
|
-
for (size_t i = 0; i <
|
|
411
|
+
array[array_position] = 0;
|
|
412
|
+
for (size_t i = 0; i < ndim * this->distances.size(); i += ndim) {
|
|
383
413
|
for (size_t j = 0; j < ndim; j++)
|
|
384
|
-
coord2[j] =
|
|
414
|
+
coord2[j] = coord_[j] + this->neighbourhood[i + j];
|
|
385
415
|
if (outside_bounds(coord2, lower_bound, upper_bound)) {
|
|
386
416
|
continue;
|
|
387
417
|
}
|
|
388
418
|
if (components[calculate_position(coord2, global_dimension_size)] ==
|
|
389
419
|
0) {
|
|
390
|
-
queue.push(
|
|
391
|
-
coord_in_queue[calculate_position(
|
|
420
|
+
queue.push(coord_);
|
|
421
|
+
coord_in_queue[calculate_position(coord_, global_dimension_size)] =
|
|
392
422
|
true;
|
|
393
423
|
break;
|
|
394
424
|
}
|
|
@@ -408,7 +438,7 @@ class MSO {
|
|
|
408
438
|
fdt_value = array[array_position];
|
|
409
439
|
for (size_t i = 0; i < this->distances.size(); i++) {
|
|
410
440
|
for (size_t j = 0; j < ndim; j++)
|
|
411
|
-
coord2[j] = coord[j] + this->neighbourhood[
|
|
441
|
+
coord2[j] = coord[j] + this->neighbourhood[ndim * i + j];
|
|
412
442
|
if (outside_bounds(coord2, lower_bound, upper_bound)) continue;
|
|
413
443
|
neigh_position = calculate_position(coord2, global_dimension_size);
|
|
414
444
|
array_neigh_position =
|
|
@@ -429,14 +459,14 @@ class MSO {
|
|
|
429
459
|
// std::cout << "Count " << count << std::endl;
|
|
430
460
|
};
|
|
431
461
|
|
|
432
|
-
size_t optimum_erosion_calculate(const std::vector<mu_type>&
|
|
462
|
+
size_t optimum_erosion_calculate(const std::vector<mu_type>& fdt_array_,
|
|
433
463
|
std::vector<T>& components_arr,
|
|
434
464
|
std::vector<bool>& sprawl_area,
|
|
435
465
|
size_t count_steps_factor = 3) {
|
|
436
466
|
Point coord, coord2;
|
|
437
467
|
size_t position, neigh_position;
|
|
438
468
|
mu_type val, val2;
|
|
439
|
-
std::vector<mu_type> distances_from_components(
|
|
469
|
+
std::vector<mu_type> distances_from_components(fdt_array_.size(), 0);
|
|
440
470
|
std::vector<my_queue<Point>> queues(this->components_num + 1);
|
|
441
471
|
std::vector<bool> coord_in_queue(this->get_length(), false);
|
|
442
472
|
auto bounds =
|
|
@@ -445,17 +475,17 @@ class MSO {
|
|
|
445
475
|
calculate_dimension_size(this->upper_bound - this->lower_bound);
|
|
446
476
|
const size_t area_size = bounds.size();
|
|
447
477
|
|
|
448
|
-
for (auto
|
|
449
|
-
position = calculate_position(
|
|
478
|
+
for (auto coord_ : bounds) {
|
|
479
|
+
position = calculate_position(coord_, dimension_size);
|
|
450
480
|
if (components_arr[position] != 0) {
|
|
451
|
-
distances_from_components[position] =
|
|
452
|
-
for (size_t i = 0; i <
|
|
481
|
+
distances_from_components[position] = fdt_array_[position];
|
|
482
|
+
for (size_t i = 0; i < ndim * this->distances.size(); i += ndim) {
|
|
453
483
|
for (size_t j = 0; j < ndim; j++)
|
|
454
|
-
coord2[j] =
|
|
484
|
+
coord2[j] = coord_[j] + this->neighbourhood[i + j];
|
|
455
485
|
if (outside_bounds(coord2, lower_bound, upper_bound)) continue;
|
|
456
486
|
if (sprawl_area[calculate_position(coord2, dimension_size)] == true) {
|
|
457
|
-
queues[components_arr[position]].push(
|
|
458
|
-
coord_in_queue[calculate_position(
|
|
487
|
+
queues[components_arr[position]].push(coord_);
|
|
488
|
+
coord_in_queue[calculate_position(coord_, dimension_size)] = true;
|
|
459
489
|
break;
|
|
460
490
|
}
|
|
461
491
|
}
|
|
@@ -476,11 +506,11 @@ class MSO {
|
|
|
476
506
|
val = distances_from_components[position];
|
|
477
507
|
for (size_t i = 0; i < this->distances.size(); i++) {
|
|
478
508
|
for (size_t j = 0; j < ndim; j++)
|
|
479
|
-
coord2[j] = coord[j] + this->neighbourhood[
|
|
509
|
+
coord2[j] = coord[j] + this->neighbourhood[ndim * i + j];
|
|
480
510
|
if (outside_bounds(coord2, lower_bound, upper_bound)) continue;
|
|
481
511
|
neigh_position = calculate_position(coord2, dimension_size);
|
|
482
512
|
if (sprawl_area[neigh_position] == false) continue;
|
|
483
|
-
val2 = std::min(val,
|
|
513
|
+
val2 = std::min(val, fdt_array_[neigh_position]);
|
|
484
514
|
if (val2 < distances_from_components[neigh_position] -
|
|
485
515
|
std::numeric_limits<mu_type>::epsilon())
|
|
486
516
|
continue;
|
|
@@ -505,7 +535,7 @@ class MSO {
|
|
|
505
535
|
}
|
|
506
536
|
|
|
507
537
|
if (count_steps > count_steps_factor * area_size) {
|
|
508
|
-
throw std::runtime_error("
|
|
538
|
+
throw std::runtime_error("too many steps: constrained dilation");
|
|
509
539
|
}
|
|
510
540
|
coord_in_queue[position] = false;
|
|
511
541
|
}
|
|
@@ -526,7 +556,7 @@ class MSO {
|
|
|
526
556
|
return count;
|
|
527
557
|
};
|
|
528
558
|
|
|
529
|
-
size_t constrained_dilation(const std::vector<mu_type>&
|
|
559
|
+
size_t constrained_dilation(const std::vector<mu_type>& fdt_array_,
|
|
530
560
|
std::vector<T>& components_arr,
|
|
531
561
|
std::vector<bool>& sprawl_area) const {
|
|
532
562
|
if (this->get_length() == 0) throw BadInitialization("Zero sized array");
|
|
@@ -539,7 +569,7 @@ class MSO {
|
|
|
539
569
|
size_t position, neigh_position, position_global;
|
|
540
570
|
mu_type val, val2, dist_val;
|
|
541
571
|
std::vector<mu_type> distances_from_components(
|
|
542
|
-
|
|
572
|
+
fdt_array_.size(), std::numeric_limits<mu_type>::max());
|
|
543
573
|
std::vector<my_queue<Point>> queues(this->components_num + 1);
|
|
544
574
|
my_queue<Point> queue_copy;
|
|
545
575
|
std::vector<bool> coord_in_queue(this->get_length(), false);
|
|
@@ -554,15 +584,15 @@ class MSO {
|
|
|
554
584
|
const size_t area_size = bounds.size();
|
|
555
585
|
|
|
556
586
|
// Put borders of components to queue
|
|
557
|
-
for (auto
|
|
558
|
-
position = calculate_position(
|
|
587
|
+
for (auto coord_ : bounds) {
|
|
588
|
+
position = calculate_position(coord_, dimension_size);
|
|
559
589
|
if (components_arr[position] != 0) {
|
|
560
|
-
for (size_t i = 0; i <
|
|
590
|
+
for (size_t i = 0; i < ndim * this->distances.size(); i += ndim) {
|
|
561
591
|
for (size_t j = 0; j < ndim; j++)
|
|
562
|
-
coord2[j] =
|
|
592
|
+
coord2[j] = coord_[j] + this->neighbourhood[i + j];
|
|
563
593
|
if (outside_bounds(coord2, lower_bound, upper_bound)) continue;
|
|
564
594
|
if (sprawl_area[calculate_position(coord2, dimension_size)] == true) {
|
|
565
|
-
queues[components_arr[position]].push(
|
|
595
|
+
queues[components_arr[position]].push(coord_);
|
|
566
596
|
distances_from_components[position] =
|
|
567
597
|
0; // this->mu_array[calculate_position(coord +
|
|
568
598
|
// this->lower_bound, global_dimension_size)];
|
|
@@ -586,14 +616,14 @@ class MSO {
|
|
|
586
616
|
coord = queue.front();
|
|
587
617
|
queue.pop();
|
|
588
618
|
position = calculate_position(coord, dimension_size);
|
|
589
|
-
val =
|
|
619
|
+
val = fdt_array_[position];
|
|
590
620
|
for (size_t i = 0; i < this->distances.size(); i++) {
|
|
591
621
|
for (size_t j = 0; j < ndim; j++)
|
|
592
|
-
coord2[j] = coord[j] + this->neighbourhood[
|
|
622
|
+
coord2[j] = coord[j] + this->neighbourhood[ndim * i + j];
|
|
593
623
|
if (outside_bounds(coord2, lower_bound, upper_bound)) continue;
|
|
594
624
|
neigh_position = calculate_position(coord2, dimension_size);
|
|
595
625
|
if (sprawl_area[neigh_position] == false) continue;
|
|
596
|
-
if (
|
|
626
|
+
if (fdt_array_[neigh_position] <= val &&
|
|
597
627
|
morphological_neighbourhood[neigh_position] != comp_num &&
|
|
598
628
|
morphological_neighbourhood[neigh_position] !=
|
|
599
629
|
std::numeric_limits<T>::max()) {
|
|
@@ -619,7 +649,7 @@ class MSO {
|
|
|
619
649
|
// std::cerr << "Coord " << coord << " val " << val << std::endl;
|
|
620
650
|
for (size_t i = 0; i < this->distances.size(); i++) {
|
|
621
651
|
for (size_t j = 0; j < ndim; j++)
|
|
622
|
-
coord2[j] = coord[j] + this->neighbourhood[
|
|
652
|
+
coord2[j] = coord[j] + this->neighbourhood[ndim * i + j];
|
|
623
653
|
if (outside_bounds(coord2, lower_bound, upper_bound)) continue;
|
|
624
654
|
neigh_position = calculate_position(coord2, dimension_size);
|
|
625
655
|
if (sprawl_area[neigh_position] == false ||
|
|
@@ -631,7 +661,7 @@ class MSO {
|
|
|
631
661
|
this->distances[i] / 2;
|
|
632
662
|
val2 = dist_val + val2;
|
|
633
663
|
if (val2 + std::numeric_limits<mu_type>::epsilon() >=
|
|
634
|
-
|
|
664
|
+
fdt_array_[neigh_position]) {
|
|
635
665
|
// std::cerr << " coord(fdt) " << coord2 << " " << val2 << " - "
|
|
636
666
|
// << fdt_array[neigh_position] << std::endl;
|
|
637
667
|
continue;
|
|
@@ -642,14 +672,14 @@ class MSO {
|
|
|
642
672
|
// << distances_from_components[neigh_position] << std::endl;
|
|
643
673
|
continue;
|
|
644
674
|
}
|
|
645
|
-
if (fabs(val2 -
|
|
675
|
+
if (fabs(val2 - fdt_array_[neigh_position]) <
|
|
646
676
|
std::numeric_limits<mu_type>::epsilon()) {
|
|
647
677
|
if (components_arr[neigh_position] == std::numeric_limits<T>::max())
|
|
648
678
|
continue;
|
|
649
679
|
else
|
|
650
680
|
components_arr[neigh_position] = std::numeric_limits<T>::max();
|
|
651
681
|
}
|
|
652
|
-
if (val2 <
|
|
682
|
+
if (val2 < fdt_array_[neigh_position]) {
|
|
653
683
|
components_arr[neigh_position] = components_arr[position];
|
|
654
684
|
distances_from_components[neigh_position] = val2;
|
|
655
685
|
}
|
|
@@ -659,8 +689,8 @@ class MSO {
|
|
|
659
689
|
coord_in_queue[neigh_position] = true;
|
|
660
690
|
}
|
|
661
691
|
}
|
|
662
|
-
if (count_steps >
|
|
663
|
-
throw std::runtime_error("
|
|
692
|
+
if (count_steps > ndim * area_size) {
|
|
693
|
+
throw std::runtime_error("too many steps: constrained dilation");
|
|
664
694
|
}
|
|
665
695
|
|
|
666
696
|
coord_in_queue[position] = false;
|
|
@@ -671,7 +701,7 @@ class MSO {
|
|
|
671
701
|
// std::endl; std::cerr << " component change " << count3 << " ";
|
|
672
702
|
// std::cerr << "Queue1 " << queue.get_size() << " Queue2 " <<
|
|
673
703
|
// queue_copy.get_size() << std::endl;
|
|
674
|
-
comp_num
|
|
704
|
+
++comp_num;
|
|
675
705
|
}
|
|
676
706
|
size_t count = 0;
|
|
677
707
|
for (auto& el : components_arr) {
|
|
@@ -732,7 +762,7 @@ class MSO {
|
|
|
732
762
|
|
|
733
763
|
size_t run_MSO(size_t steps_limits = 1, size_t count_steps_factor = 3) {
|
|
734
764
|
if (this->components_num == 0)
|
|
735
|
-
throw BadInitialization("Wrong number of components
|
|
765
|
+
throw BadInitialization("Wrong number of components set");
|
|
736
766
|
size_t total_changes = 0;
|
|
737
767
|
if (steps_limits == 0) steps_limits = 1;
|
|
738
768
|
if (steps_limits < this->steps) this->steps = 0;
|
|
@@ -756,16 +786,16 @@ class MSO {
|
|
|
756
786
|
this->fdt_array, this->res_components_array, this->sprawl_area_array);
|
|
757
787
|
total_changes += count_changes;
|
|
758
788
|
// std::cerr << "loop3\n";
|
|
759
|
-
this->steps
|
|
789
|
+
++this->steps;
|
|
760
790
|
}
|
|
761
791
|
// std::cerr << "end\n";
|
|
762
792
|
if (count_changes == 0) {
|
|
763
|
-
this->steps
|
|
793
|
+
--this->steps;
|
|
764
794
|
}
|
|
765
795
|
return total_changes;
|
|
766
796
|
}
|
|
767
797
|
|
|
768
|
-
size_t steps_done() { return this->steps; }
|
|
798
|
+
[[nodiscard]] size_t steps_done() const { return this->steps; }
|
|
769
799
|
|
|
770
800
|
std::vector<T> get_result_catted() const {
|
|
771
801
|
return this->res_components_array;
|
|
@@ -790,7 +820,7 @@ class MuCalc {
|
|
|
790
820
|
std::vector<R> result(length, 0);
|
|
791
821
|
R mu;
|
|
792
822
|
for (size_t i = 0; i < length; i++) {
|
|
793
|
-
mu =
|
|
823
|
+
mu = static_cast<R>(array[i] - lower_bound) / (upper_bound - lower_bound);
|
|
794
824
|
shrink(mu);
|
|
795
825
|
result[i] = mu;
|
|
796
826
|
}
|
|
@@ -803,7 +833,7 @@ class MuCalc {
|
|
|
803
833
|
std::vector<R> result(length, 0);
|
|
804
834
|
R mu;
|
|
805
835
|
for (size_t i = 0; i < length; i++) {
|
|
806
|
-
mu =
|
|
836
|
+
mu = static_cast<R>(array[i] - lower_bound) / (upper_bound - lower_bound);
|
|
807
837
|
shrink(mu);
|
|
808
838
|
if (mu < 0.5) mu = 1 - mu;
|
|
809
839
|
result[i] = mu;
|
|
@@ -820,13 +850,16 @@ class MuCalc {
|
|
|
820
850
|
T pixel_val;
|
|
821
851
|
for (size_t i = 0; i < length; i++) {
|
|
822
852
|
pixel_val = array[i];
|
|
823
|
-
mu =
|
|
853
|
+
mu =
|
|
854
|
+
static_cast<R>(pixel_val - lower_bound) / (upper_bound - lower_bound);
|
|
824
855
|
if (((lower_bound - lower_mid_bound) > 0) &&
|
|
825
856
|
(pixel_val >= lower_mid_bound) && (pixel_val <= lower_bound))
|
|
826
|
-
mu =
|
|
857
|
+
mu = static_cast<R>(pixel_val - lower_mid_bound) /
|
|
858
|
+
(lower_bound - lower_mid_bound);
|
|
827
859
|
else if (((upper_bound - lower_bound) > 0) && (lower_bound < pixel_val) &&
|
|
828
860
|
(pixel_val <= upper_bound))
|
|
829
|
-
mu =
|
|
861
|
+
mu = static_cast<R>(upper_bound - pixel_val) /
|
|
862
|
+
(upper_bound - lower_bound);
|
|
830
863
|
shrink(mu);
|
|
831
864
|
result[i] = mu;
|
|
832
865
|
}
|
|
@@ -835,12 +868,12 @@ class MuCalc {
|
|
|
835
868
|
|
|
836
869
|
static std::vector<R> calculate_mu_array_masked(T* array, size_t length,
|
|
837
870
|
T lower_bound, T upper_bound,
|
|
838
|
-
uint8_t* mask) {
|
|
871
|
+
const uint8_t* mask) {
|
|
839
872
|
std::vector<R> result(length, 0);
|
|
840
873
|
R mu;
|
|
841
874
|
for (size_t i = 0; i < length; i++) {
|
|
842
875
|
if (mask[i] == 0) continue;
|
|
843
|
-
mu =
|
|
876
|
+
mu = static_cast<R>(array[i] - lower_bound) / (upper_bound - lower_bound);
|
|
844
877
|
shrink(mu);
|
|
845
878
|
result[i] = mu;
|
|
846
879
|
}
|
|
@@ -848,12 +881,13 @@ class MuCalc {
|
|
|
848
881
|
}
|
|
849
882
|
|
|
850
883
|
static std::vector<R> calculate_reflection_mu_array_masked(
|
|
851
|
-
T* array, size_t length, T lower_bound, T upper_bound,
|
|
884
|
+
T* array, size_t length, T lower_bound, T upper_bound,
|
|
885
|
+
const uint8_t* mask) {
|
|
852
886
|
std::vector<R> result(length, 0);
|
|
853
887
|
R mu;
|
|
854
888
|
for (size_t i = 0; i < length; i++) {
|
|
855
889
|
if (mask[i] == 0) continue;
|
|
856
|
-
mu =
|
|
890
|
+
mu = static_cast<R>(array[i] - lower_bound) / (upper_bound - lower_bound);
|
|
857
891
|
shrink(mu);
|
|
858
892
|
if (mu < 0.5) mu = 1 - mu;
|
|
859
893
|
result[i] = mu;
|
|
@@ -862,20 +896,23 @@ class MuCalc {
|
|
|
862
896
|
}
|
|
863
897
|
static std::vector<R> calculate_two_object_mu_masked(
|
|
864
898
|
T* array, size_t length, T lower_bound, T upper_bound, T lower_mid_bound,
|
|
865
|
-
T upper_mid_bound, uint8_t* mask) {
|
|
899
|
+
T upper_mid_bound, const uint8_t* mask) {
|
|
866
900
|
std::vector<R> result(length, 0);
|
|
867
901
|
R mu;
|
|
868
902
|
T pixel_val;
|
|
869
903
|
for (size_t i = 0; i < length; i++) {
|
|
870
904
|
if (mask[i] == 0) continue;
|
|
871
905
|
pixel_val = array[i];
|
|
872
|
-
mu =
|
|
906
|
+
mu =
|
|
907
|
+
static_cast<R>(pixel_val - lower_bound) / (upper_bound - lower_bound);
|
|
873
908
|
if (((lower_bound - lower_mid_bound) > 0) &&
|
|
874
909
|
(pixel_val >= lower_mid_bound) && (pixel_val <= lower_bound))
|
|
875
|
-
mu =
|
|
910
|
+
mu = static_cast<R>(pixel_val - lower_mid_bound) /
|
|
911
|
+
(lower_bound - lower_mid_bound);
|
|
876
912
|
else if (((upper_bound - lower_bound) > 0) && (lower_bound < pixel_val) &&
|
|
877
913
|
(pixel_val <= upper_bound))
|
|
878
|
-
mu =
|
|
914
|
+
mu = static_cast<R>(upper_bound - pixel_val) /
|
|
915
|
+
(upper_bound - lower_bound);
|
|
879
916
|
shrink(mu);
|
|
880
917
|
result[i] = mu;
|
|
881
918
|
}
|
|
@@ -883,3 +920,5 @@ class MuCalc {
|
|
|
883
920
|
}
|
|
884
921
|
};
|
|
885
922
|
} // namespace MSO
|
|
923
|
+
|
|
924
|
+
#endif
|