vigra
vigra copied to clipboard
In skeletonizeImage(), squared_distance is not a matrix, producing a segfault
Hi,
In skeleton.hxx:
squared_distance = squaredNorm(vectors);
which is incorrect, as squaredNorm() returns a long (checked). When below the "matrix" is indexed, a seqfault it emitted, since it is an empty matrix.
Could you please take a look into this?
Definitely. The fix is:
diff --git a/include/vigra/skeleton.hxx b/include/vigra/skeleton.hxx
index dd88334..278b2ac 100644
--- a/include/vigra/skeleton.hxx
+++ b/include/vigra/skeleton.hxx
@@ -413,7 +413,7 @@ skeletonizeImageImpl(MultiArrayView<2, T1, S1> const & labels,
vigra_precondition(labels.shape() == dest.shape(),
"skeleton(): shape mismatch between input and output.");
- MultiArray<N, MultiArrayIndex> squared_distance;
+ MultiArray<N, MultiArrayIndex> squared_distance(labels.width(), labels.height());
dest = 0;
T1 maxLabel = 0;
// find skeleton points
@@ -422,7 +422,13 @@ skeletonizeImageImpl(MultiArrayView<2, T1, S1> const & labels,
MultiArray<N, Shape> vectors(labels.shape());
boundaryVectorDistance(labels, vectors, false, OuterBoundary);
- squared_distance = squaredNorm(vectors);
+ for (int sdi = 0; sdi < squared_distance.size(); ++sdi) {
+ squared_distance[sdi] = squaredNorm(vectors[sdi]);
+ }
+
+ using namespace std;
+ cout << "DEBUG: vectors: w:" << vectors.width() << "," << vectors.height() << endl;
+ cout << "DEBUG: squared_distance: w:" << squared_distance.width() << "," << squared_distance.height() << endl;
ArrayVector<Node> ends_to_be_checked;
Graph g(labels.shape());