vigra icon indicating copy to clipboard operation
vigra copied to clipboard

In skeletonizeImage(), squared_distance is not a matrix, producing a segfault

Open shardator opened this issue 7 years ago • 1 comments

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?

shardator avatar Mar 23 '18 15:03 shardator

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());

shardator avatar Mar 23 '18 15:03 shardator