Ask Your Question

Kert's profile - activity

2014-01-12 15:04:41 -0600 commented question Depth reduction algorithm

found it already...thanks anyways :)

2014-01-12 14:46:50 -0600 received badge  Editor (source)
2014-01-12 14:46:11 -0600 asked a question 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?