Hey all,
I am trying to scan an image using the efficient C-style pointer access. For every pixel of a 16-bit unsigned image, i look at its right and bottom neighbor and perform some operations if they are not the same. The problem appears when the pixel is at the border of the image because the neighbor to its right l[j+1]
is the first pixel of the next row.
http://docs.opencv.org/2.4/doc/tutorials/core/how_to_scan_images/how_to_scan_images.html#the-efficient-way
Is there a solution for this ?
int n_rows = label.rows;
int n_cols = label.cols;
for (int i = 0; i < 1; ++i)
{
ushort* l = label.ptr<ushort>(i);
cv::Vec3b* c = color.ptr<cv::Vec3b>(i);
for (int j = 0; j < n_cols * n_rows; ++j)
{
//labels
int mid = l[j],
right = l[j + 1],
bottom = l[j + n_cols];
//do something if (mid label != right label_ || (mid label != bottom label)
if(mid != right) //do something
if(mid != bottom) //do something
}
}