Smorodov 579 Жалоба Опубликовано July 21, 2012 Часто применяется в печати. Делается очень просто: #include <iostream> #include <vector> #include <stdio.h> #include <stdarg.h> #include "opencv2/core/core.hpp" #include "opencv2/highgui/highgui.hpp" #include "opencv2/imgproc/imgproc.hpp" #include "fstream" #include "iostream" using namespace std; using namespace cv; //----------------------------------------------------------------------------------------------------- // //----------------------------------------------------------------------------------------------------- int main( int argc, char** argv ) { // Это "магический квадрат" 6х6 взят из graphics gems II unsigned char f[]={15,7,13,31,20,28, 9,1,5,21,36,25, 17,3,11,29,24,34, 32,19,27,16,8,14, 22,35,26,10,2,6, 30,23,33,18,4,12}; Mat F(6,6,CV_8UC1,f); namedWindow("Res"); Mat res=imread("C:\\ImagesForTest\\mandril.jpg",0); for(int i=0;i<res.rows-6;i+=6) { for(int j=0;j<res.cols-6;j+=6) { res(Range(i,i+6),Range(j,j+6))=res(Range(i,i+6),Range(j,j+6))>(F*8); } } imshow("Res",res); waitKey(0); return 0; } [/code] Halftoning.cpp Еще интересные документы по теме здесь: http://people.scs.carleton.ca/~hli1/ Поделиться сообщением Ссылка на сообщение Поделиться на других сайтах
mrgloom 242 Жалоба Опубликовано July 23, 2012 кстати убирать эти точечки вроде можно с помощью фильтрации в частотной области, т.е. при сканировании газет их вроде убирают. Поделиться сообщением Ссылка на сообщение Поделиться на других сайтах
Smorodov 579 Жалоба Опубликовано September 7, 2012 Еще один метод (error-diffusion (Флойд-Стинберг)): http://en.wikipedia.org/wiki/Floyd%E2%80%93Steinberg_dithering http://www.2038bug.com/ptrans/ptrans.html Для выбора варианта надо раскомментировать нужную часть, и закомментировать остальные. Вариант 1: Вариант 2: Вариант 3: #include <iostream> #include <vector> #include <stdio.h> #include <stdarg.h> #include "opencv2/core/core.hpp" #include "opencv2/highgui/highgui.hpp" #include "opencv2/imgproc/imgproc.hpp" #include "fstream" #include "iostream" using namespace std; using namespace cv; //----------------------------------------------------------------------------------------------------- // //----------------------------------------------------------------------------------------------------- int main( int argc, char** argv ) { namedWindow("Res"); Mat img=imread("D:\\ImagesForTest\\lena.jpg",0); Mat res=Mat::zeros(img.rows,img.cols,CV_8UC1); img.convertTo(img,CV_32FC1); for(int i=3;i<img.rows-3;i++) { for(int j=3;j<img.cols-3;j++) { if(img.at<float>(i,j)<=128) { res.at<unsigned char>(i,j)=0; }else { res.at<unsigned char>(i,j)=255; } float err=img.at<float>(i,j)-(float)res.at<unsigned char>(i,j); // Вариант 1 /* img.at<float>(i,j+1)+=err*7/16; img.at<float>(i+1,j)+=err*3/16; img.at<float>(i+1,j)+=err*5/16; img.at<float>(i+1,j+1)+=err*1/16; */ // Вариант 2 /* img.at<float>(i,j+1)+=err*5/32; img.at<float>(i,j+2)+=err*3/32; img.at<float>(i+1,j)+=err*5/32; img.at<float>(i+2,j)+=err*3/32; img.at<float>(i+1,j+1)+=err*4/32; img.at<float>(i+1,j+2)+=err*2/32; img.at<float>(i+2,j+1)+=err*2/32; img.at<float>(i+1,j-2)+=err*2/32; img.at<float>(i+1,j-1)+=err*4/32; img.at<float>(i+2,j-1)+=err*2/32; */ // Вариант 3 img.at<float>(i,j+2)+=err*32/200; img.at<float>(i+2,j)+=err*26/200; img.at<float>(i+1,j+1)+=err*30/200; img.at<float>(i+1,j+3)+=err*16/200; img.at<float>(i+2,j+2)+=err*12/200; img.at<float>(i+3,j+1)+=err*12/200; img.at<float>(i+3,j+3)+=err*5/200; img.at<float>(i+1,j-3)+=err*12/200; img.at<float>(i+1,j-1)+=err*26/200; img.at<float>(i+2,j-2)+=err*12/200; img.at<float>(i+3,j-3)+=err*5/200; img.at<float>(i+3,j-1)+=err*12/200; } } imshow("Res",res); waitKey(0); return 0; } [/code] Поделиться сообщением Ссылка на сообщение Поделиться на других сайтах