In fact, yes. You can avoid calling Mat::ptr
when writing data into the dst
image:
...
for(int i=1; i<src.rows-1; i++) {
unsigned char *dst_row = dst.ptr<unsigned char>(i-1); << THIS CAN BE AVOIDED
...
You can simply initialize a pointer to the data buffer in dst
after creating it and then filling it without calling ptr
, i.e.:
dst = Mat::zeros(src.rows-2, src.cols-2, CV_8UC1);
unsigned char *dst_data = dst.data;
int pix_ctr = 0;
// .. and then, inside the `for` loop, after calculating the LBP code.
dst_data[pix_ctr++] = code;
This is possible only if the data stored in dst
is contiguous (in this case you know it because you just initialized it by calling to Mat::zeros
). You can check it by calling dst.isContinuous()
.
(In fact, you could get rid of all the Mat::ptr
inside the loop if the input data in src
is contiguous. In that case, advance your pixel pointers without ptr
by using the image dimensions).