// 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 版權聲明:本文爲博主原創文章,轉載請附上博文連接!
原圖html
處理後的圖片:ios
==============================================================================c++
https://wenku.baidu.com/view/9056aa45c4da50e2524de518964bcf84b9d52d0d.html算法
===========================================================================函數
圖像處理工具
https://www.codeproject.com/Articles/66341/A-Simple-Yet-Quite-Powerful-Palette-Quantizer-in-Cui
基於偏差擴散算法的半色調色彩抖動處理程序spa
http://bbs.bccn.net/thread-480344-1-1.html.net