Ask Your Question
0

Depth reduction algorithm

asked 2014-01-12 14:46:11 -0600

Kert gravatar image

updated 2014-01-12 14:46:50 -0600

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?

edit retag flag offensive close merge delete

Comments

1

because you confused input and output here:

uchar *out_data = input.ptr<uchar>(i); // 'input' should be 'output'

berak gravatar imageberak ( 2014-01-12 14:57:11 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2014-01-12 15:04:41 -0600

Kert gravatar image

found it already...thanks anyways :)

edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-01-12 14:46:11 -0600

Seen: 184 times

Last updated: Jan 13 '14