zoukankan      html  css  js  c++  java
  • 半色调 二值化 条码打印 针式打印

    • 利用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

  • 相关阅读:
    Golang的标准命令简述
    Golang的环境安装
    初识Golang编程语言
    基于Ambari的WebUI部署Hive服务
    基于Ambari Server部署HDP集群实战案例
    HBase shell常用命令总结
    HBase完全分布式集群搭建
    HBase工作原理概述
    面向对象-接口(interface)实战案例
    myBatis 简介
  • 原文地址:https://www.cnblogs.com/mingjing/p/10404895.html
Copyright © 2011-2022 走看看