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?