Depth reduction algorithm
Hi!
I'm trying to implement a basic depth reduction algorithm by not editing the input image. Here is the code:
void colorReduceFast( Mat &input, Mat &output, int div=64 ){
int nl = input.rows;
int nc = input.cols * 3;
if( input.isContinuous() ){
nc *= nl;
nl = 1;
}
output.create(input.size(), input.type());
int n = static_cast<int>( log(static_cast<double>(div)) / log(2.0) );
uchar mask = 0xFF << n;
for(int i = 0; i < nl; i++){
uchar *data = input.ptr<uchar>(i);
uchar *out_data = input.ptr<uchar>(i);
for(int j = 0; j < nc; j++){
out_data[j] = (data[j] & mask);
}
}
}
My question is why the input image is edited instead of leaving it untouched?
because you confused input and output here:
uchar *out_data = input.ptr<uchar>(i); // 'input' should be 'output'