Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

index matrix

Hi,

In my code I need create a matrix filled with all the coordinates of an image Mat.

ex.for a 1024x768 image: [ 0, 0] [ 0, 1] [ 0, 2] . . . [1024, 768]

Is there a more efficient way of doing this then:

void indexMatrix(Mat &matrix, int height, int width){

int cols = height*width;
int index = 0;

matrix = Mat::ones(cols, 2, CV_8UC1);

for( int col = 0; col < width; ++col ) {
    for (int row = 0; row < height; ++row) {
        matrix.at<uchar>(index,0) = col;
        matrix.at<uchar>(index,1) = row;

        index++;
    }
}

index matrix

Hi,

In my code I need to create a matrix filled with all the possible pixel coordinates of an image Mat. ( Mat ).

ex.for a 1024x768 image: [ 0, 0] [ 0, 1] [ 0, 2] . . . [1024, 768]

Is there a more efficient way of doing this then: than:

void indexMatrix(Mat &matrix, int height, int width){

int cols = height*width;
int index = 0;

matrix = Mat::ones(cols, 2, CV_8UC1);

for( int col = 0; col < width; ++col ) {
    for (int row = 0; row < height; ++row) {
        matrix.at<uchar>(index,0) = col;
        matrix.at<uchar>(index,1) = row;

        index++;
    }
}