Ask Your Question
0

SparseMat constructed from Mat also storing zero values

asked 2013-04-02 03:35:40 -0500

I'm trying to store detected edge points of canny filter algorithm in a sparse matrix ( SparseMat ). This should make it easy to iterate through the detected edge points.
But if I construct the sparse matrix from the edge map ( Mat ) it contains as much elements as specified by width and height of the image (see code below).
So it's also storing the zero elements of the edge map. In my understanding a sparse matrix is intended to only store non zero values and the edge map contains zero values to a high extent, that should not be stored.
What am I missing? Do I construct the SparseMat in the correct way?

Regards Knight123

Mat input, tmp;
input = imread("./test.png", CV_LOAD_IMAGE_GRAYSCALE);

Canny(input, tmp, 35, 70);

SparseMat edgePoints(tmp);

edgePoints.nzcount(); // returns 360960 = width x height
countNonZero(tmp); // returns 7878
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2013-04-02 03:53:32 -0500

I guess the explanation says it all:

Sparse means that only non-zero elements are stored (though, as a result of operations on a sparse matrix, some of its stored elements can actually become 0. It is up to you to detect such elements and delete them using SparseMat::erase ).

Loop over the sparsematrix and delete the zeros manually before proceeding?

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

Stats

Asked: 2013-04-02 03:35:40 -0500

Seen: 285 times

Last updated: Apr 02 '13