明净

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
  • 利用c++的CImg库和用于矩阵处理的Eigen库来实现
  • 编译工具:visual stdio(建议使用,之前我也使用sublime来配置c++的各种库,总是各种bug)

// image2.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include <algorithm>
#include "pch.h"
#include <iostream>
#include "CImg.h"
#include <Eigen3/Eigen/Dense>

using namespace cimg_library;
using namespace std;
using namespace Eigen;
int main()
{
    CImg<int> SrcImg;
    SrcImg.load_bmp("E:/Desktop/picture_process/Lenna/general_img.bmp");
    double r = (double)SrcImg.height() / 272;
    double c = (double)SrcImg.width() / 352;
    double scale = max(r, c);
    if (scale > 1) {
        double s = (double)1.0 / scale;
        SrcImg.resize(s*SrcImg.height(), s*SrcImg.width(),1,1,5);
    }
    MatrixXd m(3*SrcImg.height(), 3*SrcImg.width());
    MatrixXd dot_mat[10];
    for (int i = 0; i < 10; i++) {
        dot_mat[i] = MatrixXd::Zero(3, 3);
    }
    dot_mat[1] << 0, 255, 0,
        0, 0, 0,
        0, 0, 0;
    dot_mat[2] << 0, 255, 0,
        0, 0, 0,
        0, 0, 255;
    dot_mat[3] << 255, 255, 0,
        0, 0, 0,
        0, 0, 255;
    dot_mat[4] << 255, 255, 0,
        0, 0, 0,
        255, 0, 255;
    dot_mat[5] << 255, 255, 255,
        0, 0, 0,
        255, 0, 255;
    dot_mat[6] << 255, 255, 255,
        0, 0, 255,
        255, 0, 255;
    dot_mat[7] << 255, 255, 255,
        0, 0, 255,
        255, 255, 255;
    dot_mat[8] << 255, 255, 255,
        255, 0, 255,
        255, 255, 255;
    dot_mat[9] << 255, 255, 255,
        255, 255, 255,
        255, 255, 255;

    cimg_forXY(SrcImg, x, y) {
        SrcImg(x, y) = (int)(SrcImg(x, y) / 25.6);
    }
    //cout << SrcImg(0, 0, 0) << endl;
    for (int i = 0; i < SrcImg.height(); i++) {
        for (int j = 0; j < SrcImg.width(); j++) {
            int level = SrcImg(i, j, 0);
            m.block<3,3>(i*3,j*3) <<  dot_mat[level];
        }
    }
    CImg<int> tmp(m.rows(), m.cols(), 1, 1);
    cimg_forXY(tmp, x, y) {
        tmp(x, y) = m(x, y);
    }
    tmp.display();
    return 0;
}

--------------------- 
作者:perry0528 
来源:CSDN 
原文:https://blog.csdn.net/perry0528/article/details/82854322 
版权声明:本文为博主原创文章,转载请附上博文链接!

原图

处理后的图片:

 

 

==============================================================================

半色调打印技术实验报告

https://wenku.baidu.com/view/9056aa45c4da50e2524de518964bcf84b9d52d0d.html

===========================================================================

图像处理

https://www.codeproject.com/Articles/66341/A-Simple-Yet-Quite-Powerful-Palette-Quantizer-in-C

基于误差扩散算法的半色调色彩抖动处理程序

http://bbs.bccn.net/thread-480344-1-1.html

 

posted on 2019-02-20 10:03  明净  阅读(498)  评论(0编辑  收藏  举报