colorReduce1(const cv::Mat &image, cv::Mat &imageOut,int div=64)


using namespace cv;

void colorReduce0(cv::Mat image, int div=64) {

 int nl= image.rows; // number of lines
 int nc= image.cols * image.channels(); // total number of elements per line

 for (int j=0; j<nl; j++) {

  // get the address of row j
  uchar* data= image.ptr<uchar>(j);

  for (int i=0; i<nc; i++) {

   // process each pixel ---------------------

   data[i]= data[i]/div*div + div/2;

   // end of pixel processing ----------------

  } // end of line
 }
}


void colorReduce1(const cv::Mat &image, cv::Mat &imageOut,int div=64) {

 int nl= image.rows; // number of lines
 int nc= image.cols * image.channels(); // total number of elements per line

 for (int j=0; j<nl; j++) {

  // get the address of row j
  const uchar* data= image.ptr<uchar>(j);
  uchar* dataOut= imageOut.ptr<uchar>(j);

  for (int i=0; i<nc; i++) {

   // process each pixel ---------------------

   dataOut[i]= data[i]/div*div + div/2;

   // end of pixel processing ----------------

  } // end of line
 }
}


int main(int argc, char** argv)
{
 

    Mat img1 = imread("lena.jpg");
 Mat img2=img1.clone();
    //Mat img2 = imread(argv[2], CV_LOAD_IMAGE_GRAYSCALE);
    if(img1.empty() )
    {
        printf("Can't read one of the images\n");
        return -1;
    }
 imshow("org", img1);
 waitKey(0);
 cv::Mat imageOut(img1.rows,img1.cols,img1.type());
 colorReduce1(img1,imageOut ,64);
 imshow("imageOut", imageOut);
 waitKey(0);
 colorReduce0(img1, 128);
 // drawing the results
 imshow("reduce128", img1);

  colorReduce0(img2, 64);
    // drawing the results
    imshow("reduce64", img2);
    waitKey(0);

    return 0;
}



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值