Ask Your Question
0

how to efficiently scan matrix this way ?

asked 2017-03-28 06:27:05 -0600

Nbb gravatar image

updated 2017-03-28 06:37:45 -0600

For each point, I scan the right and bottom all the way down, then I move diagonally and continue. It is extremely difficult to do this with pointer access. I was wondering if anyone has any suggestion.

//diagonal scan
for (int i = 0; i < n_cols * n_rows * n_channels; i = i + n_rows*n_channels + 1)
{
    //pointer to color mat (cv::Vec3b)
    uchar*p = color.ptr<uchar>(i / 3);
    //pointer to label mat (int)
    int* l = label.ptr<int>(i / 3);

    cout << l[0] << " "; cin.get();

    ////right scan
    //for (int j = 0; j < n_cols - i; j++)
    //{

    //}

    ////bottom scan
    //for (int j = 0; j < n_rows - i; j++)
    //{

    //}
}

image description

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2017-03-28 07:22:15 -0600

LBerger gravatar image

updated 2017-03-28 09:14:09 -0600

I think you need to understand previous answer and it is not difficult to do it with pointer access. I haven't test following lines (Mat i must be continuous):

int i,j;
uchar* p;
for( i = 0; i < nRows; ++i)
{
    p = I.ptr<uchar>(i)+i;
    for ( j = i; j < nCols; ++j,p++)
    {
        *p = table[*p];
    }
}

int i,j;
uchar* p;
for( i = 0; i < nCols; ++i)
{
    p = I.ptr<uchar>(i)+i+1;
    for ( j = i+1; j < nRows; ++j,p+=nCols)
    {
        *p = table[*p];
    }
}


int i,j;
uchar* p=I.ptr<uchar>(i);
for( i = 0; i < min(nCols,nRows); ++i,p+=nCols+1)
{
        *p = table[*p];
}
edit flag offensive delete link more

Comments

Thanks ! It was a little bit confusing but I get the idea now

Nbb gravatar imageNbb ( 2017-03-28 23:52:22 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-03-28 06:27:05 -0600

Seen: 317 times

Last updated: Mar 28 '17