├── data ├── lena.bmp └── NADD2013 │ ├── ct256.map │ └── ct512.map ├── lib ├── x64 │ └── vc10 │ │ ├── pixkit_cv052.lib │ │ ├── pixkit_cv052d.lib │ │ ├── pixkit_file052.lib │ │ ├── pixkit_ml052.lib │ │ ├── pixkit_ml052d.lib │ │ ├── pixkit_file052d.lib │ │ ├── pixkit_image052.lib │ │ ├── pixkit_image052d.lib │ │ ├── pixkit_timer052.lib │ │ └── pixkit_timer052d.lib └── x86 │ └── vc10 │ ├── pixkit_cv052.lib │ ├── pixkit_cv052d.lib │ ├── pixkit_file052.lib │ ├── pixkit_ml052.lib │ ├── pixkit_ml052d.lib │ ├── pixkit_file052d.lib │ ├── pixkit_image052.lib │ ├── pixkit_image052d.lib │ ├── pixkit_timer052.lib │ └── pixkit_timer052d.lib ├── modules ├── pixkit-image │ ├── src │ │ ├── comp.cpp │ │ ├── attack.cpp │ │ ├── filtering.cpp │ │ ├── halftoning.cpp │ │ ├── edgedetection.cpp │ │ ├── MSRCR1997 │ │ │ └── retinex.cpp │ │ ├── CelikTjahjadi2012 │ │ │ └── CelikTjahjadi2012.cpp │ │ ├── multitoning │ │ │ └── DMS2012 │ │ │ │ └── ChanduStanichWuTrager2014.cpp │ │ ├── qualityassessment │ │ │ ├── IW_PSNR.cpp │ │ │ └── IW_SSIM.cpp │ │ ├── halftoning │ │ │ ├── CVT │ │ │ │ └── cvt.hpp │ │ │ └── LiuGuo2015 │ │ │ │ └── LiuGuo2015.cpp │ │ ├── LAT2011 │ │ │ └── LAT2011.cpp │ │ ├── MSRCP2014 │ │ │ └── MSRCP2014.cpp │ │ ├── MS_SSIM │ │ │ └── MS_SSIM.cpp │ │ ├── enhancement │ │ │ ├── WangZhengHuLi2013 │ │ │ │ └── WangZhengHuLi2013.cpp │ │ │ └── NRCIR2009 │ │ │ │ └── NRCIR2009.cpp │ │ ├── comp │ │ │ └── YangTsai1998.cpp │ │ ├── POHE2013 │ │ │ └── pohe.cpp │ │ └── DBSBTC2011 │ │ │ └── DBSBTC2011.cpp │ ├── test │ │ ├── prog.vcxproj.filters │ │ ├── prog.sln │ │ ├── test_halftoning.cpp │ │ └── prog.vcxproj │ └── readme.md ├── pixkit-cv │ ├── src │ │ ├── labeling.cpp │ │ └── detection.cpp │ └── include │ │ └── pixkit-cv.hpp ├── pixkit-file │ ├── include │ │ └── pixkit-file.hpp │ └── src │ │ └── pixkit-file.cpp ├── python │ └── unittest.py ├── pixkit-timer │ ├── include │ │ └── pixkit-timer.hpp │ └── src │ │ └── pixkit-timer.cpp └── pixkit-ml │ ├── src │ ├── mldata.cpp │ ├── KMeans.cpp │ ├── fuzzyCMeans.cpp │ └── KNN.cpp │ └── include │ └── pixkit-ml.hpp ├── examples-image ├── halftoning │ ├── dotdiffusion.NADD2013 │ │ ├── ct256.map │ │ ├── ct512.map │ │ ├── output.bmp │ │ ├── prog.vcxproj.filters │ │ ├── prog.sln │ │ ├── example_dotdiffusion.NADD2013.cpp │ │ └── prog.vcxproj │ └── dotdiffusion.GuoLiu2009 │ │ ├── output.bmp │ │ ├── example_dotdiffusion.GuoLiu2009.cpp │ │ ├── prog.vcxproj.filters │ │ ├── prog.sln │ │ └── prog.vcxproj └── enhancement │ ├── enhancement.MaryKim2008 │ ├── output.bmp │ ├── prog.vcxproj.filters │ ├── example_MaryKim2008.cpp │ ├── prog.sln │ └── prog.vcxproj │ └── enhancement.WadudKabirDewanChae2007 │ ├── output.bmp │ ├── prog.vcxproj.filters │ ├── example_WadudKabirDewanChae2007.cpp │ ├── prog.sln │ └── prog.vcxproj ├── .gitattributes ├── examples-ml └── clustering │ └── fuzzyCMeans │ ├── prog.vcxproj.filters │ ├── example_fuzzyCMeans.cpp │ ├── prog.sln │ └── prog.vcxproj ├── README.md ├── LICENSE.txt ├── MANUAL.md ├── .gitignore ├── CONTRIBUTING.md └── CMakeLists.txt /data/lena.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunfuliu/pixkit/HEAD/data/lena.bmp -------------------------------------------------------------------------------- /data/NADD2013/ct256.map: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunfuliu/pixkit/HEAD/data/NADD2013/ct256.map -------------------------------------------------------------------------------- /data/NADD2013/ct512.map: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunfuliu/pixkit/HEAD/data/NADD2013/ct512.map -------------------------------------------------------------------------------- /lib/x64/vc10/pixkit_cv052.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunfuliu/pixkit/HEAD/lib/x64/vc10/pixkit_cv052.lib -------------------------------------------------------------------------------- /lib/x64/vc10/pixkit_cv052d.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunfuliu/pixkit/HEAD/lib/x64/vc10/pixkit_cv052d.lib -------------------------------------------------------------------------------- /lib/x64/vc10/pixkit_file052.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunfuliu/pixkit/HEAD/lib/x64/vc10/pixkit_file052.lib -------------------------------------------------------------------------------- /lib/x64/vc10/pixkit_ml052.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunfuliu/pixkit/HEAD/lib/x64/vc10/pixkit_ml052.lib -------------------------------------------------------------------------------- /lib/x64/vc10/pixkit_ml052d.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunfuliu/pixkit/HEAD/lib/x64/vc10/pixkit_ml052d.lib -------------------------------------------------------------------------------- /lib/x86/vc10/pixkit_cv052.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunfuliu/pixkit/HEAD/lib/x86/vc10/pixkit_cv052.lib -------------------------------------------------------------------------------- /lib/x86/vc10/pixkit_cv052d.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunfuliu/pixkit/HEAD/lib/x86/vc10/pixkit_cv052d.lib -------------------------------------------------------------------------------- /lib/x86/vc10/pixkit_file052.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunfuliu/pixkit/HEAD/lib/x86/vc10/pixkit_file052.lib -------------------------------------------------------------------------------- /lib/x86/vc10/pixkit_ml052.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunfuliu/pixkit/HEAD/lib/x86/vc10/pixkit_ml052.lib -------------------------------------------------------------------------------- /lib/x86/vc10/pixkit_ml052d.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunfuliu/pixkit/HEAD/lib/x86/vc10/pixkit_ml052d.lib -------------------------------------------------------------------------------- /lib/x64/vc10/pixkit_file052d.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunfuliu/pixkit/HEAD/lib/x64/vc10/pixkit_file052d.lib -------------------------------------------------------------------------------- /lib/x64/vc10/pixkit_image052.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunfuliu/pixkit/HEAD/lib/x64/vc10/pixkit_image052.lib -------------------------------------------------------------------------------- /lib/x64/vc10/pixkit_image052d.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunfuliu/pixkit/HEAD/lib/x64/vc10/pixkit_image052d.lib -------------------------------------------------------------------------------- /lib/x64/vc10/pixkit_timer052.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunfuliu/pixkit/HEAD/lib/x64/vc10/pixkit_timer052.lib -------------------------------------------------------------------------------- /lib/x64/vc10/pixkit_timer052d.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunfuliu/pixkit/HEAD/lib/x64/vc10/pixkit_timer052d.lib -------------------------------------------------------------------------------- /lib/x86/vc10/pixkit_file052d.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunfuliu/pixkit/HEAD/lib/x86/vc10/pixkit_file052d.lib -------------------------------------------------------------------------------- /lib/x86/vc10/pixkit_image052.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunfuliu/pixkit/HEAD/lib/x86/vc10/pixkit_image052.lib -------------------------------------------------------------------------------- /lib/x86/vc10/pixkit_image052d.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunfuliu/pixkit/HEAD/lib/x86/vc10/pixkit_image052d.lib -------------------------------------------------------------------------------- /lib/x86/vc10/pixkit_timer052.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunfuliu/pixkit/HEAD/lib/x86/vc10/pixkit_timer052.lib -------------------------------------------------------------------------------- /lib/x86/vc10/pixkit_timer052d.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunfuliu/pixkit/HEAD/lib/x86/vc10/pixkit_timer052d.lib -------------------------------------------------------------------------------- /modules/pixkit-image/src/comp.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunfuliu/pixkit/HEAD/modules/pixkit-image/src/comp.cpp -------------------------------------------------------------------------------- /modules/pixkit-cv/src/labeling.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunfuliu/pixkit/HEAD/modules/pixkit-cv/src/labeling.cpp -------------------------------------------------------------------------------- /modules/pixkit-image/src/attack.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunfuliu/pixkit/HEAD/modules/pixkit-image/src/attack.cpp -------------------------------------------------------------------------------- /modules/pixkit-image/src/filtering.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunfuliu/pixkit/HEAD/modules/pixkit-image/src/filtering.cpp -------------------------------------------------------------------------------- /modules/pixkit-image/src/halftoning.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunfuliu/pixkit/HEAD/modules/pixkit-image/src/halftoning.cpp -------------------------------------------------------------------------------- /modules/pixkit-image/src/edgedetection.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunfuliu/pixkit/HEAD/modules/pixkit-image/src/edgedetection.cpp -------------------------------------------------------------------------------- /modules/pixkit-image/src/MSRCR1997/retinex.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunfuliu/pixkit/HEAD/modules/pixkit-image/src/MSRCR1997/retinex.cpp -------------------------------------------------------------------------------- /examples-image/halftoning/dotdiffusion.NADD2013/ct256.map: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunfuliu/pixkit/HEAD/examples-image/halftoning/dotdiffusion.NADD2013/ct256.map -------------------------------------------------------------------------------- /examples-image/halftoning/dotdiffusion.NADD2013/ct512.map: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunfuliu/pixkit/HEAD/examples-image/halftoning/dotdiffusion.NADD2013/ct512.map -------------------------------------------------------------------------------- /examples-image/halftoning/dotdiffusion.NADD2013/output.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunfuliu/pixkit/HEAD/examples-image/halftoning/dotdiffusion.NADD2013/output.bmp -------------------------------------------------------------------------------- /examples-image/enhancement/enhancement.MaryKim2008/output.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunfuliu/pixkit/HEAD/examples-image/enhancement/enhancement.MaryKim2008/output.bmp -------------------------------------------------------------------------------- /examples-image/halftoning/dotdiffusion.GuoLiu2009/output.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunfuliu/pixkit/HEAD/examples-image/halftoning/dotdiffusion.GuoLiu2009/output.bmp -------------------------------------------------------------------------------- /modules/pixkit-image/src/CelikTjahjadi2012/CelikTjahjadi2012.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunfuliu/pixkit/HEAD/modules/pixkit-image/src/CelikTjahjadi2012/CelikTjahjadi2012.cpp -------------------------------------------------------------------------------- /examples-image/enhancement/enhancement.WadudKabirDewanChae2007/output.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunfuliu/pixkit/HEAD/examples-image/enhancement/enhancement.WadudKabirDewanChae2007/output.bmp -------------------------------------------------------------------------------- /modules/pixkit-image/src/multitoning/DMS2012/ChanduStanichWuTrager2014.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunfuliu/pixkit/HEAD/modules/pixkit-image/src/multitoning/DMS2012/ChanduStanichWuTrager2014.cpp -------------------------------------------------------------------------------- /examples-image/enhancement/enhancement.MaryKim2008/prog.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /modules/pixkit-file/include/pixkit-file.hpp: -------------------------------------------------------------------------------- 1 | // system related headers 2 | #include 3 | #include 4 | 5 | #ifndef __PIXKIT_FILE_HPP__ 6 | #define __PIXKIT_FILE_HPP__ 7 | namespace pixkit{ 8 | typedef const std::string CStr; 9 | typedef std::vector vecS; 10 | vecS loadStrList(CStr &fName); 11 | 12 | // vecMat 13 | bool write_vecMat(std::string fname,const std::vector &vec); 14 | bool read_vecMat(std::string fname,std::vector &vec); 15 | } 16 | #endif -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /examples-image/enhancement/enhancement.MaryKim2008/example_MaryKim2008.cpp: -------------------------------------------------------------------------------- 1 | // opencv related headers 2 | #include 3 | #include 4 | 5 | // system related headers 6 | #include 7 | 8 | // pixkit-image 9 | #include "../../../modules/pixkit-image/include/pixkit-image.hpp" 10 | 11 | 12 | void main(){ 13 | cv::Mat src,dst; 14 | src = cv::imread("../../../data/lena.bmp",CV_LOAD_IMAGE_GRAYSCALE); 15 | if(!src.empty()){ 16 | // process 17 | if(pixkit::enhancement::global::MaryKim2008(src,dst,2)){ 18 | // write output 19 | cv::imwrite("output.bmp",dst); 20 | // show image 21 | cv::imshow("src",src); 22 | cv::imshow("dst",dst); 23 | cv::waitKey(0); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /examples-ml/clustering/fuzzyCMeans/prog.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | pixkit-image 6 | 7 | 8 | 9 | 10 | 11 | {c5dde762-4131-4606-9189-48c7b5b5d2af} 12 | 13 | 14 | 15 | 16 | pixkit-image 17 | 18 | 19 | -------------------------------------------------------------------------------- /examples-image/halftoning/dotdiffusion.GuoLiu2009/example_dotdiffusion.GuoLiu2009.cpp: -------------------------------------------------------------------------------- 1 | // opencv related headers 2 | #include 3 | #include 4 | 5 | // system related headers 6 | #include 7 | 8 | // pixkit-image 9 | #include "../../../modules/pixkit-image/include/pixkit-image.hpp" 10 | 11 | void main(){ 12 | 13 | cv::Mat src,dst; 14 | 15 | // load image 16 | src = cv::imread("../../../data/lena.bmp",CV_LOAD_IMAGE_GRAYSCALE); 17 | if(!src.empty()){ 18 | // process 19 | if(pixkit::halftoning::dotdiffusion::GuoLiu2009(src,dst,8)){ 20 | // write output 21 | cv::imwrite("output.bmp",dst); 22 | 23 | // show image 24 | cv::imshow("src",src); 25 | cv::imshow("dst",dst); 26 | cv::waitKey(0); 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /examples-image/halftoning/dotdiffusion.GuoLiu2009/prog.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | pixkit-image 6 | 7 | 8 | 9 | 10 | 11 | {c5dde762-4131-4606-9189-48c7b5b5d2af} 12 | 13 | 14 | 15 | 16 | pixkit-image 17 | 18 | 19 | -------------------------------------------------------------------------------- /examples-image/halftoning/dotdiffusion.NADD2013/prog.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | pixkit-image 7 | 8 | 9 | 10 | 11 | {c5dde762-4131-4606-9189-48c7b5b5d2af} 12 | 13 | 14 | 15 | 16 | pixkit-image 17 | 18 | 19 | -------------------------------------------------------------------------------- /examples-image/enhancement/enhancement.WadudKabirDewanChae2007/prog.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | pixkit-image 6 | 7 | 8 | 9 | 10 | 11 | {c5dde762-4131-4606-9189-48c7b5b5d2af} 12 | 13 | 14 | 15 | 16 | pixkit-image 17 | 18 | 19 | -------------------------------------------------------------------------------- /modules/pixkit-image/test/prog.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | pixkit 7 | 8 | 9 | pixkit 10 | 11 | 12 | 13 | 14 | {6852f004-ee75-44a1-8eb6-bb7bc6a3a17f} 15 | 16 | 17 | 18 | 19 | pixkit 20 | 21 | 22 | -------------------------------------------------------------------------------- /examples-image/enhancement/enhancement.WadudKabirDewanChae2007/example_WadudKabirDewanChae2007.cpp: -------------------------------------------------------------------------------- 1 | // opencv related headers 2 | #include 3 | #include 4 | 5 | // system related headers 6 | #include 7 | 8 | // pixkit-image 9 | #include "../../../modules/pixkit-image/include/pixkit-image.hpp" 10 | 11 | void main(){ 12 | 13 | cv::Mat src,dst; 14 | 15 | char name1[50],name2[50]; 16 | 17 | src = cv::imread("../../../data/lena.bmp",CV_LOAD_IMAGE_GRAYSCALE); 18 | if(!src.empty()){ 19 | // process 20 | if(pixkit::enhancement::global::WadudKabirDewanChae2007(src,dst,2)){ 21 | // write output 22 | cv::imwrite("output.bmp",dst); 23 | 24 | // show image 25 | cv::imshow("src",src); 26 | cv::imshow("dst",dst); 27 | cv::waitKey(0); 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /modules/python/unittest.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | 4 | # =============================================================================== 5 | # add programs 6 | programs = ['test_image_halftoning'] 7 | for i in range(len(programs)): 8 | programs[i] = '.\\' + programs[i] 9 | if sys.platform == 'win32': 10 | for i in range(len(programs)): 11 | programs[i] = programs[i] + '.exe' 12 | 13 | # =============================================================================== 14 | # Helper functions 15 | def image_halftoning(delay): 16 | command = " ".join([programs[0], delay]) 17 | print command 18 | a = os.system(command) 19 | print a 20 | 21 | # =============================================================================== 22 | # Example datasets 23 | delay = '0' #ms 24 | 25 | # Go! 26 | image_halftoning(delay) 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /modules/pixkit-image/readme.md: -------------------------------------------------------------------------------- 1 | [Online version](https://github.com/yunfuliu/pixkit/blob/master/pixkit-image/readme.md) 2 | 3 | For users 4 | --------- 5 | * Include `pixkit-image.hpp`. 6 | * Include the source code placed in `/src` you needed.
Corresponding examples please go [example](https://github.com/yunfuliu/pixkit/tree/master/examples-image). 7 | 8 | For contributors 9 | ---------------- 10 | * Function definitions please place in `pixkit-image.hpp`. 11 | * Place your source code in `/src`.
If your code needs 12 | lots of functions required by only yourself, 13 | you can use an isolate file for them with a name as short 14 | as possible (example please see the NADD2013 case).
15 | Otherwise, we recommend you to implement your function 16 | into corresponding `/src/.cpp`. For instance, if you are 17 | implementing a filtering function, you can implement it 18 | into `src/filtering.cpp`. 19 | -------------------------------------------------------------------------------- /modules/pixkit-file/src/pixkit-file.cpp: -------------------------------------------------------------------------------- 1 | #include "../include/pixkit-file.hpp" 2 | #include 3 | #include 4 | 5 | using namespace cv; 6 | 7 | pixkit::vecS pixkit::loadStrList(CStr &fName){ 8 | std::ifstream fIn(fName); 9 | std::string line; 10 | pixkit::vecS strs; 11 | while(getline(fIn, line) && line.size()) 12 | strs.push_back(line); 13 | return strs; 14 | } 15 | 16 | bool pixkit::write_vecMat(std::string fname,const std::vector &vec){ 17 | FileStorage fs(fname,FileStorage::WRITE); 18 | fs << "size" << ((int)vec.size()); 19 | for(int i=0;i &vec){ 27 | FileStorage fs(fname,FileStorage::READ); 28 | int vec_size; 29 | fs["size"] >> vec_size; 30 | vec.resize(vec_size); 31 | Mat aa; 32 | for(int i=0;i> vec[i]; 34 | } 35 | fs.release(); 36 | return true; 37 | } -------------------------------------------------------------------------------- /examples-ml/clustering/fuzzyCMeans/example_fuzzyCMeans.cpp: -------------------------------------------------------------------------------- 1 | // opencv related headers 2 | #include 3 | #include 4 | 5 | // system related headers 6 | #include 7 | 8 | // pixkit-image 9 | #include "../../../modules/pixkit-ml/include/pixkit-ml.hpp" 10 | 11 | void main(){ 12 | 13 | // sample point definition (2d case) 14 | std::vector> src(6,std::vector(2,0)),dst; 15 | src[0][0] = 1; src[0][1] = 1; 16 | src[1][0] = 1; src[1][1] = 2; 17 | src[2][0] = 2; src[2][1] = 1; 18 | src[3][0] = 10; src[3][1] = 3; 19 | src[4][0] = 10; src[4][1] = 5; 20 | src[5][0] = 12; src[5][1] = 4; 21 | 22 | // unsupervised clustering with fuzzy c means 23 | pixkit::clustering::fuzzyCMeans(src,dst,1,2,2.0,4); 24 | 25 | // output display 26 | for(int i = 0; i < src.size(); i++){ 27 | for(int j = 0; j < src[0].size(); j++){ 28 | std::cout << dst[i][j] << "\t"; 29 | } 30 | std::cout << std::endl; 31 | } 32 | std::cout << std::endl; 33 | 34 | system("pause"); 35 | } -------------------------------------------------------------------------------- /modules/pixkit-cv/include/pixkit-cv.hpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////// 2 | // 3 | // SOURCE CODE: https://github.com/yunfuliu/pixkit 4 | // 5 | // BEIRF: pixkit-cv contains computer vision related tools and methods which 6 | // have been published (on articles, e.g., journal or conference papers). 7 | // 8 | ////////////////////////////////////////////////////////////////////////// 9 | #include 10 | #include 11 | 12 | #include 13 | #include 14 | 15 | 16 | #ifndef __PIXKIT_CV_HPP__ 17 | #define __PIXKIT_CV_HPP__ 18 | 19 | namespace pixkit{ 20 | 21 | namespace detection{ 22 | 23 | // bounding box 24 | class CBBs{ 25 | public: 26 | cv::Rect rect; // position of that BB 27 | float conf; // confidence 28 | }; 29 | 30 | bool nms_PairwiseMax_2010(std::vector &boxes,float overlap=0.5); 31 | 32 | bool nms_PairwiseMaxStar_2009(std::vector &boxes,float overlap=0.6); 33 | 34 | } 35 | 36 | namespace labeling{ 37 | 38 | // Two-pass connected-component labeling 39 | bool twoPass(const cv::Mat &src,cv::Mat &dst,const int offset=1); 40 | 41 | } 42 | 43 | } 44 | #endif 45 | -------------------------------------------------------------------------------- /modules/pixkit-timer/include/pixkit-timer.hpp: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // 3 | // pixkit-timer.hpp 4 | // repo: https://github.com/yunfuliu/pixkit 5 | // 6 | // Prototype of this comes from the CmTimer.h 7 | // in repo: https://github.com/MingMingCheng/CmCode 8 | // 9 | // Author: Ming-Ming Cheng 10 | // 11 | //======================================================================== 12 | 13 | #pragma once 14 | #include 15 | #include 16 | 17 | namespace pixkit{ 18 | 19 | class Timer{ 20 | public: 21 | Timer(const std::string t = "Timer"):title(t){ 22 | is_started = false; start_clock = 0; cumulative_clock = 0; n_starts = 0; 23 | } 24 | ~Timer(){ if (is_started) printf("pixkit::timer '%s' is started and is being destroyed.\n", title.c_str()); } 25 | 26 | void Start(); 27 | void Stop(); 28 | void Reset(); 29 | 30 | float Report(); 31 | float StopAndReport() { Stop(); return Report(); } 32 | float TimeInSeconds(); 33 | 34 | float AvgTime(){assert(is_started == false); return TimeInSeconds()/n_starts;} 35 | 36 | private: 37 | const std::string title; 38 | 39 | bool is_started; 40 | unsigned long long int start_clock; 41 | unsigned long long int cumulative_clock; 42 | unsigned int n_starts; 43 | }; 44 | } -------------------------------------------------------------------------------- /modules/pixkit-image/test/prog.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual Studio 2010 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "prog", "prog.vcxproj", "{1F160CC2-3EAA-429B-AAF8-1A54FD967981}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Debug|x64 = Debug|x64 10 | Release|Win32 = Release|Win32 11 | Release|x64 = Release|x64 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {1F160CC2-3EAA-429B-AAF8-1A54FD967981}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {1F160CC2-3EAA-429B-AAF8-1A54FD967981}.Debug|Win32.Build.0 = Debug|Win32 16 | {1F160CC2-3EAA-429B-AAF8-1A54FD967981}.Debug|x64.ActiveCfg = Debug|x64 17 | {1F160CC2-3EAA-429B-AAF8-1A54FD967981}.Debug|x64.Build.0 = Debug|x64 18 | {1F160CC2-3EAA-429B-AAF8-1A54FD967981}.Release|Win32.ActiveCfg = Release|Win32 19 | {1F160CC2-3EAA-429B-AAF8-1A54FD967981}.Release|Win32.Build.0 = Release|Win32 20 | {1F160CC2-3EAA-429B-AAF8-1A54FD967981}.Release|x64.ActiveCfg = Release|x64 21 | {1F160CC2-3EAA-429B-AAF8-1A54FD967981}.Release|x64.Build.0 = Release|x64 22 | EndGlobalSection 23 | GlobalSection(SolutionProperties) = preSolution 24 | HideSolutionNode = FALSE 25 | EndGlobalSection 26 | EndGlobal 27 | -------------------------------------------------------------------------------- /examples-ml/clustering/fuzzyCMeans/prog.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual Studio 2010 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "prog", "prog.vcxproj", "{1F160CC2-3EAA-429B-AAF8-1A54FD967981}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Debug|x64 = Debug|x64 10 | Release|Win32 = Release|Win32 11 | Release|x64 = Release|x64 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {1F160CC2-3EAA-429B-AAF8-1A54FD967981}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {1F160CC2-3EAA-429B-AAF8-1A54FD967981}.Debug|Win32.Build.0 = Debug|Win32 16 | {1F160CC2-3EAA-429B-AAF8-1A54FD967981}.Debug|x64.ActiveCfg = Debug|x64 17 | {1F160CC2-3EAA-429B-AAF8-1A54FD967981}.Debug|x64.Build.0 = Debug|x64 18 | {1F160CC2-3EAA-429B-AAF8-1A54FD967981}.Release|Win32.ActiveCfg = Release|Win32 19 | {1F160CC2-3EAA-429B-AAF8-1A54FD967981}.Release|Win32.Build.0 = Release|Win32 20 | {1F160CC2-3EAA-429B-AAF8-1A54FD967981}.Release|x64.ActiveCfg = Release|x64 21 | {1F160CC2-3EAA-429B-AAF8-1A54FD967981}.Release|x64.Build.0 = Release|x64 22 | EndGlobalSection 23 | GlobalSection(SolutionProperties) = preSolution 24 | HideSolutionNode = FALSE 25 | EndGlobalSection 26 | EndGlobal 27 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![GitHub version](https://badge.fury.io/gh/yunfuliu%2Fpixkit.png)](http://badge.fury.io/gh/yunfuliu%2Fpixkit) 2 | 3 | pixkit 4 | ====== 5 | For only academic usages of image processing (`pixkit-image`), machine learning (`pixkit-ml`), and computer vision (`pixkit-cv`). 6 | 7 | Contains related methods which had been published (on articles, e.g., journal or conference papers). 8 | In addition to above implementations, some frequently utilized tools, are also involved as expected. 9 | 10 | The repo, OpenCV, is used to build up all the pixkit functions: 11 | 12 | For users 13 | --------- 14 | See [manual](https://github.com/yunfuliu/pixkit/blob/master/MANUAL.md) for details. 15 | 16 | For contributors 17 | ---------------- 18 | Please read [CONTRIBUTING.md](https://github.com/yunfuliu/pixkit/blob/master/CONTRIBUTING.md) in this directory. 19 | Many thanks to our [contributors](https://github.com/yunfuliu/pixkit/graphs/contributors). 20 | 21 | Bugs 22 | ---- 23 | Please "report bugs on GitHub ". 24 | 25 | License 26 | ------- 27 | Please read [LICENSE.txt](https://github.com/yunfuliu/pixkit/blob/master/LICENSE.txt) in this directory. 28 | 29 | Others 30 | ------ 31 | [Semantic Versioning](http://semver.org/) is used in our version control. 32 | -------------------------------------------------------------------------------- /examples-image/halftoning/dotdiffusion.GuoLiu2009/prog.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual Studio 2010 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "prog", "prog.vcxproj", "{1F160CC2-3EAA-429B-AAF8-1A54FD967981}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Debug|x64 = Debug|x64 10 | Release|Win32 = Release|Win32 11 | Release|x64 = Release|x64 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {1F160CC2-3EAA-429B-AAF8-1A54FD967981}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {1F160CC2-3EAA-429B-AAF8-1A54FD967981}.Debug|Win32.Build.0 = Debug|Win32 16 | {1F160CC2-3EAA-429B-AAF8-1A54FD967981}.Debug|x64.ActiveCfg = Debug|x64 17 | {1F160CC2-3EAA-429B-AAF8-1A54FD967981}.Debug|x64.Build.0 = Debug|x64 18 | {1F160CC2-3EAA-429B-AAF8-1A54FD967981}.Release|Win32.ActiveCfg = Release|Win32 19 | {1F160CC2-3EAA-429B-AAF8-1A54FD967981}.Release|Win32.Build.0 = Release|Win32 20 | {1F160CC2-3EAA-429B-AAF8-1A54FD967981}.Release|x64.ActiveCfg = Release|x64 21 | {1F160CC2-3EAA-429B-AAF8-1A54FD967981}.Release|x64.Build.0 = Release|x64 22 | EndGlobalSection 23 | GlobalSection(SolutionProperties) = preSolution 24 | HideSolutionNode = FALSE 25 | EndGlobalSection 26 | EndGlobal 27 | -------------------------------------------------------------------------------- /examples-image/halftoning/dotdiffusion.NADD2013/prog.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual Studio 2010 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "prog", "prog.vcxproj", "{1F160CC2-3EAA-429B-AAF8-1A54FD967981}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Debug|x64 = Debug|x64 10 | Release|Win32 = Release|Win32 11 | Release|x64 = Release|x64 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {1F160CC2-3EAA-429B-AAF8-1A54FD967981}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {1F160CC2-3EAA-429B-AAF8-1A54FD967981}.Debug|Win32.Build.0 = Debug|Win32 16 | {1F160CC2-3EAA-429B-AAF8-1A54FD967981}.Debug|x64.ActiveCfg = Debug|x64 17 | {1F160CC2-3EAA-429B-AAF8-1A54FD967981}.Debug|x64.Build.0 = Debug|x64 18 | {1F160CC2-3EAA-429B-AAF8-1A54FD967981}.Release|Win32.ActiveCfg = Release|Win32 19 | {1F160CC2-3EAA-429B-AAF8-1A54FD967981}.Release|Win32.Build.0 = Release|Win32 20 | {1F160CC2-3EAA-429B-AAF8-1A54FD967981}.Release|x64.ActiveCfg = Release|x64 21 | {1F160CC2-3EAA-429B-AAF8-1A54FD967981}.Release|x64.Build.0 = Release|x64 22 | EndGlobalSection 23 | GlobalSection(SolutionProperties) = preSolution 24 | HideSolutionNode = FALSE 25 | EndGlobalSection 26 | EndGlobal 27 | -------------------------------------------------------------------------------- /examples-image/enhancement/enhancement.MaryKim2008/prog.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual Studio 2010 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "prog", "prog.vcxproj", "{1F160CC2-3EAA-429B-AAF8-1A54FD967981}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Debug|x64 = Debug|x64 10 | Release|Win32 = Release|Win32 11 | Release|x64 = Release|x64 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {1F160CC2-3EAA-429B-AAF8-1A54FD967981}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {1F160CC2-3EAA-429B-AAF8-1A54FD967981}.Debug|Win32.Build.0 = Debug|Win32 16 | {1F160CC2-3EAA-429B-AAF8-1A54FD967981}.Debug|x64.ActiveCfg = Debug|x64 17 | {1F160CC2-3EAA-429B-AAF8-1A54FD967981}.Debug|x64.Build.0 = Debug|x64 18 | {1F160CC2-3EAA-429B-AAF8-1A54FD967981}.Release|Win32.ActiveCfg = Release|Win32 19 | {1F160CC2-3EAA-429B-AAF8-1A54FD967981}.Release|Win32.Build.0 = Release|Win32 20 | {1F160CC2-3EAA-429B-AAF8-1A54FD967981}.Release|x64.ActiveCfg = Release|x64 21 | {1F160CC2-3EAA-429B-AAF8-1A54FD967981}.Release|x64.Build.0 = Release|x64 22 | EndGlobalSection 23 | GlobalSection(SolutionProperties) = preSolution 24 | HideSolutionNode = FALSE 25 | EndGlobalSection 26 | EndGlobal 27 | -------------------------------------------------------------------------------- /examples-image/enhancement/enhancement.WadudKabirDewanChae2007/prog.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual Studio 2010 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "prog", "prog.vcxproj", "{1F160CC2-3EAA-429B-AAF8-1A54FD967981}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Debug|x64 = Debug|x64 10 | Release|Win32 = Release|Win32 11 | Release|x64 = Release|x64 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {1F160CC2-3EAA-429B-AAF8-1A54FD967981}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {1F160CC2-3EAA-429B-AAF8-1A54FD967981}.Debug|Win32.Build.0 = Debug|Win32 16 | {1F160CC2-3EAA-429B-AAF8-1A54FD967981}.Debug|x64.ActiveCfg = Debug|x64 17 | {1F160CC2-3EAA-429B-AAF8-1A54FD967981}.Debug|x64.Build.0 = Debug|x64 18 | {1F160CC2-3EAA-429B-AAF8-1A54FD967981}.Release|Win32.ActiveCfg = Release|Win32 19 | {1F160CC2-3EAA-429B-AAF8-1A54FD967981}.Release|Win32.Build.0 = Release|Win32 20 | {1F160CC2-3EAA-429B-AAF8-1A54FD967981}.Release|x64.ActiveCfg = Release|x64 21 | {1F160CC2-3EAA-429B-AAF8-1A54FD967981}.Release|x64.Build.0 = Release|x64 22 | EndGlobalSection 23 | GlobalSection(SolutionProperties) = preSolution 24 | HideSolutionNode = FALSE 25 | EndGlobalSection 26 | EndGlobal 27 | -------------------------------------------------------------------------------- /modules/pixkit-image/src/qualityassessment/IW_PSNR.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "..\..\include\pixkit-image.hpp" 5 | 6 | using namespace std; 7 | using namespace cv; 8 | 9 | float calculate_MSE(const cv::Mat &X,const cv::Mat &Y){ 10 | float MSE=0; 11 | int Nj=0;//Np is the number of pixels in X 12 | for(int i=0;i(i)[j]-Y.ptr(i)[j]),2); 16 | } 17 | } 18 | MSE/=Nj; 19 | return MSE; 20 | } 21 | 22 | //caculate eace value of IW_PSNR in jth scale 23 | float * IW_MSEj(const cv::Mat &X,const cv::Mat &Y,float * MSEj){ 24 | int scale_j=4; 25 | double MSE; 26 | //build 5 scale of original 27 | vector ScaleX,ScaleY; 28 | buildPyramid(X,ScaleX,scale_j); 29 | buildPyramid(Y,ScaleY,scale_j); 30 | 31 | 32 | for(int jth=0;jth<5;jth++){ 33 | MSE=calculate_MSE(ScaleX[jth],ScaleY[jth]); 34 | MSEj[jth]=MSE; 35 | } 36 | 37 | return MSEj; 38 | } 39 | 40 | float pixkit::qualityassessment::IW_PSNR(const cv::Mat &src1,const cv::Mat &src2){ 41 | if(src1.type()!=CV_8UC1 || src2.type()!=CV_8UC1 ){CV_Assert(false);} 42 | 43 | int L=255; 44 | float MSEj[5]={0,0,0,0,0}; 45 | float IW_MSE=1;//initialize the value of IW_MSE 46 | float IW_PSNR=1;//initialize the value of IW_PSNR 47 | float betaj[5]={0.0448,0.2856,0.3001,0.2363,0.1333}; 48 | 49 | IW_MSEj(src1,src2,MSEj); 50 | for (int j = 0; j < 5; j++) 51 | { 52 | IW_MSE*=pow(MSEj[j],betaj[j]); 53 | } 54 | //cout<<"IW_MSE value= "<& data, const std::string file){ 6 | 7 | ifstream fin(file.c_str()); 8 | if (!fin){ 9 | cout << "File error!" << endl; 10 | exit(1); 11 | } 12 | 13 | string line; 14 | double d = 0.0; 15 | 16 | while (getline(fin, line)){ 17 | istringstream in(line); 18 | pixkit::classification::SSample data1; 19 | in >> data1.classnumber; 20 | while (in >> d){ 21 | data1.features.push_back(d); 22 | } 23 | data.push_back(data1); 24 | } 25 | 26 | fin.close(); 27 | } 28 | void pixkit::mldata::readTest(std::vector& data, const std::string file){ 29 | ifstream fin(file.c_str()); 30 | 31 | if (!fin){ 32 | cout << "File error!" << endl; 33 | exit(1); 34 | } 35 | 36 | double d = 0.0; 37 | string line; 38 | while (getline(fin, line)){ 39 | istringstream in(line); 40 | pixkit::classification::SSample data1; 41 | while (in >> d){ 42 | data1.features.push_back(d); 43 | } 44 | data.push_back(data1); 45 | } 46 | 47 | fin.close(); 48 | } 49 | void pixkit::mldata::write(std::vector& data, const std::string file){ 50 | ofstream fout(file.c_str()); 51 | if (!fout){ 52 | fout << "File error!" << endl; 53 | exit(1); 54 | } 55 | for (vector::size_type i = 0; i != data.size(); ++i){ 56 | fout << data[i].classnumber << '\t'; 57 | for (vector::size_type j = 0; j != data[i].features.size(); ++j){ 58 | fout << data[i].features[j] << ' '; 59 | } 60 | fout << endl; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013, Multimedia Signal Processing Lab., 2 | National Taiwan University of Science and Technology, all rights reserved. 3 | Third party copyrights are property of their respective owners. 4 | 5 | Redistribution and use in source and binary forms, with or without modification, 6 | are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | * The name of the copyright holders may not be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 22 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 25 | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /modules/pixkit-timer/src/pixkit-timer.cpp: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // 3 | // pixkit-timer.cpp 4 | // repo: https://github.com/yunfuliu/pixkit 5 | // 6 | // Prototype of this comes from the CmTimer.h 7 | // in repo: https://github.com/MingMingCheng/CmCode 8 | // 9 | // Author: Ming-Ming Cheng 10 | // 11 | //======================================================================== 12 | 13 | #include "../include/pixkit-timer.hpp" 14 | #include 15 | 16 | void pixkit::Timer::Start(){ 17 | if (is_started){ 18 | printf("pixkit::timer '%s' is already started. Nothing done.\n", title.c_str()); 19 | start_clock = cvGetTickCount(); 20 | return; 21 | } 22 | is_started = true; n_starts++; start_clock = cvGetTickCount(); 23 | } 24 | void pixkit::Timer::Stop(){ 25 | if (!is_started){ 26 | printf("pixkit::timer '%s' is started. Nothing done\n", title.c_str()); 27 | return; 28 | } 29 | cumulative_clock += cvGetTickCount() - start_clock; is_started = false; 30 | } 31 | void pixkit::Timer::Reset(){ 32 | if (is_started) { 33 | printf("pixkit::timer '%s'is started during reset request.\n Only reset cumulative time.\n"); 34 | return; 35 | } 36 | start_clock = 0; cumulative_clock = 0; n_starts = 0; 37 | } 38 | float pixkit::Timer::Report(){ 39 | if (is_started){ 40 | printf("pixkit::timer '%s' is started.\n Cannot provide a time report.", title.c_str()); 41 | return false; 42 | } 43 | float timeUsed = TimeInSeconds(); 44 | printf("[%s] CumuTime: %4gs, #run: %4d, AvgTime: %4gs\n", title.c_str(), timeUsed, n_starts, timeUsed/n_starts); 45 | return timeUsed/(float)n_starts; 46 | } 47 | float pixkit::Timer::TimeInSeconds(){ 48 | if (is_started){ 49 | printf("pixkit::timer '%s' is started. Nothing done\n", title.c_str()); 50 | return 0; 51 | } 52 | return static_cast(double(cumulative_clock) / cv::getTickFrequency()); 53 | } -------------------------------------------------------------------------------- /examples-image/halftoning/dotdiffusion.NADD2013/example_dotdiffusion.NADD2013.cpp: -------------------------------------------------------------------------------- 1 | // opencv related headers 2 | #include 3 | #include 4 | 5 | // system related headers 6 | #include 7 | 8 | // pixkit-image 9 | #include "../../../modules/pixkit-image/include/pixkit-image.hpp" 10 | 11 | void main(){ 12 | 13 | 14 | ////////////////////////////////////////////////////////////////////////// 15 | ///// Select a CT Size 16 | std::cout << "Select a size of CT:" << std::endl 17 | << "\t1) 256" << std::endl 18 | << "\t2) 512" << std::endl; 19 | short CTSize; 20 | std::cin >> CTSize; 21 | if(CTSize!=1&&CTSize!=2){ 22 | CV_Error(CV_StsBadArg,""); 23 | } 24 | CTSize = CTSize*256; 25 | char name[30]; 26 | sprintf(name,"ct%.3d.map",CTSize); 27 | 28 | 29 | ////////////////////////////////////////////////////////////////////////// 30 | ///// [case01] ct generation and save 31 | pixkit::halftoning::dotdiffusion::CNADDCT cct; 32 | cct.generation(cv::Size(CTSize,CTSize)); // assign the size to ct 33 | cct.save(name); // Thus, this save (and entire [case01] can be perform 34 | // only once for many images with different sizes. 35 | // Maps of sizes 256 and 512 are also saved in 36 | // pixkit/data/NADD2013. 37 | 38 | 39 | ////////////////////////////////////////////////////////////////////////// 40 | ///// [case02] load ct and perform nadd halftoning 41 | // load .map file 42 | cv::Mat src,dst; 43 | // pixkit::halftoning::dotdiffusion::CNADDCT cct; // required when without [case01] 44 | cct.load(name); 45 | // load image 46 | src = cv::imread("../../../data/lena.bmp",CV_LOAD_IMAGE_GRAYSCALE); 47 | if(!src.empty()){ 48 | // process 49 | pixkit::halftoning::dotdiffusion::NADD2013(src,dst,cct); 50 | 51 | // write 52 | cv::imwrite("output.bmp",dst); 53 | 54 | // show results 55 | cv::namedWindow("src"); 56 | cv::namedWindow("dst"); 57 | cv::moveWindow("src",0,0); 58 | cv::moveWindow("dst",src.cols,0); 59 | cv::imshow("src",src); 60 | cv::imshow("dst",dst); 61 | cv::waitKey(0); 62 | } 63 | 64 | 65 | } -------------------------------------------------------------------------------- /modules/pixkit-cv/src/detection.cpp: -------------------------------------------------------------------------------- 1 | #include "../include/pixkit-cv.hpp" 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | bool comparator(const pixkit::detection::CBBs &l, const pixkit::detection::CBBs &r){ 10 | return l.conf > r.conf; 11 | } 12 | bool pixkit::detection::nms_PairwiseMax_2010(std::vector &boxes,float overlap){ 13 | if(boxes.size()<=0){ 14 | return false; 15 | }else{ 16 | // sort pick 17 | std::sort(boxes.begin(),boxes.end(),comparator); 18 | // erase others 19 | std::vector::iterator it_major,it_minor; 20 | int idx_major = 0; 21 | while(idx_majorrect & it_minor->rect; // intersection rect 30 | float overlap_ratio = ((float)int_rect.area())/((float)it_minor->rect.area()); 31 | if(overlap_ratio>overlap){ 32 | boxes.erase(it_minor); // erase 33 | }else{ 34 | idx_minor ++; 35 | } 36 | } 37 | idx_major++; 38 | } 39 | return true; 40 | } 41 | return true; 42 | } 43 | bool pixkit::detection::nms_PairwiseMaxStar_2009(std::vector &boxes,float overlap){ 44 | if(boxes.size()<=0){ 45 | return false; 46 | }else{ 47 | // sort pick 48 | std::sort(boxes.begin(),boxes.end(),comparator); 49 | // erase others 50 | std::vector::iterator it_major,it_minor; 51 | int idx_major = 0; 52 | while(idx_majorrect & it_minor->rect; // intersection rect 61 | float union_area_size = it_major->rect.area() + it_minor->rect.area() - int_rect.area(); 62 | float overlap_ratio = ((float)int_rect.area())/union_area_size; 63 | if(overlap_ratio>overlap){ 64 | boxes.erase(it_minor); // erase 65 | }else{ 66 | idx_minor ++; 67 | } 68 | } 69 | idx_major++; 70 | } 71 | return true; 72 | } 73 | return true; 74 | } 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /MANUAL.md: -------------------------------------------------------------------------------- 1 | PIXKIT MANUAL 2 | ============= 3 | 4 | * Install [OpenCV](http://opencv.org/) 5 | 6 | * Go [releases](http://goo.gl/GHfv9g "pixkit/releases") and download the latest stable version to for instance, `C:\pixkit\src\` 7 | *You can also click the "[Download ZIP](https://github.com/yunfuliu/pixkit)" on the homepage for up-to-date functions. However, the libs in `C:\pixkit\src\lib\` may not support the newer functions which are released after the latest release version.* 8 | 9 | pixkit involves following major functions: 10 | - computer vision: `pixkit-cv` 11 | - file process: `pixkit-file` 12 | - image processing: `pixkit-image` 13 | - maching learning: `pixkit-ml` 14 | - timer: `pixkit-timer` 15 | 16 | * Function definitions: Please go [wiki](https://github.com/yunfuliu/pixkit/wiki) 17 | 18 | * (Optional) If you meet bugs during above procedure or while you are using pixkit, please go [issues](https://github.com/yunfuliu/pixkit/issues) and report in either English or Chinese. 19 | 20 | * There are two ways for using pixkit: 21 | 1. Without CMake: 22 | - 1) Check whether the versions of libs in `C:\pixkit\src\lib` support your environment. If not, you have to use CMake for using pixkit; if yes, go to the next step. 23 | - 2) For each of your project, involves the following link to your lib path. For instance, the environment with vc10 and x64, you should involve this to your lib path: `C:\pixkit\src\lib\x64\vc10`. 24 | - 3) For each of your project, involves this link to your source code path: `C:\pixkit\src\modules\` 25 | 2. With CMake: 26 | 27 | - 1) Build up pixkit with [CMake](http://www.cmake.org/) for your environment, and assign a path for your build with, i.e., `C:\pixkit\build\` 28 | 29 | By now, only the following environments are tested: 30 | - Visual Studio 12 Win64 (please select the Visual Studio 11 while selecting your platform) 31 | - Visual Studio 11 Win32/Win64 32 | - Visual Studio 10 Win32/Win64 33 | 34 | ![aa](http://miupix.cc/dm/M45HRY/sample.jpg) 35 | 36 | - 2) Compile INSTALL project in `C:\pixkit\build\pixkit.sln` with both release and debug modes 37 | 38 | - 3) All the required resources involving "include" and "lib" are in the folder `C:\pixkit\build\install\` 39 | 40 | - Samples: Some few examples are also built up in `C:\pixkit\build\install\samples\` for test 41 | 42 | -------------------------------------------------------------------------------- /modules/pixkit-image/src/halftoning/CVT/cvt.hpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////// 2 | // 3 | // cvt.hpp 4 | // ------- 5 | // This source code comes from the following website: 6 | // http://people.sc.fsu.edu/~jburkardt/cpp_src/cvt/cvt.html// 7 | // Please read it for details and license. 8 | // 9 | // Source code: http://people.sc.fsu.edu/~jburkardt/cpp_src/cvt/cvt.hpp 10 | // 11 | ////////////////////////////////////////////////////////////////////////// 12 | char ch_cap ( char c ); 13 | bool ch_eqi ( char c1, char c2 ); 14 | int ch_to_digit ( char c ); 15 | void cvt ( int dim_num, int n, int batch, int init, int sample, int sample_num, 16 | int it_max, int it_fixed, int *seed, double r[], int *it_num, 17 | double *it_diff, double *energy ); 18 | double cvt_energy ( int dim_num, int n, int batch, int sample, bool initialize, 19 | int sample_num, int *seed, double r[] ); 20 | void cvt_iterate ( int dim_num, int n, int batch, int sample, bool initialize, 21 | int sample_num, int *seed, double r[], double *it_diff, double *energy ); 22 | void cvt_sample ( int dim_num, int n, int n_now, int sample, bool initialize, 23 | int *seed, double r[] ); 24 | void data_read ( char *file_in_name, int dim_num, int n, double r[] ); 25 | char digit_to_ch ( int i ); 26 | void find_closest ( int dim_num, int n, int sample_num, double s[], double r[], 27 | int nearest[] ); 28 | int get_seed ( void ); 29 | bool halham_leap_check ( int dim_num, int leap[] ); 30 | bool halham_n_check ( int n ); 31 | bool halham_dim_num_check ( int dim_num ); 32 | bool halham_seed_check ( int dim_num, int seed[] ); 33 | bool halham_step_check ( int step ); 34 | bool halton_base_check ( int dim_num, int base[] ); 35 | int i4_log_10 ( int i ); 36 | int i4_max ( int i1, int i2 ); 37 | int i4_min ( int i1, int i2 ); 38 | void i4_to_halton_sequence ( int dim_num, int n, int step, int seed[], int leap[], 39 | int base[], double r[] ); 40 | char *i4_to_s ( int i ); 41 | int prime ( int n ); 42 | double r8_epsilon ( void ); 43 | double r8_huge ( void ); 44 | void r8mat_transpose_print ( int m, int n, double a[], char *title ); 45 | void r8mat_transpose_print_some ( int m, int n, double a[], int ilo, int jlo, 46 | int ihi, int jhi, char *title ); 47 | void r8mat_uniform_01 ( int m, int n, int *seed, double r[] ); 48 | void r8mat_write ( std::string output_filename, int m, int n, double table[] ); 49 | unsigned long random_initialize ( int seed ); 50 | void s_blank_delete ( char *s ); 51 | void s_cap ( char *s ); 52 | bool s_eqi ( char *s1, char *s2 ); 53 | int s_len_trim ( char* s ); 54 | double s_to_r8 ( char *s, int *lchar, bool *error ); 55 | bool s_to_r8vec ( char *s, int n, double rvec[] ); 56 | void timestamp ( void ); 57 | void tuple_next_fast ( int m, int n, int rank, int x[] ); 58 | void user ( int dim_num, int n, int *seed, double r[] ); 59 | -------------------------------------------------------------------------------- /modules/pixkit-image/src/LAT2011/LAT2011.cpp: -------------------------------------------------------------------------------- 1 | #include "../../include/pixkit-image.hpp" 2 | 3 | void new_integral(const cv::Mat &src, int **integral_image) 4 | { 5 | 6 | int i,j; 7 | 8 | integral_image[1][1]=static_cast < int >(src.data[0*src.cols+0]); 9 | 10 | 11 | for (i = 1 ; i< src.cols ; i++) 12 | { 13 | 14 | integral_image[1][i+1]=static_cast < int >(src.data[0*src.cols+i])+integral_image[1][i]; 15 | 16 | } 17 | 18 | for (i = 1 ; i< src.rows ; i++) 19 | { 20 | integral_image[i+1][1]=static_cast < int >(src.data[i*src.cols+0])+integral_image[i][1]; 21 | } 22 | 23 | for (i = 1 ; i< src.rows ; i++) 24 | { 25 | for (j = 1 ; j< src.cols ; j++) 26 | { 27 | integral_image[i+1][j+1]=static_cast < int >(src.data[i*src.cols+j])+integral_image[i+1][j]+integral_image[i][j+1]-integral_image[i][j]; 28 | 29 | } 30 | } 31 | 32 | } 33 | 34 | 35 | double new_local_mean(int x,int y,int windowsize,int **integral_image) 36 | { 37 | 38 | int d= (windowsize/2)+1,s; 39 | double localmean; 40 | s=(integral_image[x+d-1][y+d-1]+integral_image[x-d][y-d])-(integral_image[x-d][y+d-1]+integral_image[x+d-1][y-d]); 41 | localmean=s/(windowsize*windowsize); 42 | return localmean; 43 | 44 | 45 | } 46 | 47 | bool pixkit::thresholding::LAT2011(const cv::Mat &src,cv::Mat &dst,int windowSize, double k){ 48 | 49 | ////////////////////////////////////////////////////////////////////////// 50 | ///// exceptions 51 | if(src.type()!=CV_8UC1){ 52 | CV_Error(CV_StsBadArg,"[pixkit::thresholding::LAT2011] src's type should be CV_8UC1."); 53 | } 54 | 55 | 56 | ////////////////////////////////////////////////////////////////////////// 57 | ///// integral 58 | int **new_integral_image = new int *[src.rows+1]; 59 | for(int i=0;i<=src.rows;i++){ 60 | new_integral_image[i] = new int [src.cols+1]; 61 | } 62 | new_integral( src, new_integral_image); 63 | 64 | ////////////////////////////////////////////////////////////////////////// 65 | ///// initial 66 | dst.create(src.size(),src.type()); 67 | dst.setTo(0); 68 | 69 | 70 | ////////////////////////////////////////////////////////////////////////// 71 | ///// process 72 | int startstep= (windowSize/2)+1; 73 | int endstep=startstep-1; 74 | double localmean,deviation,T; 75 | 76 | for (int i=startstep ; i<=src.rows-endstep-1;i++){ 77 | for (int j=startstep ; j<=src.cols-endstep-1;j++){ 78 | 79 | localmean=new_local_mean(i+1,j+1, windowSize,new_integral_image); 80 | deviation=src.data[i*src.cols+j]-localmean; 81 | T=localmean*(1+k*((deviation/(1-deviation))-1)); 82 | 83 | if (src.data[i*src.cols+j]<=T){ 84 | dst.data[i*dst.cols+j]=0; 85 | 86 | }else{ 87 | dst.data[i*dst.cols+j]=255; 88 | } 89 | 90 | } 91 | } 92 | 93 | 94 | for(int i=0;i 3 | 4 | using namespace std; 5 | 6 | void calculate(vector> &input, vector> &out, vector> &sum){ 7 | 8 | vector lable(input.size(),(-1)); // Labeling 9 | vector num(out.size(),0); // Check that how many points in each group 10 | double dist = 0,min=5000.0; 11 | 12 | 13 | #pragma region Calculate distance 14 | for(int i=0;i> &src, std::vector> &dst, int K, int iter, pixkit::clustering::KM_TYPE type){ 50 | 51 | double vectorSize = src.size(); // The vector height 52 | double dimension = src[0].size(); // The vector width 53 | 54 | vector dimensionMaxValue(dimension, 0); 55 | dst = vector>(K, vector(src[0].size(), 0)); 56 | 57 | srand(time(NULL)); 58 | 59 | if( src[0].size() != dst[0].size()){ // Determind the dimension between the input data and the output data is same or not 60 | 61 | cout<<"The input data and the output need be the same dimension\n"; 62 | return false; 63 | } 64 | 65 | if(type == pixkit::clustering::KM_RANDPOS){ // Generate random initial points 66 | 67 | // In default case, the initial point define by the computer using the random function 68 | for(int d = 0; d < dimension; d++){ 69 | dimensionMaxValue[d] = 0.0; 70 | 71 | // Detect the dimension of input database 72 | for(int i = 0; i < vectorSize; i++){ 73 | if(src[i][d] > dimensionMaxValue[d]){ 74 | dimensionMaxValue[d] = src[i][d]; 75 | } 76 | } 77 | } 78 | 79 | for(int i = 0; i < K; i++){ 80 | for(int d = 0; d < dimension; d++){ 81 | dst[i][d] = rand() % (int)dimensionMaxValue[d]; 82 | } 83 | } 84 | } 85 | 86 | vector oldlength(dst.size(),1); 87 | vector newlength(dst.size(),0); 88 | vector> sum(dst.size(),vector(dst[0].size(),0)); // Calculate the sum 89 | 90 | if(iter != -1){ 91 | 92 | while (iter !=0 ){ 93 | 94 | calculate(src,dst,sum); // Calculate new mean value 95 | 96 | for(int i=0;i 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #ifndef __PIXKIT_ML_HPP__ 17 | #define __PIXKIT_ML_HPP__ 18 | 19 | namespace pixkit{ 20 | 21 | namespace clustering{ 22 | 23 | /** 24 | * @brief Clustering 25 | * @brief paper: V. K. Dehariya, S. K. Shrivastava, R. C. Jain, "Clustering Of Image Data Set Using K-Means And Fuzzy K-Means Algorithms", IEEE International Conf. of CICN, 2010 26 | * 27 | * @author HuangYu Liu (yf6204220@hotmail.com) 28 | * @date Jan. 3, 2014 29 | * 30 | * @param src: Input data. The data type is vector. 31 | * @param dst: Output data. The data type is vector. 32 | * @param seedNum: How many seed do the user want to spread 33 | * @param K: How many universe do the user want to cluster, for instance, if you want to segment the input data to two different parts, then you must set the argument to 2. 34 | * @param m: The fuzzy coefficient. If set this argument close to 1.0, then the cluster effect like K-Means clustering. 35 | * @param iterNum: Set the iteration number. If set this argument bigger, then the error of result will be much smaller. 36 | * @param initialPosi: The argument is relate to the type, which is the next argument. The initial position can define by the user or computer. 37 | * @param FUZZYCM_TYPE: If user set the type to 1, then the initial position will define by the user. If user set the type to 2, then the initial position will define random by the computer. 38 | * @return bool: true: successful, false: failure 39 | */ 40 | enum FUZZYCM_TYPE{FUZZYCM_USERDEFINEPOS, FUZZYCM_RANDPOS}; 41 | bool fuzzyCMeans(const std::vector> &src, std::vector> &dst, const int seedNum, const int K, const double m, const int iterNum, std::vector> &initialPosi = std::vector>(), pixkit::clustering::FUZZYCM_TYPE type = FUZZYCM_RANDPOS,bool debug=false); 42 | 43 | /** 44 | * @brief clustering 45 | * 46 | * @auther ChienYu Chen (s941314g@yahoo.com.tw) 47 | * @date Jan. 24, 2014 48 | * 49 | * @param src: Input data. The data type is vector. 50 | * @param dst: Output data. The data type is vector. 51 | * @param K: How many universe do the user want to cluster, for instance, if you want to segment the input data to two different parts, then you must set the argument to 2. 52 | * @param iter: Set the iteration number. If set this argument bigger, then the error of result will be much smaller. 53 | * @param type: The initial position can define by the user or computer. 54 | * @param KM_TYPE: If user set the type to 1, then the initial position will define by the user. If user set the type to 2, then the initial position will define random by the computer. 55 | */ 56 | enum KM_TYPE{KM_USERDEFINEPOS, KM_RANDPOS}; 57 | bool KMeans(std::vector> &src, std::vector> &dst, int K, int iter, pixkit::clustering::KM_TYPE type = KM_RANDPOS); 58 | } 59 | 60 | namespace classification{ 61 | 62 | struct SSample{ 63 | std::string classnumber; // class 64 | std::vector features; 65 | }; 66 | 67 | bool KNN(std::vector &sample,const std::vector &dataset,int k); 68 | bool FKNN(std::vector &sample,const std::vector &dataset,int k); 69 | bool FRNN(std::vector &sample,const std::vector &dataset); 70 | 71 | } 72 | 73 | namespace mldata{ 74 | 75 | void readTrain(std::vector& data, const std::string file); 76 | void readTest(std::vector& data, const std::string file); 77 | void write(std::vector& data, const std::string file); 78 | 79 | } 80 | } 81 | #endif -------------------------------------------------------------------------------- /modules/pixkit-image/src/MSRCP2014/MSRCP2014.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | MSRCP 3 | */ 4 | # include 5 | # include 6 | # include 7 | # include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include "../../include/pixkit-image.hpp" 13 | 14 | 15 | bool SimplestColorBalance(cv::Mat ori,float upperthresh,float lowerthresh){ 16 | 17 | int totalarea=ori.rows*ori.cols; 18 | upperthresh=upperthresh*totalarea; 19 | lowerthresh=lowerthresh*totalarea; 20 | cv::Mat sorted_ori; 21 | cv::Mat reshapeOri; 22 | reshapeOri=ori.reshape(0,1); 23 | cv::sort(reshapeOri,sorted_ori,CV_SORT_ASCENDING ); 24 | 25 | int Vmin=(sorted_ori.at(lowerthresh)); 26 | int Vmax=sorted_ori.at((ori.rows*ori.cols-1)-upperthresh); 27 | for (int i=0; i(i,j)(i,j)=0; 30 | else if(ori.at(i,j)>Vmax)ori.at(i,j)=255; 31 | else ori.at(i,j)= (ori.at(i,j)-Vmin)*255./(Vmax-Vmin); 32 | 33 | } 34 | } 35 | 36 | return 1; 37 | 38 | } 39 | bool pixkit::enhancement::local::MSRCP2014(const cv::Mat &src,cv::Mat &dst){ 40 | 41 | ///// exceptions 42 | if(src.type()!=CV_8UC3){ 43 | CV_Assert(false); 44 | } 45 | 46 | int Nscale=3; 47 | int RetinexScales[3]={7,81,241}; 48 | float weight = 1.0f / Nscale; 49 | int NumChannel=src.channels(); 50 | cv::Mat GaussianOut; 51 | 52 | //zeros 53 | dst=cv::Mat::zeros(src.rows,src.cols,CV_8UC3); 54 | cv::Mat Intensity=cv::Mat::zeros(src.rows,src.cols,CV_8UC1); 55 | cv::Mat MSR_Nor; 56 | cv::Mat RetinexOut=cv::Mat::zeros(src.rows,src.cols,CV_32FC1); 57 | 58 | 59 | 60 | /* 61 | compute intensity channel 62 | */ 63 | for (int i=0; i(i)[j]= (src.at(i,j)[0]+src.at(i,j)[1]+src.at(i,j)[2])/3; 66 | } 67 | } 68 | 69 | //compute 3-scale retinex output, log domain 70 | for (int scale = 0; scale <3; scale++ ){ 71 | cv::Size a(RetinexScales[scale],RetinexScales[scale]); 72 | cv::GaussianBlur(Intensity,GaussianOut,a,(int)RetinexScales[scale]); 73 | float zero=0; 74 | for (int i = 0; i < src.rows; i++ ){ 75 | for (int j = 0; j < src.cols; j++ ){ 76 | RetinexOut.ptr(i)[j] += 1/3. *( log((float)Intensity.ptr(i)[j]+1)-log((float)GaussianOut.ptr(i)[j]+1.)); 77 | } 78 | } 79 | } 80 | 81 | 82 | //SimplestColorBalance, see IPOL for more information 83 | cv::normalize(RetinexOut,RetinexOut,0,255,32); 84 | SimplestColorBalance(RetinexOut,0.01,0.01); 85 | RetinexOut.convertTo(RetinexOut,CV_8UC1); 86 | MSR_Nor=RetinexOut.clone(); 87 | 88 | 89 | //According to the reference paper(page 79,Algorithm 2), output the final image. 90 | double factor, max; 91 | cv::Mat tempshow=cv::Mat::zeros(src.rows,src.cols,CV_32FC3); 92 | for (int i = 0; i < src.rows; i ++ ){ 93 | for (int j = 0; j < src.cols; j ++ ){ 94 | int B=0; 95 | float A=0; 96 | B=0; 97 | A=0; 98 | if(src.at(i,j)[0]>B)B=src.at(i,j)[0]; 99 | if(src.at(i,j)[1]>B)B=src.at(i,j)[1]; 100 | if(src.at(i,j)[2]>B)B=src.at(i,j)[2]; 101 | 102 | float temp=(src.at(i,j)[0]+src.at(i,j)[1]+src.at(i,j)[2])/3.; //intensity channel(before /3) 103 | 104 | if(temp <= 1.) temp=1.; 105 | factor=MSR_Nor.at(i,j)/ temp; 106 | if( factor > 3.) factor=3.; 107 | tempshow.at(i,j)[2]=factor* src.at(i,j)[2]; 108 | tempshow.at(i,j)[1]=factor*src.at(i,j)[1]; 109 | tempshow.at(i,j)[0]=factor*src.at(i,j)[0]; 110 | if( tempshow.at(i,j)[0] > 255. || tempshow.at(i,j)[1] > 255. ||tempshow.at(i,j)[0] > 255.) 111 | { 112 | max=src.at(i,j)[2]; 113 | if(src.at(i,j)[1]> max) max=src.at(i,j)[1]; 114 | if( src.at(i,j)[0] > max) max=src.at(i,j)[0]; 115 | factor= 255. /max; 116 | tempshow.at(i,j)[2]=factor*src.at(i,j)[2]; 117 | tempshow.at(i,j)[1]=factor*src.at(i,j)[1]; 118 | tempshow.at(i,j)[0]=factor*src.at(i,j)[0]; 119 | } 120 | 121 | } 122 | } 123 | 124 | std::vector tt(3); 125 | cv::Mat finalshow; 126 | cv::split(tempshow,tt); 127 | tt[0].convertTo(tt[0],CV_8UC1); 128 | tt[1].convertTo(tt[1],CV_8UC1); 129 | tt[2].convertTo(tt[2],CV_8UC1); 130 | cv::merge(tt,finalshow); 131 | dst=finalshow.clone(); 132 | 133 | return true; 134 | } 135 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Online version please go
2 | 3 | 4 | The initial form of CONTRIBUTING.txt comes from scikit-image
5 | 6 | 7 | Development process 8 | =================== 9 | 10 | Here's the long and short of it: 11 | 12 | 1. If you are a first-time contributor: 13 | --------------------------------------- 14 | 15 | * Sign up for github (if you have no accounts): [Go here](https://github.com/) 16 | 17 | * Be a fork: 18 | 19 | Go to <[pixkit](https://github.com/yunfuliu/pixkit)> 20 | and click the "fork" button to create your own copy of the project 21 | (called ``origin`` remote). 22 | 23 | * Clone the project to your local computer: 24 | 25 | Download GitHub for your system from 26 |
27 | Login and clone the project. 28 | 29 | * Add upstream repository: 30 | 31 | To keep track of the original repository, you need to add 32 | another remote named ``upstream``.
33 | 34 | Right click on the project after you clone it, and click "open a shell here" 35 | ``git remote add upstream https://github.com/yunfuliu/pixkit.git`` 36 | 37 | Checkout by ``git remote`` 38 | 39 | * Now, you have remote repositories named: 40 | 41 | - ``upstream``, which refers to the original 'pixkit' repository 42 | - ``origin``, which refers to your personal fork
43 | 44 | *NOTE* 45 | 46 | About 'remote', please go 47 | for details. 48 | 49 | 2. Develop your contribution: 50 | ----------------------------- 51 | Following operations are needed to keep track of the original repo. 52 | 53 | * Pull the latest changes from ``upstream``: 54 | 55 | ``git checkout master``
56 | ``git pull upstream master`` 57 | 58 | * Go to the GUI, and create a new branch for the feature you want 59 | to work on. Since the branch name will appear in the merge message, 60 | use a sensible name such as 'add-halftoning' (add funcationality of 61 | halftoning): 62 | 63 | *NOTE* 64 | 65 | Please base upon the branch 'master' to create your new branch, 66 | rather than 'release'. 67 | Also, branch name 'add-???' for adding new functionality; 68 | branch name 'bug#???' for debuging. 69 | 70 | * Commit locally as you progress (``git add`` and ``git commit``). You can also do these on GitHub GUI. 71 | 72 | 3. Work on your contributions: 73 | ----------------------------- 74 | 75 | * To contribute a new functionality:
76 | - 1) Define your functions in `./modules/pixkit-NAME/include/pixkit-NAME.hpp`
77 | - 2) Place your source code in `.modules/pixkit-NAME/src/*.cpp`
78 | - 3) Place and organize each of your examples in `./examples-NAME/*` individually. 79 | Notably, please completely test your functions, such as various image sizes, 80 | to make sure it could work correctly on various situstions.
81 | - 4) Explane your functions in [wiki](https://github.com/yunfuliu/pixkit/wiki) with same style. 82 | 83 | 4. To submit your contribution: 84 | ------------------------------- 85 | 86 | * To make sure your contributions are basing upon the state-of-the-art original 87 | pixkit (for consistency), pull the latest changes from ``upstream``: 88 | 89 | ``git checkout master``
90 | ``git pull upstream master`` 91 | 92 | * Make sure your functions still work correctly on each of your examples in 93 | `./examples-NAME/*`. 94 | 95 | * Go on to the GitHub GUI, commit and push (sync) your contributions to cloud. 96 | 97 | * The last step is to send a pull request to merge your contributions into original repo: 98 | - Go to original repo [here](https://github.com/yunfuliu/pixkit). 99 | - Click "Pull Requests". 100 | - Click "New pull request". 101 | - Click "compare across forks", 102 | the **base fork** should be "yunfuliu/pixkit master", and the **head fork** should be yours. 103 | - Create this pull request, and wait for a peer review process for your contributions. 104 | 105 | *NOTE* 106 | 107 | To reviewers: add a short explanation of what a branch did to the merge 108 | message and, if closing a bug, also add "Closes gh-123" where 123 is the 109 | bug number. 110 | 111 | Divergence between 'upstream master' and your feature branch 112 | -------------------------------------------------------------- 113 | 114 | Do *not* ever merge the main branch into yours. If GitHub indicates that the 115 | branch of your Pull Request can no longer be merged automatically, rebase 116 | onto master:: 117 | 118 | ``git checkout master``
119 | ``git pull upstream master``
120 | ``git checkout transform-speedups``
121 | ``git rebase master`` 122 | 123 | If any conflicts occur, fix the according files and continue:: 124 | 125 | ``git add conflict-file1 conflict-file2``
126 | ``git rebase --continue`` 127 | 128 | However, you should only rebase your own branches and must generally not 129 | rebase any branch which you collaborate on with someone else. 130 | 131 | Finally, you must push your rebased branch:: 132 | 133 | ``git push --force origin transform-speedups`` 134 | 135 | (If you are curious, here's a further discussion on the 136 | `dangers of rebasing `__. 137 | Also see this `LWN article `__.) 138 | 139 | 140 | Guidelines 141 | ========== 142 | 143 | * All code should be documented, to the wiki
144 | 145 | 146 | * For new functionality, always add an example to the corresponding 147 | ./examples-NAME/ folder. 148 | 149 | * No changes should be committed without review. Ask 150 | [Yun-Fu Liu](yunfuliu@gmail.com) if you get no response to your pull request. 151 | **Never merge your own pull request.** 152 | 153 | -------------------------------------------------------------------------------- /modules/pixkit-image/src/MS_SSIM/MS_SSIM.cpp: -------------------------------------------------------------------------------- 1 | #include "../../include/pixkit-image.hpp" 2 | 3 | bool downSample(cv::Mat &src, cv::Mat &dst) 4 | { 5 | ////////////////////////////////////////////////////////////////////////// 6 | // exception 7 | if(src.empty()||dst.empty()){ 8 | CV_Error(CV_HeaderIsNull,"[downSample] image is empty"); 9 | return false; 10 | } 11 | if((src.rows/2) != dst.rows || (src.cols/2) != dst.cols){ 12 | CV_Error(CV_BadNumChannels,"[downSample] sizes of two images are not multiples of 2"); 13 | return false; 14 | } 15 | if(src.type()!=CV_8U || dst.type()!=CV_8U){ 16 | CV_Error(CV_BadNumChannels,"[downSample] image should be grayscale"); 17 | return false; 18 | } 19 | 20 | ////////////////////////////////////////////////////////////////////////// 21 | double LL_mask[5][5] = { 22 | 0.015625, -0.03125, -0.09375, -0.03125, 0.015625, 23 | -0.03125, 0.0625, 0.1875, 0.0625, -0.03125, 24 | -0.09375, 0.1875, 0.5625, 0.1875, -0.09375, 25 | -0.03125, 0.0625, 0.1875, 0.0625, -0.03125, 26 | 0.015625, -0.03125, -0.09375, -0.03125, 0.015625 27 | }; 28 | int filterHeight=5, filterWidth=5, wd_size=filterHeight/2*2; 29 | 30 | cv::Mat ext_src; 31 | ext_src.create(src.rows+filterHeight/2*2, src.cols+filterWidth/2*2, 0); 32 | 33 | // Boundary Extension ////////////////////////////// 34 | //WdImage((Height+wd_size)x(Width+wd_size)) <- Input(HeightxWidth) 35 | for(int i=0; i(g); 67 | } 68 | } 69 | return true; 70 | } 71 | 72 | float pixkit::qualityassessment::MS_SSIM(const cv::Mat &src1, const cv::Mat &src2, int HVSsize) 73 | { 74 | ////////////////////////////////////////////////////////////////////////// 75 | // exception 76 | if(src1.empty()||src2.empty()){ 77 | CV_Error(CV_HeaderIsNull,"[qualityassessment::MS_SSIM] image is empty"); 78 | } 79 | if(src1.cols != src2.cols || src1.rows != src2.rows){ 80 | CV_Error(CV_StsBadArg,"[qualityassessment::MS_SSIM] sizes of two images are not equal"); 81 | } 82 | if(src1.type()!=CV_8U || src2.type()!=CV_8U){ 83 | CV_Error(CV_BadNumChannels,"[qualityassessment::MS_SSIM] image should be grayscale"); 84 | } 85 | if(src1.cols < 32 || src1.rows < 32 || src2.cols < 32 || src2.rows < 32){ 86 | CV_Error(CV_BadNumChannels,"[qualityassessment::MS_SSIM] sizes of two images should be greater than 32x32"); 87 | } 88 | 89 | ////////////////////////////////////////////////////////////////////////// 90 | // initialize the ssim weights of each scales 91 | int HalfSize = static_cast(HVSsize/2); 92 | double alpha = 0.1333; 93 | std::vector< double >beta(5); 94 | std::vector< double >gamma(5); 95 | beta[0] = gamma[0] = 0.0448; 96 | beta[1] = gamma[1] = 0.2856; 97 | beta[2] = gamma[2] = 0.3001; 98 | beta[3] = gamma[3] = 0.2363; 99 | beta[4] = gamma[4] = alpha; 100 | cv::Mat tsrc1, tsrc2; 101 | tsrc1 = src1.clone(); 102 | tsrc2 = src2.clone(); 103 | 104 | /////////////////////////////////////////////////// 105 | // HVS filter 106 | std::vector< std::vector > gaussianFilter( HVSsize, std::vector(HVSsize) ); 107 | double sum = 0, STD = 1.5 ; 108 | 109 | for (int i=-HalfSize; i<=HalfSize; i++){ 110 | for (int j=-HalfSize; j<=HalfSize; j++){ 111 | gaussianFilter[i+HalfSize][j+HalfSize] = exp( -1 * (i*i+j*j) / (2*STD*STD) ); 112 | sum += gaussianFilter[i+HalfSize][j+HalfSize]; 113 | } 114 | } 115 | 116 | // Normalize to 0~1 117 | for (int i=-HalfSize; i<=HalfSize; i++){ 118 | for (int j=-HalfSize; j<=HalfSize; j++){ 119 | gaussianFilter[i+HalfSize][j+HalfSize] /= sum; 120 | } 121 | } 122 | ///////////////////////////////////////////////////// 123 | double SSIMresult=1, luminance=0, contrast=0, structure=0; 124 | double *lu_co_st = new double [3]; 125 | 126 | for (int m=0; m<5; m++){ 127 | 128 | // mssim calculation 129 | pixkit::qualityassessment::MSSIM(tsrc1, tsrc2, HVSsize, &lu_co_st[0]); 130 | 131 | contrast = pow(lu_co_st[1], beta[m]); 132 | structure = pow(lu_co_st[2], gamma[m]); 133 | 134 | if (m==4){ 135 | luminance = pow(lu_co_st[0], alpha); 136 | SSIMresult *= (luminance * contrast * structure); 137 | }else{ 138 | SSIMresult *= (contrast * structure); 139 | } 140 | ////////////////////////////////////////////////////////////////////////// 141 | 142 | // down sample 143 | cv::Mat rsrc2, rsrc1; 144 | rsrc1 = tsrc1.clone(); 145 | rsrc2 = tsrc2.clone(); 146 | 147 | tsrc1.create(rsrc1.rows/2, rsrc1.cols/2, rsrc1.type()); 148 | tsrc2.create(rsrc2.rows/2, rsrc2.cols/2, rsrc2.type()); 149 | 150 | downSample(rsrc1, tsrc1); 151 | downSample(rsrc2, tsrc2); 152 | } 153 | delete [] lu_co_st; 154 | return SSIMresult; 155 | } 156 | 157 | 158 | 159 | -------------------------------------------------------------------------------- /modules/pixkit-image/test/test_halftoning.cpp: -------------------------------------------------------------------------------- 1 | // opencv related headers 2 | #include 3 | #include 4 | 5 | // system related headers 6 | #include 7 | #include 8 | 9 | // pixkit-image 10 | #include "../include/pixkit-image.hpp" 11 | 12 | ////////////////////////////////////////////////////////////////////////// 13 | // others 14 | void describe(std::string str){ 15 | std::cout << "\t" << str << "\t... "; 16 | } 17 | int checkout(bool input,bool compare){ 18 | if(compare==input){ 19 | std::cout << "ok" << std::endl; 20 | return 0; 21 | }else{ 22 | std::cout << "x" << std::endl; 23 | return 1; 24 | } 25 | } 26 | 27 | ////////////////////////////////////////////////////////////////////////// 28 | bool help(){ 29 | 30 | std::cout << "[usage]: .exe [delay]" << std::endl 31 | << "\tdelay:\t>0: show demo images with [delay] ms" << std::endl 32 | << "\t\t0: show no image" << std::endl; 33 | return false; 34 | } 35 | 36 | ////////////////////////////////////////////////////////////////////////// 37 | ///// functions 38 | typedef bool (*predicate)(cv::Mat&,cv::Mat&); 39 | std::vector function_vec; 40 | bool dd_GuoLiu2009(cv::Mat &src,cv::Mat &dst){ 41 | describe("[pixkit::halftoning::dotdiffusion::GuoLiu2009]"); 42 | return pixkit::halftoning::dotdiffusion::GuoLiu2009(src,dst,8); 43 | } 44 | bool dd_NADD2013(cv::Mat &src,cv::Mat &dst){ 45 | describe("[pixkit::halftoning::dotdiffusion::NADD2013]"); 46 | pixkit::halftoning::dotdiffusion::CNADDCT cct; 47 | cct.generation(cv::Size(256,256)); 48 | return pixkit::halftoning::dotdiffusion::NADD2013(src,dst,cct); 49 | } 50 | ///// construction 51 | void construct(){ 52 | function_vec.push_back(dd_GuoLiu2009); 53 | function_vec.push_back(dd_NADD2013); 54 | } 55 | 56 | 57 | int main(int argc,char* argv[]){ 58 | 59 | 60 | if(argc<2){ 61 | return help(); 62 | } 63 | short delay = -1; // default 64 | if(argc>1){ 65 | delay = atoi(argv[1]); 66 | } 67 | srand(time(NULL)); 68 | 69 | 70 | ////////////////////////////////////////////////////////////////////////// 71 | ///// initial 72 | construct(); 73 | cv::Mat src,dst; 74 | int nCount = 0; // calc the counts of errors 75 | 76 | 77 | ////////////////////////////////////////////////////////////////////////// 78 | ///// ** (test) empty input, [output] should be false 79 | std::cout << "(test) empty input, [output] should be false" << std::endl; 80 | for(int k=0;k0){ 94 | cv::imshow("output",dst); 95 | cv::waitKey(delay); 96 | } 97 | } 98 | std::cout << std::endl << std::endl; 99 | 100 | 101 | ////////////////////////////////////////////////////////////////////////// 102 | ///// ** (test) check channel types 103 | std::cout << "(test) check channel types" << std::endl; 104 | int chennel_types[]={CV_8UC1, CV_8UC2, CV_8UC3, CV_8UC4, CV_8S, CV_16U, CV_16S, CV_32S, CV_32F, CV_64F}; // 10 types 105 | for(int k=0;k input_sizes; 120 | input_sizes.push_back(cv::Size(0,0)); // false 121 | input_sizes.push_back(cv::Size(0,1)); // false 122 | input_sizes.push_back(cv::Size(1,0)); // false 123 | input_sizes.push_back(cv::Size(1,1)); // true 124 | input_sizes.push_back(cv::Size(100,200)); // true 125 | input_sizes.push_back(cv::Size(200,100)); // true 126 | input_sizes.push_back(cv::Size(1001,99)); // true 127 | input_sizes.push_back(cv::Size(501,277)); // true 128 | for(int k=0;k0){ 135 | cv::imshow("output",dst); 136 | cv::waitKey(delay); 137 | } 138 | } 139 | } 140 | std::cout << std::endl << std::endl; 141 | 142 | 143 | ////////////////////////////////////////////////////////////////////////// 144 | ///// ** (test) check output should be black/white 145 | std::cout << "(test) check output should be black/white" << std::endl; 146 | int error_pixel; 147 | for(int k=0;k0){ 167 | cv::imshow("output",dst); 168 | cv::waitKey(delay); 169 | } 170 | } 171 | } 172 | std::cout << std::endl << std::endl; 173 | 174 | 175 | ////////////////////////////////////////////////////////////////////////// 176 | std::cout << nCount << " errors." << std::endl; 177 | return nCount; 178 | } -------------------------------------------------------------------------------- /modules/pixkit-image/src/qualityassessment/IW_SSIM.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | //opencv headers 5 | #include 6 | #include 7 | #include "..\..\include\pixkit-image.hpp" 8 | /////////////////////////////////////////////////////////////////////////////////////////////////////// 9 | 10 | using namespace std; 11 | using namespace cv; 12 | 13 | //calculate mean value of each patch 14 | void patchmean(const cv::Mat &src,cv::Mat &mean){ 15 | 16 | for(int i=1;i(i)[j]+=src.ptr(i+fr)[j+fc]; 24 | Np++; 25 | } 26 | } 27 | mean.ptr(i)[j]/=Np; 28 | } 29 | } 30 | } 31 | 32 | //funtion to calculate patchsigama 33 | void patchsigma(const cv::Mat &src,const cv::Mat &mean,cv::Mat &sigama){ 34 | 35 | cv::Mat tmp=cv::Mat::zeros(src.rows,src.cols,CV_64FC1); 36 | for(int i=1;i(i)[j]+=pow(src.ptr(i+fc)[j+fr],2); 44 | Np++; 45 | } 46 | } 47 | tmp.ptr(i)[j]/=Np;//9 is the pixel numbers of each patch 48 | sigama.ptr(i)[j]=sqrt(tmp.ptr(i)[j]-pow(mean.ptr(i)[j],2)); 49 | } 50 | } 51 | } 52 | 53 | //funtion to calculate the covariance of X and Y 54 | void covarianceXY(const cv::Mat &X,const cv::Mat &Y,const cv::Mat &meanX,const cv::Mat &meanY,cv::Mat &covariance){ 55 | 56 | for(int i=1;i(i)[j]+=(X.ptr(i+fr)[j+fc]*Y.ptr(i+fr)[j+fc]); 63 | Np++; 64 | } 65 | } 66 | covariance.ptr(i)[j]=covariance.ptr(i)[j]/Np-meanX.ptr(i)[j]*meanY.ptr(i)[j]; 67 | } 68 | } 69 | } 70 | 71 | //function to calculate l Matrix 72 | void calculate_l(const cv::Mat &meanX,const cv::Mat &meanY,cv::Mat &l){ 73 | int L=255; 74 | double K1=0.01; 75 | double C1=pow(K1*L,2); 76 | 77 | for(int i=1;i(i)[j]=(2*meanX.ptr(i)[j]*meanY.ptr(i)[j]+C1)/(pow(meanX.ptr(i)[j],2)+pow(meanY.ptr(i)[j],2)+C1); 80 | } 81 | } 82 | } 83 | 84 | //function to calculate c Matrix 85 | void calculate_c(const cv::Mat &sigmaX,const cv::Mat &sigmaY,cv::Mat &c){ 86 | int L=255; 87 | double K2=0.03; 88 | double C2=pow(K2*L,2); 89 | for(int i=1;i(i)[j]=(2*sigmaX.ptr(i)[j]*sigmaY.ptr(i)[j]+C2)/(pow(sigmaX.ptr(i)[j],2)+pow(sigmaY.ptr(i)[j],2)+C2); 92 | } 93 | } 94 | } 95 | 96 | //function to calculate s Matrix 97 | void calculate_s(const cv::Mat &sigmaX,const cv::Mat &sigmaY,const cv::Mat &covariance,cv::Mat &s){ 98 | int L=255; 99 | double K2=0.03; 100 | double C2=pow(K2*L,2); 101 | double C3=C2/2.; 102 | 103 | for(int i=1;i(i)[j]=(covariance.ptr(i)[j]+C3)/(sigmaX.ptr(i)[j]*sigmaY.ptr(i)[j]+C3); 106 | } 107 | } 108 | } 109 | 110 | ////////////////////////////////////////////////////////////////////////////////////////////////// 111 | float *IW_SSIMj(const cv::Mat &X,const cv::Mat &Y,float *SSIMj){ 112 | 113 | int scale_j=4; 114 | //build 5 scale of original signal X and distorted signal Y 115 | cv::vector ScaleX,ScaleY; 116 | cv::buildPyramid(X,ScaleX,scale_j); 117 | cv::buildPyramid(Y,ScaleY,scale_j); 118 | 119 | for(int jth=0;jth(i)[j]*c.ptr(i)[j]*s.ptr(i)[j]); 148 | Nj++; 149 | } 150 | } 151 | SSIMj[jth]/=Nj; 152 | } 153 | return SSIMj; 154 | } 155 | 156 | float pixkit::qualityassessment::IW_SSIM(const cv::Mat &src1,const cv::Mat &src2){ 157 | 158 | if(src1.type()!=CV_8UC1 || src2.type()!=CV_8UC1 ){CV_Assert(false);} 159 | //initialize the value of each scale 160 | float SSIMj[5]={0,0,0,0,0}; 161 | //given constant of beta 162 | float betaj[5]={0.0448,0.2856,0.3001,0.2363,0.1333}; 163 | // calculate the SSIM value of each scale 164 | IW_SSIMj(src1,src2,SSIMj); 165 | 166 | // get IW_SSIM 167 | float IW_SSIM=1.; 168 | for(int i=0;i<5;i++){ 169 | IW_SSIM*= pow(SSIMj[i],betaj[i]); 170 | } 171 | return IW_SSIM; 172 | } 173 | 174 | -------------------------------------------------------------------------------- /modules/pixkit-ml/src/fuzzyCMeans.cpp: -------------------------------------------------------------------------------- 1 | #include "../include/pixkit-ml.hpp" 2 | #include 3 | #ifdef _OPENMP 4 | #include 5 | #else 6 | #define omp_get_thread_num() 0 7 | #endif 8 | 9 | using namespace std; 10 | 11 | //Calculate the euclidean distance between the two points 12 | double radius(const vector> &src, const int c1, const vector> &randomPosi, const int k1){ 13 | double euclideanDistance = 0.0; 14 | 15 | //Calculate the euclidean distance in multi-dimension 16 | for(int d = 0; d < src[0].size(); d++){ 17 | euclideanDistance += fabs((double)(src[c1][d] - randomPosi[k1][d])); 18 | } 19 | 20 | return euclideanDistance; 21 | } 22 | bool pixkit::clustering::fuzzyCMeans(const std::vector> &src, std::vector> &dst, const int seedNum, const int K, const double m, const int iterNum, std::vector> &initialPosi, pixkit::clustering::FUZZYCM_TYPE type, bool debug){ 23 | 24 | ////////////////////////////////////////////////////////////////////////// 25 | ///// exceptions 26 | if(iterNum <= 0){ 27 | cout << "The iteration number must setting greater than 0" << endl; 28 | return false; 29 | }else if(K <= 0){ 30 | cout << "The parameter K must setting greater than 0" << endl; 31 | return false; 32 | }else if(seedNum <= 0){ 33 | cout << "The seed number must setting greater than 0" << endl; 34 | return false; 35 | }else if(m <= 1.0){ 36 | cout << "The parameter m must setting greater than 1.0" << endl; 37 | return false; 38 | }else if(src.size() <= 0 || src[0].size() <= 0){ 39 | cout << "Please input the data" << endl; 40 | return false; 41 | } 42 | 43 | ////////////////////////////////////////////////////////////////////////// 44 | ///// process 45 | int i, j, k, d, s; 46 | double vectorSize = src.size(); // The vector height 47 | double dimension = src[0].size(); // The vector width 48 | double minValue = 50000.0; // The minimum distance 49 | double distance = 0.0; 50 | srand(time(NULL)); 51 | 52 | // Destination vector size defined by the source vector size 53 | dst = vector>(vectorSize, vector(dimension, 0)); 54 | 55 | vector weightSum(vectorSize, 0); 56 | 57 | vector srcLabel(vectorSize, 0); 58 | 59 | vector> colorSum(K, vector(dimension, 0)); 60 | vector> sum(K, vector(dimension, 0)); 61 | 62 | vector> fcmWeight(vectorSize, vector(K, 0)); 63 | 64 | vector dimensionMaxValue(dimension, 0); 65 | vector> fcmError(seedNum, vector(K, 0)); 66 | 67 | vector minError(seedNum, 9999999999); 68 | 69 | for(s = 0; s < seedNum; s++){ 70 | if(type == 1){ 71 | initialPosi = vector>(K, vector(dimension, 0)); 72 | 73 | // In default case, the initial point define by the computer using the random function 74 | for(d = 0; d < dimension; d++){ 75 | dimensionMaxValue[d] = 0.0; 76 | 77 | // Detect the dimension of input database 78 | for(i = 0; i < vectorSize; i++){ 79 | if(src[i][d] > dimensionMaxValue[d]){ 80 | dimensionMaxValue[d] = src[i][d]; 81 | } 82 | } 83 | } 84 | 85 | // Starting to generate the random initial point 86 | #ifdef _OPENMP 87 | #pragma omp parallel for 88 | #endif 89 | for(i = 0; i < K; i++){ 90 | for(d = 0; d < dimension; d++){ 91 | initialPosi[i][d] = rand() % (int)dimensionMaxValue[d]; 92 | } 93 | } 94 | } 95 | 96 | int iter; 97 | for(iter = 0; iter < iterNum; iter++){ 98 | // Initialize 99 | for(i = 0; i < K; i++){ 100 | for(d = 0; d < dimension; d++){ 101 | colorSum[i][d] = 0.0; 102 | sum[i][d] = 0.0; 103 | } 104 | } 105 | 106 | for(i = 0; i < vectorSize; i++){ 107 | weightSum[i] = 0.0; 108 | } 109 | 110 | double demSum = 0.0, dstRaidusValue; 111 | 112 | // Fuzzy C-Means Clustering 113 | for(i = 0; i < vectorSize; i++){ 114 | minValue = 50000.0; 115 | 116 | for(k = 0; k < K; k++){ 117 | dstRaidusValue = radius(src, i, initialPosi, k); 118 | 119 | demSum = 0.0; 120 | for(int kk = 0; kk < K; kk++){ 121 | distance = radius(src, i, initialPosi, kk); 122 | demSum += pow((dstRaidusValue / (distance + 0.0000000001)), 2.0/(m-1.0)); 123 | } 124 | // Calculate the relationship from this destinate point to the other points. 125 | fcmWeight[i][k] = 1.0/(demSum + 0.0000000001); 126 | } 127 | } 128 | 129 | for(i = 0; i < vectorSize; i++){ 130 | for(d = 0; d < dimension; d++){ 131 | for(k = 0; k < K; k++){ 132 | // Calculate the destinate point 133 | colorSum[k][d] += src[i][d] * pow(fcmWeight[i][k], m); 134 | 135 | // Calculate the sum of the point to the other point 136 | sum[k][d] += pow(fcmWeight[i][k], m); 137 | } 138 | } 139 | } 140 | 141 | // Calculate the new focus 142 | for(k = 0; k < K; k++){ 143 | for(d = 0; d < dimension; d++){ 144 | initialPosi[k][d] = colorSum[k][d] / (sum[k][d] + 0.0000000001); 145 | } 146 | } 147 | } 148 | 149 | // Find which points is closet to the initial point or focus point, then label it. 150 | for(int i = 0; i < vectorSize; i++){ 151 | minValue = 50000.0; 152 | 153 | for(k = 0; k < K; k++){ 154 | distance = radius(src, i, initialPosi, k); 155 | 156 | if(distance < minValue){ 157 | minValue = distance; 158 | srcLabel[i] = k; 159 | } 160 | } 161 | } 162 | 163 | // Calculate the error 164 | for(i = 0; i < vectorSize; i++){ 165 | for(d = 0; d < dimension; d++){ 166 | fcmError[s][srcLabel[i]] += fabs((double)(src[i][d] - initialPosi[srcLabel[i]][d])); 167 | } 168 | } 169 | } 170 | 171 | // Find the minimum error 172 | for(i = 0; i < seedNum; i++){ 173 | for(k = 0; k < K; k++){ 174 | if(fcmError[i][k] > 0.0){ 175 | if(fcmError[i][k] < minError[i]){ 176 | minError[i] = fcmError[i][k]; 177 | } 178 | } 179 | } 180 | } 181 | 182 | if(debug){ 183 | cout << "=========== Minimum Error ===========" << endl; 184 | for(i = 0; i < seedNum; i++){ 185 | cout << "Seed index = " << i << " || Error: " << (double)minError[i] << endl; 186 | } 187 | cout << "=====================================" << endl; 188 | } 189 | 190 | // Output the Results 191 | for(i = 0; i < vectorSize; i++){ 192 | for(d = 0; d < dimension; d++){ 193 | dst[i][d] = colorSum[srcLabel[i]][d] / sum[srcLabel[i]][d]; 194 | } 195 | } 196 | return true; 197 | } -------------------------------------------------------------------------------- /modules/pixkit-image/src/enhancement/WangZhengHuLi2013/WangZhengHuLi2013.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "../../../include/pixkit-image.hpp" 3 | bool Mirror_Reflect(const cv::Mat ori,cv::Mat &ret,int Pixel){ 4 | 5 | int height=ori.rows; 6 | int width=ori.cols; 7 | int new_height=height+Pixel*2; 8 | int new_width=width+Pixel*2; 9 | ret.create(new_height,new_width,ori.type()); 10 | 11 | //set the ori-iimage to the center area 12 | for(int i=0;i(i+Pixel,j+Pixel)=ori.at(i,j); 15 | } 16 | } 17 | 18 | //left-right reflect 19 | for(int i=0;i((i+Pixel),j)= 24 | ret.at(i+Pixel,Pixel*2-j-1); 25 | //right reflect 26 | ret.at(i+Pixel,+width+Pixel+j)= 27 | ret.at(i+Pixel,width+Pixel-1-j); 28 | } 29 | } 30 | 31 | //treat the result of left-right reflect as the input of up-down reflect 32 | for(int j=0;j(i,j)=ret.at((Pixel*2-i-1),j); 36 | ret.at((height+Pixel+i),j)=ret.at((height+Pixel-1-i),j); 37 | } 38 | } 39 | return 1; 40 | } 41 | bool pixkit::enhancement::local::WangZhengHuLi2013(const cv::Mat &ori,cv::Mat &ret){ 42 | if(ori.type()!=CV_8UC3){ 43 | printf("The type of input image should be CV_8UC3.\n"); 44 | CV_Assert(false); 45 | } 46 | std::vector HSV(3); 47 | cv::Mat_ Result=cv::Mat::zeros(ori.rows,ori.cols,ori.type()); 48 | cv::Mat_ reflectance_f=cv::Mat::zeros(ori.rows,ori.cols,CV_32FC1); //equation (13) 49 | cv::Mat_ L1g=cv::Mat::zeros(ori.rows,ori.cols,CV_32FC1); //equation (14) 50 | cv::Mat_ Lm=cv::Mat::zeros(ori.rows,ori.cols,CV_8UC1); //equation (22) 51 | cv::Mat_ clv=cv::Mat::zeros(1,256,CV_32FC1); //equation (17) 52 | cv::Mat_ cfz=cv::Mat::zeros(1,256,CV_32FC1); //equation (18) 53 | cv::Mat_ Qhat_matrix=cv::Mat::zeros(256,256,CV_64FC1); //equation (6) 54 | cv::Mat_ illumination=cv::Mat::zeros(ori.rows,ori.cols,CV_8UC1); //equation (12) 55 | int patch=7; //ideal value 56 | int patch_x=patch; 57 | int patch_y=patch; 58 | cv::split(ori,HSV); 59 | double Qhat=0; 60 | 61 | int Gmax=0; 62 | int Gmin=255; 63 | int win=0; 64 | for(int index=0;indexGmax)Gmax=HSV[2].data[index]; 66 | if(HSV[2].data[index](HSV[2].at(n,m),HSV[2].at(n+1,m))++; 82 | Qhat_matrix.at(HSV[2].at(n,m),HSV[2].at(n-1,m))++; 83 | Qhat_matrix.at(HSV[2].at(n,m),HSV[2].at(n,m+1))++; 84 | Qhat_matrix.at(HSV[2].at(n,m),HSV[2].at(n,m-1))++; 85 | Qhat_matrix.at(HSV[2].at(n,m),HSV[2].at(n,m))++; 86 | } 87 | } 88 | 89 | //calculate equation (12) 90 | for(int a=patch_y;a(CenterY,CenterX)>HSV[2].at(y,x))continue; 100 | //G(x,y) HSV[2].at(CenterY,CenterX) 101 | //G(i,j) HSV[2].at(y,x) 102 | 103 | //calculate Q 104 | Qhat=0; 105 | int l=HSV[2].at(y,x); 106 | int k=HSV[2].at(CenterY,CenterX); 107 | for(int i=l-win;i<=l+win;i++){ 108 | if(i<0||i>255){continue;} 109 | Qhat = Qhat + Qhat_matrix.at(k,i); 110 | } 111 | Q=Q+HSV[2].at(y,x)*Qhat/(2*win+1); 112 | W=W+Qhat/(2*win+1); 113 | } 114 | } 115 | 116 | Q=ceil(Q/W); 117 | 118 | //calculate reflectance and illumination, b-patch_x and a-patch_y are due to the margin problem 119 | if(Q==(double)0){ 120 | reflectance_f.at(a-patch_y,b-patch_x)[0]=1; 121 | reflectance_f.at(a-patch_y,b-patch_x)[1]=1; 122 | reflectance_f.at(a-patch_y,b-patch_x)[2]=1; 123 | } 124 | reflectance_f.at(a-patch_y,b-patch_x)[0]=(float)(ori.at(a-patch_y,b-patch_x)[0]/Q); 125 | reflectance_f.at(a-patch_y,b-patch_x)[1]=(float)(ori.at(a-patch_y,b-patch_x)[1]/Q); 126 | reflectance_f.at(a-patch_y,b-patch_x)[2]=(float)(ori.at(a-patch_y,b-patch_x)[2]/Q); 127 | illumination.at(a-patch_y,b-patch_x)=Q; 128 | } 129 | } 130 | 131 | //equation (14) 132 | for(int i=0;i(i,j)=log((float)(illumination.at(i,j)+1)); 135 | 136 | } 137 | } 138 | 139 | 140 | //equation (17) 141 | double L1gTotal = 0; 142 | for(int i=0;i(i,j); 145 | } 146 | } 147 | for(int z=0;z<256;z++){ 148 | float v=z; 149 | double L1gU = 0; 150 | for(int i=0;i=illumination.at(i,j)){ 153 | L1gU=L1gU+L1g.at(i,j); 154 | } 155 | } 156 | } 157 | clv.at(0,z)=L1gU/L1gTotal; 158 | } 159 | 160 | double siTotal=0;//equation (18) 161 | for(int i=0;i<256;i++){ 162 | siTotal=siTotal+log((float)(i+1)); 163 | } 164 | for(int n=0;n<256;n++){ 165 | double temp=0; 166 | for(int m=0;m<=n;m++){ 167 | temp=temp+log((float)(m+1)); 168 | } 169 | cfz.at(0,n)=temp/siTotal; 170 | } 171 | 172 | //equation (20) (21) (22) 173 | for(int i=0;i(0,z)-clv.at(0,illumination.at(i,j)))(0,z)-clv.at(0,illumination.at(i,j))); 179 | Lm.at(i,j)=z; 180 | } 181 | } 182 | } 183 | } 184 | 185 | //equation (23) 186 | for(int channel=0;channel(i,j)[channel]=cv::saturate_cast(reflectance_f.at(i,j)[channel]*Lm.at(i,j)); 190 | } 191 | } 192 | } 193 | ret=Result.clone(); 194 | return 1; 195 | } -------------------------------------------------------------------------------- /modules/pixkit-image/src/enhancement/NRCIR2009/NRCIR2009.cpp: -------------------------------------------------------------------------------- 1 | #define _USE_MATH_DEFINES // for C 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "../../include/pixkit-image.hpp" 7 | bool SimplestColorBalance(cv::Mat ori,float upperthresh,float lowerthresh){ 8 | 9 | int totalarea=ori.rows*ori.cols; 10 | upperthresh=upperthresh*totalarea; 11 | lowerthresh=lowerthresh*totalarea; 12 | cv::Mat sorted_ori; 13 | cv::Mat reshapeOri; 14 | reshapeOri=ori.reshape(0,1); 15 | cv::sort(reshapeOri,sorted_ori,CV_SORT_ASCENDING ); 16 | 17 | int Vmin=(sorted_ori.at(lowerthresh)); 18 | int Vmax=sorted_ori.at((ori.rows*ori.cols-1)-upperthresh); 19 | for (int i=0; i(i)[j](i)[j]=0; 22 | else if(ori.ptr(i)[j]>Vmax)ori.ptr(i)[j]=255; 23 | else ori.ptr(i)[j]= (ori.ptr(i)[j]-Vmin)*255./(Vmax-Vmin); 24 | } 25 | } 26 | 27 | return 1; 28 | 29 | } 30 | bool pixkit::enhancement::local::NRCIR2009( cv::Mat ori,cv::Mat &ret){ 31 | 32 | if(ori.type()!=CV_8UC3){ 33 | CV_Assert(false); 34 | } 35 | 36 | //calculate key value 37 | cv::Mat Lab=cv::Mat::zeros(ori.rows,ori.cols,CV_32FC3); 38 | cv::Mat GL_mapped=cv::Mat::zeros(ori.rows,ori.cols,CV_32FC1); 39 | cv::Mat ori_32FC1=ori.clone(); 40 | std::vector RGB_Indepen(3); 41 | std::vector RGB_GLmapped(3); 42 | std::vector GLmapped_LabIndepen(3); 43 | std::vector Final_Lab_In(3); 44 | std::vector Lab_Indepen(3); 45 | for(int i=0;i<3;i++){ 46 | RGB_GLmapped[i]=cv::Mat::zeros(ori.rows,ori.cols,CV_32FC1); 47 | RGB_Indepen[i]=cv::Mat::zeros(ori.rows,ori.cols,CV_32FC1); 48 | GLmapped_LabIndepen[i]=cv::Mat::zeros(ori.rows,ori.cols,CV_32FC1); 49 | Final_Lab_In[i]=cv::Mat::zeros(ori.rows,ori.cols,CV_32FC1); 50 | Lab_Indepen[i]=cv::Mat::zeros(ori.rows,ori.cols,CV_32FC1); 51 | } 52 | 53 | ori.convertTo(ori_32FC1,CV_32FC3); 54 | ori.convertTo(Lab,CV_32FC3); 55 | Lab=Lab/255.; 56 | cv::cvtColor(Lab,Lab,CV_BGR2Lab); 57 | cv::split(ori_32FC1,RGB_Indepen); 58 | cv::split(Lab,Lab_Indepen); 59 | 60 | //calculate keys, equation (1) 61 | double key_value=0; 62 | double radius=0; 63 | double Igm=0; 64 | double CenterPrecision=0.001; 65 | cv::Point2d MCcenter; //mapping circle center 66 | float Fzero=0; 67 | for(int i=0;i(i,j)[0]==Fzero)continue; 70 | key_value = key_value+log(((float)Lab.at(i,j)[0])); 71 | } 72 | } 73 | key_value=key_value/(ori.rows*ori.cols); 74 | key_value=exp(key_value); 75 | 76 | //calculate radius and perform global mapping for each RGB channel 77 | if(key_value<=50){ 78 | radius=3.*log10(key_value/10+1); 79 | if(radius<1.4)radius=1.4; 80 | for(MCcenter.x=0;;MCcenter.x=MCcenter.x+CenterPrecision){ 81 | MCcenter.y=1-MCcenter.x; 82 | if(sqrt(pow(MCcenter.y,2)+pow(MCcenter.x,2))>radius)break; 83 | } 84 | 85 | for(int z=0;z<3;z++){ 86 | for(int i=0;i(i)[j]/255.; 89 | Igm=MCcenter.y+sqrt(pow(radius,2)-pow(RGBscaled-MCcenter.x,2)); 90 | RGB_GLmapped[z].ptr(i)[j]=Igm; 91 | 92 | } 93 | } 94 | } 95 | } 96 | else if (key_value>=60){ 97 | radius=3.*log10(10-key_value/10+1); 98 | if(radius<1.4)radius=1.4; 99 | for(MCcenter.x=0;;MCcenter.x=MCcenter.x-CenterPrecision){ 100 | MCcenter.y=1-MCcenter.x; 101 | if(sqrt(pow(MCcenter.y,2)+pow(MCcenter.x,2))>radius)break; 102 | } 103 | for(int z=0;z(i)[j]/255; 108 | Igm=MCcenter.y-sqrt(pow(radius,2)-pow(RGBscaled-MCcenter.x,2)); 109 | RGB_GLmapped[z].ptr(i)[j]=Igm; 110 | } 111 | } 112 | } 113 | }//until here, global tone mapping is done 114 | 115 | cv::merge(RGB_GLmapped,GL_mapped); 116 | cv::Mat GL_mapped_LAB; 117 | cv::cvtColor(GL_mapped,GL_mapped_LAB,CV_BGR2Lab); 118 | cv::split(GL_mapped_LAB,GLmapped_LabIndepen); 119 | cv::Mat Im=cv::Mat::zeros(GL_mapped.size(),CV_32FC1); 120 | cv::Mat E4_Result;//equation 4 121 | 122 | //acquire the proposed filter, equation (6) (7) 123 | float K=(ori.cols*ori.rows)/8; 124 | int Path_K=((int)sqrt(K)&-2)+1; 125 | cv::Mat Filter_mask=cv::Mat::zeros(Path_K,Path_K,CV_32FC1); 126 | for(int i=0;i(y+Path_K/2)[x+Path_K/2]=exp(-(y*y+x*x)/pow((float)2,2*i)); 130 | } 131 | } 132 | } 133 | 134 | //acquire Im, equation (5) 135 | cv::filter2D(GLmapped_LabIndepen[0],Im,GLmapped_LabIndepen[0].depth(),Filter_mask); 136 | 137 | //Retinex luminance, equation (4) 138 | cv::Mat E4_Domi=cv::Mat::zeros(ori.size(),CV_32FC1); 139 | for(int i=0;i(i)[j]=log10(Im.ptr(i)[j]+1); 142 | } 143 | } 144 | cv::divide(GLmapped_LabIndepen[0],E4_Domi,E4_Result); 145 | 146 | //according to the flowchart(Fig5), perform histogram rescaling after Modified Retinex 147 | cv::normalize(E4_Result,E4_Result,0,255,32); 148 | SimplestColorBalance(E4_Result,0.01,0); 149 | 150 | 151 | //obtain reference map, equation(8) 152 | cv::Mat M_ref=cv::Mat::zeros(ori.size(),CV_32FC1); 153 | cv::Mat rescaled_L; 154 | cv::normalize(Lab_Indepen[0],rescaled_L,0,255,32); 155 | for(int i=0;i(i)[j]/rescaled_L.ptr(i)[j]+1)/log(2.); 158 | M_ref.ptr(i)[j]=(log2Value); 159 | } 160 | } 161 | 162 | //enhance the globally mapped RGB image, equation(9) 163 | cv::Mat_ enhancedRGB=cv::Mat::zeros(ori.size(),CV_32FC3); 164 | 165 | for(int z=0;z(i,j)[z]=RGB_Indepen[z].ptr(i)[j]/255.*M_ref.ptr(i)[j]; 169 | if(enhancedRGB.at(i,j)[z]>=1)enhancedRGB.at(i,j)[z]=1; 170 | } 171 | } 172 | } 173 | 174 | //according to the flowchart(Fig5), perform final histogram rescaling after the step 'Luminance channel' 175 | cv::Mat Final_Lab; 176 | cv::Mat FinalResult; 177 | cv::cvtColor(enhancedRGB,Final_Lab,CV_BGR2Lab); 178 | cv::split(Final_Lab,Final_Lab_In); 179 | SimplestColorBalance(Final_Lab_In[0],0.01,0); 180 | cv::normalize(Final_Lab_In[0],Final_Lab_In[0],0,100,32); 181 | cv::merge(Final_Lab_In,Final_Lab); 182 | cv::cvtColor(Final_Lab,FinalResult,CV_Lab2BGR); 183 | FinalResult=FinalResult*255; 184 | FinalResult.convertTo(FinalResult,CV_8UC3); 185 | ret=FinalResult.clone(); 186 | return 1; 187 | } 188 | 189 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(pixkit) 2 | 3 | cmake_minimum_required (VERSION 2.6) 4 | 5 | set(PIXKIT_VERSION_MAJOR 0) 6 | set(PIXKIT_VERSION_MINOR 5) 7 | set(PIXKIT_VERSION_PATCH 2) 8 | set(PIXKIT_VERSION_STRING ${PIXKIT_VERSION_MAJOR}${PIXKIT_VERSION_MINOR}${PIXKIT_VERSION_PATCH}) 9 | 10 | 11 | # ============================================================================ # 12 | # Where to install the pixkit library 13 | set(PIXKIT_INSTALL_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/install/lib" CACHE PATH "Installation Directory") 14 | set(PIXKIT_INCLUDE_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/install/include" CACHE PATH "Includes Directory") 15 | set(PIXKIT_SAMPLES_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/install/samples" CACHE PATH "Samples Directory") 16 | set(PIXKIT_TEST_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/install/test" CACHE PATH "Samples Directory") 17 | 18 | 19 | # ============================================================================ # 20 | # Where to output binaries and libraries 21 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lib") 22 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lib") 23 | #set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/samples") 24 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${PIXKIT_SAMPLES_PREFIX}) 25 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_CURRENT_BINARY_DIR}/bin") 26 | 27 | 28 | # ============================================================================ # 29 | # Set up the lib names for debug and release modes 30 | set(CMAKE_DEBUG_POSTFIX ${PIXKIT_VERSION_STRING}d) 31 | set(CMAKE_RELEASE_POSTFIX ${PIXKIT_VERSION_STRING}) 32 | 33 | 34 | # ============================================================================ # 35 | # Library installation 36 | if(CMAKE_SIZEOF_VOID_P EQUAL 8) 37 | set(PIXKIT_ENV "x64") 38 | else(CMAKE_SIZEOF_VOID_P EQUAL 8) 39 | set(PIXKIT_ENV "x86") 40 | endif(CMAKE_SIZEOF_VOID_P EQUAL 8) 41 | if(MSVC10) 42 | set(PIXKIT_COMPILER "vc10") 43 | elseif(MSVC11) 44 | set(PIXKIT_COMPILER "vc11") 45 | endif() 46 | 47 | 48 | # ============================================================================ # 49 | # Find external libraries and dependencies 50 | find_package(OpenCV REQUIRED) 51 | #if (NOT APPLE) 52 | # find_package(OpenMP) 53 | #endif () 54 | #find_package(Doxygen) 55 | 56 | 57 | # ----------------------------------------------------------- 58 | # Install part 59 | # ----------------------------------------------------------- 60 | # *********************************************************** 61 | # Install projects (pixkit-image) 62 | # include_directories("modules/pixkit-image") 63 | 64 | # pixkit-image libraries 65 | file(GLOB PIXKIT_IMAGE_FILES 66 | "modules/pixkit-image/include/*.hpp" "modules/pixkit-image/include/*.h" 67 | "modules/pixkit-image/src/*.cpp" 68 | "modules/pixkit-image/src/*/*.cpp") 69 | add_library(pixkit_image ${PIXKIT_IMAGE_FILES}) 70 | target_link_libraries(pixkit_image ${OpenCV_LIBS}) 71 | install(TARGETS pixkit_image 72 | DESTINATION "${PIXKIT_INSTALL_PREFIX}/${PIXKIT_ENV}/${PIXKIT_COMPILER}") 73 | 74 | # *********************************************************** 75 | # Install projects (pixkit-ml) 76 | include_directories("modules/pixkit-ml/") 77 | 78 | # pixkit-ml libraries 79 | file(GLOB PIXKIT_ML_FILES 80 | "modules/pixkit-ml/include/*.hpp" "modules/pixkit-ml/include/*.h" 81 | "modules/pixkit-ml/src/*.cpp" 82 | "modules/pixkit-ml/src/*/*.cpp") 83 | add_library(pixkit_ml ${PIXKIT_ML_FILES}) 84 | target_link_libraries(pixkit_ml ${OpenCV_LIBS}) 85 | install(TARGETS pixkit_ml 86 | DESTINATION "${PIXKIT_INSTALL_PREFIX}/${PIXKIT_ENV}/${PIXKIT_COMPILER}") 87 | 88 | # *********************************************************** 89 | # Install projects (pixkit-timer) 90 | include_directories("modules/pixkit-timer/") 91 | 92 | # pixkit-timer libraries 93 | file(GLOB PIXKIT_TIMER_FILES 94 | "modules/pixkit-timer/include/*.hpp" "modules/pixkit-timer/src/*.cpp") 95 | add_library(pixkit_timer ${PIXKIT_TIMER_FILES}) 96 | target_link_libraries(pixkit_timer ${OpenCV_LIBS}) 97 | install(TARGETS pixkit_timer 98 | DESTINATION "${PIXKIT_INSTALL_PREFIX}/${PIXKIT_ENV}/${PIXKIT_COMPILER}") 99 | 100 | # *********************************************************** 101 | # Install projects (pixkit-file) 102 | include_directories("modules/pixkit-file/") 103 | 104 | # pixkit-timer libraries 105 | file(GLOB PIXKIT_FILE_FILES 106 | "modules/pixkit-file/include/*.hpp" "modules/pixkit-file/src/*.cpp") 107 | add_library(pixkit_file ${PIXKIT_FILE_FILES}) 108 | target_link_libraries(pixkit_file ${OpenCV_LIBS}) 109 | install(TARGETS pixkit_file 110 | DESTINATION "${PIXKIT_INSTALL_PREFIX}/${PIXKIT_ENV}/${PIXKIT_COMPILER}") 111 | 112 | # *********************************************************** 113 | # Install projects (pixkit-cv) 114 | include_directories("modules/pixkit-cv/") 115 | 116 | # pixkit-timer libraries 117 | file(GLOB PIXKIT_CV_FILES 118 | "modules/pixkit-cv/include/*.hpp" "modules/pixkit-cv/src/*.cpp") 119 | add_library(pixkit_cv ${PIXKIT_CV_FILES}) 120 | target_link_libraries(pixkit_cv ${OpenCV_LIBS}) 121 | install(TARGETS pixkit_cv 122 | DESTINATION "${PIXKIT_INSTALL_PREFIX}/${PIXKIT_ENV}/${PIXKIT_COMPILER}") 123 | 124 | 125 | # ----------------------------------------------------------- 126 | # Other part 127 | # ----------------------------------------------------------- 128 | # ============================================================================ # 129 | # Sample programs (image/halftoning) 130 | add_executable(image_halftoning_dotdiffusion_GuoLiu2009 131 | examples-image/halftoning/dotdiffusion.GuoLiu2009/example_dotdiffusion.GuoLiu2009.cpp 132 | ) 133 | target_link_libraries(image_halftoning_dotdiffusion_GuoLiu2009 pixkit_image) 134 | add_executable(image_halftoning_dotdiffusion_NADD2013 135 | examples-image/halftoning/dotdiffusion.NADD2013/example_dotdiffusion.NADD2013.cpp 136 | ) 137 | target_link_libraries(image_halftoning_dotdiffusion_NADD2013 pixkit_image) 138 | 139 | # Sample programs (image/enhancement) 140 | add_executable(image_enhancement_MaryKim2008 141 | examples-image/enhancement/enhancement.MaryKim2008/example_MaryKim2008.cpp 142 | ) 143 | target_link_libraries(image_enhancement_MaryKim2008 pixkit_image) 144 | add_executable(image_enhancement_WadudKabirDewanChae2007 145 | examples-image/enhancement/enhancement.WadudKabirDewanChae2007/example_WadudKabirDewanChae2007.cpp 146 | ) 147 | target_link_libraries(image_enhancement_WadudKabirDewanChae2007 pixkit_image) 148 | 149 | 150 | # ============================================================================ # 151 | # Test programs (image/halftoning) 152 | add_executable(test_image_halftoning 153 | modules/pixkit-image/test/test_halftoning.cpp 154 | ) 155 | target_link_libraries(test_image_halftoning pixkit_image) 156 | 157 | # set up property 158 | set_target_properties( 159 | test_image_halftoning 160 | PROPERTIES 161 | RUNTIME_OUTPUT_DIRECTORY_RELEASE ${PIXKIT_TEST_PREFIX} 162 | ) 163 | 164 | 165 | # ============================================================================ # 166 | # move files ******************************************************************** 167 | file(GLOB PIXKIT_HEADER # all the .hpp files 168 | "modules/pixkit-*/include/*.hpp" "modules/pixkit-*/include/*.h") 169 | install(FILES 170 | ${PIXKIT_HEADER} 171 | DESTINATION 172 | ${PIXKIT_INCLUDE_PREFIX} 173 | ) 174 | install(FILES 175 | modules/python/unittest.py 176 | DESTINATION 177 | ${PIXKIT_TEST_PREFIX} 178 | ) 179 | 180 | 181 | # ============================================================================ # 182 | # Generate Doxygen-based documentation project 183 | #if(DOXYGEN_FOUND) 184 | # add_custom_target(akaze_documentation 185 | # ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile 186 | # WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} 187 | # COMMENT "Generating API documentation with Doxygen" VERBATIM) 188 | #endif(DOXYGEN_FOUND) -------------------------------------------------------------------------------- /examples-image/halftoning/dotdiffusion.NADD2013/prog.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {1F160CC2-3EAA-429B-AAF8-1A54FD967981} 23 | test_prog 24 | 25 | 26 | 27 | Application 28 | true 29 | MultiByte 30 | v100 31 | 32 | 33 | Application 34 | true 35 | MultiByte 36 | v100 37 | 38 | 39 | Application 40 | false 41 | true 42 | MultiByte 43 | v100 44 | 45 | 46 | Application 47 | false 48 | true 49 | MultiByte 50 | v100 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | $(IncludePath) 70 | 71 | 72 | $(SourcePath) 73 | 74 | 75 | $(IncludePath) 76 | 77 | 78 | $(SourcePath) 79 | 80 | 81 | 82 | Level3 83 | Disabled 84 | C:\OpenCV\Build\install\include;C:\OpenCV\Build\install\include\opencv;C:\OpenCV\Build\install\include\opencv2 85 | 86 | 87 | true 88 | C:\OpenCV\Build\install\lib 89 | opencv_core243d.lib;opencv_imgproc243d.lib;opencv_highgui243d.lib;%(AdditionalDependencies) 90 | 91 | 92 | 93 | 94 | Level3 95 | Disabled 96 | C:\OpenCV\Build\install\include;C:\OpenCV\Build\install\include\opencv;C:\OpenCV\Build\install\include\opencv2 97 | 98 | 99 | true 100 | C:\OpenCV\Build\install\lib 101 | opencv_core243d.lib;opencv_imgproc243d.lib;opencv_highgui243d.lib 102 | 103 | 104 | 105 | 106 | Level3 107 | MaxSpeed 108 | true 109 | true 110 | C:\OpenCV\Build\install\include;C:\OpenCV\Build\install\include\opencv;C:\OpenCV\Build\install\include\opencv2 111 | 112 | 113 | true 114 | true 115 | true 116 | C:\OpenCV\Build\install\lib 117 | opencv_core243.lib;opencv_imgproc243.lib;opencv_highgui243.lib;%(AdditionalDependencies) 118 | 119 | 120 | 121 | 122 | Level3 123 | MaxSpeed 124 | true 125 | true 126 | C:\OpenCV\Build\install\include;C:\OpenCV\Build\install\include\opencv;C:\OpenCV\Build\install\include\opencv2 127 | 128 | 129 | true 130 | true 131 | true 132 | C:\OpenCV\Build\install\lib 133 | opencv_core243.lib;opencv_imgproc243.lib;opencv_highgui243.lib 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | -------------------------------------------------------------------------------- /modules/pixkit-image/test/prog.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {1F160CC2-3EAA-429B-AAF8-1A54FD967981} 23 | test_prog 24 | 25 | 26 | 27 | Application 28 | true 29 | MultiByte 30 | v120 31 | 32 | 33 | Application 34 | true 35 | MultiByte 36 | v120 37 | 38 | 39 | Application 40 | false 41 | true 42 | MultiByte 43 | v120 44 | 45 | 46 | Application 47 | false 48 | true 49 | MultiByte 50 | v120 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | $(IncludePath) 70 | 71 | 72 | $(SourcePath) 73 | 74 | 75 | $(IncludePath) 76 | 77 | 78 | $(SourcePath) 79 | 80 | 81 | 82 | Level3 83 | Disabled 84 | C:\OpenCV\Build\install\include;C:\OpenCV\Build\install\include\opencv;C:\OpenCV\Build\install\include\opencv2 85 | 86 | 87 | true 88 | C:\OpenCV\Build\install\lib 89 | opencv_core243d.lib;opencv_imgproc243d.lib;opencv_highgui243d.lib;%(AdditionalDependencies) 90 | 91 | 92 | 93 | 94 | Level3 95 | Disabled 96 | C:\OpenCV\builds\install\include;C:\OpenCV\builds\install\include\opencv;C:\OpenCV\builds\install\include\opencv2 97 | 98 | 99 | true 100 | C:\OpenCV\builds\install\x64\vc10\lib 101 | opencv_core247d.lib;opencv_imgproc247d.lib;opencv_highgui247d.lib 102 | 103 | 104 | 105 | 106 | Level3 107 | MaxSpeed 108 | true 109 | true 110 | C:\OpenCV\Build\install\include;C:\OpenCV\Build\install\include\opencv;C:\OpenCV\Build\install\include\opencv2 111 | 112 | 113 | true 114 | true 115 | true 116 | C:\OpenCV\Build\install\lib 117 | opencv_core243.lib;opencv_imgproc243.lib;opencv_highgui243.lib;%(AdditionalDependencies) 118 | 119 | 120 | 121 | 122 | Level3 123 | MaxSpeed 124 | true 125 | true 126 | C:\OpenCV\builds\install\include;C:\OpenCV\builds\install\include\opencv;C:\OpenCV\builds\install\include\opencv2 127 | 128 | 129 | true 130 | true 131 | true 132 | C:\OpenCV\builds\install\x64\vc10\lib 133 | opencv_core247.lib;opencv_imgproc247.lib;opencv_highgui247.lib 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | -------------------------------------------------------------------------------- /examples-image/halftoning/dotdiffusion.GuoLiu2009/prog.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {1F160CC2-3EAA-429B-AAF8-1A54FD967981} 23 | test_prog 24 | 25 | 26 | 27 | Application 28 | true 29 | MultiByte 30 | v100 31 | 32 | 33 | Application 34 | true 35 | MultiByte 36 | v100 37 | 38 | 39 | Application 40 | false 41 | true 42 | MultiByte 43 | v100 44 | 45 | 46 | Application 47 | false 48 | true 49 | MultiByte 50 | v100 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | $(IncludePath) 70 | 71 | 72 | $(SourcePath) 73 | 74 | 75 | $(IncludePath) 76 | 77 | 78 | $(SourcePath) 79 | 80 | 81 | 82 | Level3 83 | Disabled 84 | C:\OpenCV\Build\install\include;C:\OpenCV\Build\install\include\opencv;C:\OpenCV\Build\install\include\opencv2 85 | 86 | 87 | true 88 | C:\OpenCV\Build\install\lib 89 | opencv_core243d.lib;opencv_imgproc243d.lib;opencv_highgui243d.lib;%(AdditionalDependencies) 90 | 91 | 92 | 93 | 94 | Level3 95 | Disabled 96 | C:\OpenCV\Build\install\include;C:\OpenCV\Build\install\include\opencv;C:\OpenCV\Build\install\include\opencv2 97 | 98 | 99 | true 100 | C:\OpenCV\Build\install\lib 101 | opencv_core243d.lib;opencv_imgproc243d.lib;opencv_highgui243d.lib 102 | 103 | 104 | 105 | 106 | Level3 107 | MaxSpeed 108 | true 109 | true 110 | C:\OpenCV\Build\install\include;C:\OpenCV\Build\install\include\opencv;C:\OpenCV\Build\install\include\opencv2 111 | 112 | 113 | true 114 | true 115 | true 116 | C:\OpenCV\Build\install\lib 117 | opencv_core243.lib;opencv_imgproc243.lib;opencv_highgui243.lib;%(AdditionalDependencies) 118 | 119 | 120 | 121 | 122 | Level3 123 | MaxSpeed 124 | true 125 | true 126 | C:\OpenCV\Build\install\include;C:\OpenCV\Build\install\include\opencv;C:\OpenCV\Build\install\include\opencv2;C:\Users\yunfuliu\Documents\GitHub\pixkit\pixkit-image 127 | 128 | 129 | true 130 | true 131 | true 132 | C:\OpenCV\Build\install\lib 133 | opencv_core243.lib;opencv_imgproc243.lib;opencv_highgui243.lib 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | -------------------------------------------------------------------------------- /modules/pixkit-ml/src/KNN.cpp: -------------------------------------------------------------------------------- 1 | #include "../include/pixkit-ml.hpp" 2 | 3 | using namespace std; 4 | 5 | double Euclidean_Distance(const vector& v1, const vector& v2){ 6 | assert(v1.size() == v2.size()); 7 | double ret = 0.0; 8 | for (vector::size_type i = 0; i != v1.size(); ++i){ 9 | ret += (v1[i] - v2[i]) * (v1[i] - v2[i]); 10 | } 11 | return sqrt(ret); 12 | } 13 | void DistanceMatrix(std::vector >& dm, const std::vector &dataset,const std::vector &sample){ 14 | for ( vector::size_type i = 0; i != sample.size(); ++i){ 15 | vector DM_data; 16 | for (vector::size_type j = 0; j != dataset.size(); ++j){ 17 | DM_data.push_back(Euclidean_Distance(sample[i].features, dataset[j].features)); 18 | } 19 | dm.push_back(DM_data); 20 | } 21 | } 22 | vector kappa_Matrix(const vector& v1, const vector& v2, vector& kappa) 23 | { 24 | assert(v1.size() == v2.size()); 25 | 26 | for (vector::size_type i = 0; i != v1.size(); ++i) 27 | { 28 | kappa[i] +=sqrt((v1[i] - v2[i]) * (v1[i] - v2[i])) ; 29 | } 30 | 31 | return (kappa); 32 | 33 | } 34 | 35 | void BandwidthMatrix(vector >& Bw, const vector& sample, const vector& dataset) 36 | { 37 | 38 | for (vector::size_type i = 0; i !=sample.size(); ++i) 39 | { 40 | vector kappa_data,kappa(sample[i].features.size()); 41 | 42 | for (vector::size_type j = 0; j != dataset.size(); ++j) 43 | { 44 | 45 | 46 | kappa_data=kappa_Matrix(sample[i].features, dataset[j].features,kappa); 47 | 48 | } 49 | 50 | Bw.push_back(kappa_data); 51 | 52 | } 53 | 54 | 55 | } 56 | 57 | void Tradition_KNN_Process(vector& sample, const vector& dataset, const vector >& dm, unsigned int k){ 58 | for (vector::size_type i = 0; i != sample.size(); ++i){ 59 | multimap dts; 60 | for (vector::size_type j = 0; j != dm[i].size(); ++j){ 61 | if (dts.size() < k){ 62 | dts.insert(make_pair(dm[i][j], dataset[j].classnumber)); 63 | }else{ 64 | multimap::iterator it = dts.end(); 65 | --it; 66 | if (dm[i][j] < (it->first)){ 67 | dts.erase(it); 68 | dts.insert(make_pair(dm[i][j], dataset[j].classnumber)); 69 | } 70 | } 71 | } 72 | map tds; 73 | string type = ""; 74 | double weight = 0.0; 75 | for (multimap::const_iterator cit = dts.begin(); cit != dts.end(); ++cit){ 76 | ++tds[cit->second]; 77 | if (tds[cit->second] > weight){ 78 | weight = tds[cit->second]; 79 | type = cit->second; 80 | } 81 | } 82 | for (map::const_iterator cit = tds.begin(); cit != tds.end(); ++cit){ 83 | cout<first <<"="<second<<'\n'<& sample, const vector& dataset, const vector >& dm, unsigned int k) 92 | { 93 | for (vector::size_type i = 0; i != sample.size(); ++i) 94 | { 95 | multimap dts; 96 | for (vector::size_type j = 0; j != dm[i].size(); ++j) 97 | { 98 | if (dts.size() < k ) 99 | { 100 | dts.insert(make_pair(dm[i][j], dataset[j].classnumber)); 101 | } 102 | else 103 | { 104 | multimap::iterator it = dts.end(); 105 | --it; 106 | if (dm[i][j] < (it->first)) 107 | { 108 | dts.erase(it); 109 | dts.insert(make_pair(dm[i][j], dataset[j].classnumber)); 110 | 111 | } 112 | } 113 | } 114 | map tds,fin; 115 | string type = ""; 116 | double weight = 0.0; 117 | double now_weight = 0.0; 118 | double total_weight= 0.0; 119 | for (multimap::const_iterator cit = dts.begin(); cit != dts.end(); ++cit) 120 | { 121 | 122 | if (cit->first==0) 123 | { 124 | tds[cit->second] += 1.0 / (cit->first+1); 125 | total_weight=total_weight+(1.0 / (cit->first+1)); 126 | 127 | }else{ 128 | 129 | tds[cit->second] += 1.0 / cit->first; 130 | total_weight=total_weight+(1.0 / (cit->first)); 131 | } 132 | 133 | 134 | 135 | 136 | } 137 | 138 | for (map::const_iterator cit = tds.begin(); cit != tds.end(); ++cit) 139 | { 140 | 141 | now_weight=(cit->second/total_weight); 142 | 143 | if (now_weight > weight) 144 | { 145 | weight = now_weight; 146 | type = cit->first; 147 | 148 | } 149 | 150 | } 151 | 152 | sample[i].classnumber = type; 153 | cout<<"Result Class = "<& sample, const vector& dataset, const vector >& dm,const vector >& Bw) 160 | { 161 | for (vector::size_type i = 0; i != sample.size(); ++i) 162 | { 163 | multimap dts,dist,dist1; 164 | map tds,fin,merbership,countnmber; 165 | 166 | 167 | for (vector::size_type k = 0; k != dm[i].size(); ++k) 168 | { 169 | dist.insert(make_pair(dm[i][k], dataset[k].classnumber)); 170 | 171 | } 172 | 173 | 174 | 175 | for (vector::size_type j = 0; j != dataset.size(); ++j) 176 | { 177 | double d=0.0; 178 | for (vector::size_type x = 0; x != Bw[i].size(); ++x) 179 | { 180 | if (Bw[i][x]==0) 181 | { 182 | d+=(dataset.size()/(2))*(sample[i].features[x]-dataset[j].features[x])*(sample[i].features[x]-dataset[j].features[x]); 183 | 184 | }else{ 185 | 186 | d+=(dataset.size()/(2*Bw[i][x]))*(sample[i].features[x]-dataset[j].features[x])*(sample[i].features[x]-dataset[j].features[x]); 187 | 188 | } 189 | } 190 | dts.insert(make_pair(dm[i][j], dataset[j].classnumber)); 191 | d=d+(1/dataset.size())*exp(-d); 192 | 193 | for (multimap::const_iterator cit = dts.begin(); cit != dts.end(); ++cit) 194 | { 195 | 196 | if (cit->first==0) 197 | { 198 | tds[cit->second] += 1.0 / (cit->first+1); 199 | 200 | }else{ 201 | 202 | tds[cit->second] += 1.0 / cit->first; 203 | } 204 | 205 | } 206 | } 207 | 208 | string type = ""; 209 | double weight = 0.0; 210 | 211 | for (multimap::const_iterator cit = dts.begin(); cit != dts.end(); ++cit) 212 | { 213 | 214 | 215 | tds[cit->second] += cit->first; 216 | 217 | if (1/tds[cit->second] > weight) 218 | { 219 | weight = 1/tds[cit->second]; 220 | type = cit->second; 221 | 222 | } 223 | 224 | } 225 | 226 | 227 | sample[i].classnumber = type; 228 | cout<<"Result Class = "< &sample,const std::vector &dataset,int k){ 235 | 236 | ////////////////////////////////////////////////////////////////////////// 237 | ///// 238 | if(k<0){ 239 | CV_Error(CV_StsBadArg,"[pixkit::classification::KNN] k should >= 1."); 240 | } 241 | 242 | vector > DM; 243 | DistanceMatrix(DM, dataset, sample); 244 | Tradition_KNN_Process(sample, dataset, DM, k); 245 | 246 | return true; 247 | } 248 | 249 | bool pixkit::classification::FKNN(std::vector &sample,const std::vector &dataset,int k){ 250 | 251 | ////////////////////////////////////////////////////////////////////////// 252 | ///// 253 | if(k<0){ 254 | CV_Error(CV_StsBadArg,"[pixkit::classification::KNN] k should >= 1."); 255 | } 256 | 257 | vector > DM; 258 | DistanceMatrix(DM, dataset, sample); 259 | FKNN_Process(sample, dataset, DM, k); 260 | 261 | return true; 262 | } 263 | 264 | bool pixkit::classification::FRNN(std::vector &sample,const std::vector &dataset){ 265 | 266 | ////////////////////////////////////////////////////////////////////////// 267 | ///// 268 | 269 | vector > DM,Bw; 270 | DistanceMatrix(DM, dataset, sample); 271 | BandwidthMatrix(Bw, dataset, sample); 272 | FRNN_Process(sample, dataset, DM,Bw); 273 | 274 | return true; 275 | } -------------------------------------------------------------------------------- /modules/pixkit-image/src/comp/YangTsai1998.cpp: -------------------------------------------------------------------------------- 1 | #include "../../include/pixkit-image.hpp" 2 | #include 3 | #include 4 | 5 | using namespace cv; 6 | using namespace std; 7 | 8 | bool table_construction(const Mat &src3b,vector> &table){ 9 | 10 | ////////////////////////////////////////////////////////////////////////// 11 | ///// exceptions 12 | if (src3b.type() != CV_8UC3){ 13 | CV_Assert(false); 14 | } 15 | 16 | ////////////////////////////////////////////////////////////////////////// 17 | vector temp_vec(4,0); 18 | 19 | temp_vec[0] = src3b.ptr(0)[0][0]; 20 | temp_vec[1] = src3b.ptr(0)[0][1]; 21 | temp_vec[2] = src3b.ptr(0)[0][2]; 22 | temp_vec[3] = 1; 23 | table.push_back(temp_vec); 24 | 25 | for (int i = 2; i < src3b.rows; i+=2){ 26 | for (int j = 2; j < src3b.cols; j += 2){ 27 | int a=0; 28 | while (true){ 29 | if (table[a][0] == src3b.ptr(i)[j][0]){ 30 | if (table[a][1] == src3b.ptr(i)[j][1]){ 31 | if (table[a][2] == src3b.ptr(i)[j][2]){ 32 | table[a][3]++; 33 | break; 34 | } 35 | } 36 | } 37 | 38 | a++; 39 | if (a==table.size()){ 40 | temp_vec[0] = src3b.ptr(i)[j][0]; 41 | temp_vec[1] = src3b.ptr(i)[j][1]; 42 | temp_vec[2] = src3b.ptr(i)[j][2]; 43 | temp_vec[3] = 1; 44 | table.push_back(temp_vec); 45 | a = 0; 46 | break; 47 | } 48 | } 49 | } 50 | } 51 | 52 | return true; 53 | } 54 | bool count_var(double box_index, vector> &box_range, vector> &table){ 55 | 56 | int B_sum = 0, G_sum = 0, R_sum = 0; 57 | float moment1 = 0, moment2 = 0; 58 | 59 | for (int i = 0; i < table.size(); i++){ 60 | if (table[i][0] < box_range[box_index][0] && table[i][0] >= box_range[box_index][1]){ 61 | moment1 += table[i][0] * table[i][3]; 62 | moment2 += table[i][0] * table[i][0] * table[i][3]; 63 | B_sum += table[i][3]; 64 | } 65 | } 66 | box_range[box_index][6] = moment2/B_sum - moment1*moment1/B_sum/B_sum; 67 | box_range[box_index][11] = moment1 / B_sum; 68 | moment1 = 0; 69 | moment2 = 0; 70 | 71 | for (int i = 0; i < table.size(); i++){ 72 | if (table[i][1] < box_range[box_index][2] && table[i][1] >= box_range[box_index][3]){ 73 | moment1 += table[i][1] * table[i][3]; 74 | moment2 += table[i][1] * table[i][1] * table[i][3]; 75 | G_sum += table[i][3]; 76 | } 77 | } 78 | box_range[box_index][7] = moment2 / G_sum - moment1*moment1 / G_sum / G_sum; 79 | box_range[box_index][12] = moment1 / G_sum; 80 | moment1 = 0; 81 | moment2 = 0; 82 | 83 | for (int i = 0; i < table.size(); i++){ 84 | if (table[i][2] < box_range[box_index][4] && table[i][2] >= box_range[box_index][5]){ 85 | moment1 += table[i][2] * table[i][3]; 86 | moment2 += table[i][2] * table[i][2] * table[i][3]; 87 | R_sum += table[i][3]; 88 | } 89 | } 90 | box_range[box_index][8] = moment2 / R_sum - moment1*moment1 / R_sum / R_sum; 91 | box_range[box_index][13] = moment1 / R_sum; 92 | 93 | return true; 94 | } 95 | bool largest_plane(double box_index, vector> &box_range){ 96 | 97 | double max = box_range[box_index][6]; 98 | double max2; 99 | if (max < box_range[box_index][7]){ 100 | max2 = max; 101 | max = box_range[box_index][7]; 102 | }else{ 103 | max2 = box_range[box_index][7]; 104 | } 105 | if (max < box_range[box_index][8]){ 106 | max2 = max; 107 | max = box_range[box_index][8]; 108 | }else if (max2> &box_range, vector> &table){ 116 | 117 | double p0 = 0, total = 0, c0 = 0, c1 = 0, h0 = 0, h1 = 0, m1 = 0, m2 = 0, m3 = 0, mean11 = 0, mean12 = 0, mean21 = 0, mean22 = 0, var1 = 0, var2 = 0; 118 | 119 | for (int i = 0; i < table.size(); i++){ 120 | if (table[i][box_index] < t2 && table[i][box_index] >= t1){ 121 | total += table[i][3]; 122 | m1 += table[i][box_index] * table[i][3]; 123 | m2 += table[i][box_index] * table[i][box_index] * table[i][3]; 124 | m3 += table[i][box_index] * table[i][box_index] * table[i][box_index] * table[i][3]; 125 | } 126 | } 127 | m1 = m1 / total; 128 | m2 = m2 / total; 129 | m3 = m3 / total; 130 | 131 | c0 = (-m1*m3 + m2*m2) / (m1*m1 - m2); 132 | c1 = (-m1*m2 + m3) / (m1*m1 - m2); 133 | h0 = (-c1 - sqrt(c1*c1 - 4 * c0)) / 2; 134 | h1 = (-c1 + sqrt(c1*c1 - 4 * c0)) / 2; 135 | p0 = (h1 - m1) / (h1 - h0)*total; 136 | 137 | for (int k = t1; k < t2; k++){ 138 | total = 0; 139 | for (int i = 0; i < table.size(); i++){ 140 | if (table[i][box_index] < k && table[i][box_index] >= t1){ 141 | total += table[i][3]; 142 | if (total>p0){ 143 | return k; 144 | } 145 | } 146 | } 147 | } 148 | } 149 | bool box_splitting(vector> &box_range, vector> &table){ 150 | double box_index1 = 0,box_index2=0; 151 | for (int i = 0; i < box_range.size(); i++){ 152 | if (box_range[box_index1][9] < box_range[i][9]){ 153 | box_index1 = i; 154 | } 155 | } 156 | int t1, t2,split_point; 157 | 158 | vector memorry(14, 0); 159 | for (int i = 0; i < 14; i++){ 160 | memorry[i] = box_range[box_index1][i]; 161 | } 162 | 163 | if (box_range[box_index1][10] == box_range[box_index1][8]){ 164 | box_index2 = 2; 165 | t2 = box_range[box_index1][4]; 166 | t1 = box_range[box_index1][5]; 167 | split_point = moment_pre_thresholding(t1, t2, box_index2, box_range, table); 168 | box_range.erase(box_range.begin() + box_index1); 169 | memorry[5] = split_point; 170 | box_range.push_back(memorry); 171 | memorry[5] = t1; 172 | memorry[4] = split_point; 173 | box_range.push_back(memorry); 174 | 175 | }else if (box_range[box_index1][10] == box_range[box_index1][7]){ 176 | box_index2 = 1; 177 | t2 = box_range[box_index1][2]; 178 | t1 = box_range[box_index1][3]; 179 | split_point = moment_pre_thresholding(t1, t2, box_index2, box_range, table); 180 | box_range.erase(box_range.begin() + box_index1); 181 | memorry[3] = split_point; 182 | box_range.push_back(memorry); 183 | memorry[3] = t1; 184 | memorry[2] = split_point; 185 | box_range.push_back(memorry); 186 | }else{ 187 | box_index2 = 0; 188 | t2 = box_range[box_index1][0]; 189 | t1 = box_range[box_index1][1]; 190 | split_point = moment_pre_thresholding(t1, t2, box_index2, box_range, table); 191 | box_range.erase(box_range.begin() + box_index1); 192 | memorry[1] = split_point; 193 | box_range.push_back(memorry); 194 | memorry[1] = t1; 195 | memorry[0] = split_point; 196 | box_range.push_back(memorry); 197 | } 198 | 199 | for (int i = box_range.size() - 2; i < box_range.size(); i++){ 200 | count_var(i, box_range, table); 201 | largest_plane(i, box_range); 202 | } 203 | 204 | return true; 205 | } 206 | bool pixkit::comp::ColorBTC::YangTsai1998(const cv::Mat &src3b, cv::Mat &dst3b,const int K){ 207 | 208 | ////////////////////////////////////////////////////////////////////////// 209 | ///// exceptions 210 | if(src3b.type()==CV_8UC1){ 211 | CV_Error(CV_StsUnsupportedFormat,"this function supports only color image (CV_8UC3) imgae."); 212 | } 213 | if(K<=0){ 214 | CV_Error(CV_StsBadArg,"K should >=1."); 215 | } 216 | 217 | ////////////////////////////////////////////////////////////////////////// 218 | ///// init 219 | dst3b = src3b.clone(); 220 | 221 | ////////////////////////////////////////////////////////////////////////// 222 | ///// table construction 223 | vector> table; 224 | table_construction(src3b, table); 225 | 226 | ////////////////////////////////////////////////////////////////////////// 227 | ///// box construction 228 | vector> box_range; 229 | // box_range(b_high,b_low,g_high,g_low,r_high,r_low,b_var,g_var,r_var,largest_plane,b_mean,g_mean,r_mean) 230 | vector start(14, 0); 231 | start[0] = 256; // init 232 | start[2] = 256; // init 233 | start[4] = 256; // init 234 | box_range.push_back(start); 235 | count_var(0,box_range,table); 236 | largest_plane(0, box_range); 237 | // number of representative colors 238 | for (int i = 0; i < K-1; i++){ 239 | box_splitting(box_range, table); 240 | } 241 | 242 | ////////////////////////////////////////////////////////////////////////// 243 | ///// color mapping 244 | for (int i = 0; i < src3b.rows; i++){ 245 | for (int j = 0; j < src3b.cols; j++){ 246 | for (int m = 0; msrc3b.ptr(i)[j][0] && box_range[m][1] <= src3b.ptr(i)[j][0]){ 249 | if (box_range[m][2]>src3b.ptr(i)[j][1] && box_range[m][3] <= src3b.ptr(i)[j][1]){ 250 | if (box_range[m][4]>src3b.ptr(i)[j][2] && box_range[m][5] <= src3b.ptr(i)[j][2]){ 251 | 252 | dst3b.ptr(i)[j][0] = box_range[m][11]; 253 | dst3b.ptr(i)[j][1] = box_range[m][12]; 254 | dst3b.ptr(i)[j][2] = box_range[m][13]; 255 | 256 | } 257 | } 258 | } 259 | } 260 | } 261 | } 262 | 263 | return true; 264 | } 265 | -------------------------------------------------------------------------------- /modules/pixkit-image/src/halftoning/LiuGuo2015/LiuGuo2015.cpp: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // 3 | // LiuGuo2015.cpp 4 | // Authors: Yun-Fu Liu (1), Jing-Ming Guo (2) 5 | // Institutions: National Taiwan University of Science and Technology 6 | // Date: Sept. 14, 2015. 7 | // Email: yunfuliu@gmail.com, jmguo@seed.net.tw 8 | // 9 | // Dot-diffused halftoning with improved homogeneity, Copyright (c) 2015, 10 | // Yun-Fu Liu and Jing-Ming Guo, all rights reserved. 11 | // 12 | // Redistribution and use in source and binary forms, with or without modification, 13 | // are permitted provided that the following conditions are met: 14 | // 15 | // * Redistributions of source code must retain the above copyright notice, 16 | // this list of conditions and the following disclaimer. 17 | // 18 | // * Redistributions in binary form must reproduce the above copyright notice, 19 | // this list of conditions and the following disclaimer in the documentation 20 | // and/or other materials provided with the distribution. 21 | // 22 | // * The name of the copyright holders may not be used to endorse or promote products 23 | // derived from this software without specific prior written permission. 24 | // 25 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 26 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 27 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 28 | // IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 29 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 30 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 31 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 32 | // AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 33 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 34 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | // 36 | //======================================================================== 37 | 38 | #include "../../../include/pixkit-image.hpp" 39 | 40 | using namespace cv; 41 | using namespace std; 42 | 43 | pixkit::halftoning::dotdiffusion::CLiuGuo2015::CLiuGuo2015(std::string pthfname_resources){ 44 | 45 | cmsize = cv::Size(8, 8); // defined in paper. 46 | const int num_coe = 3; 47 | 48 | // read resources 49 | cv::FileStorage file(pthfname_resources, cv::FileStorage::READ); 50 | vector buff(num_coe); 51 | vector spmat(num_coe); 52 | Mat ct_src; 53 | file["table_256"] >> ct_src; 54 | file["paramsmap"] >> spmat; 55 | file.release(); 56 | 57 | // sparse matrix convert to mat 58 | for (int k = 0; k < num_coe; k++){ 59 | spmat[k].convertTo(buff[k], CV_32FC3); 60 | } 61 | 62 | // read class tiling (CT) 63 | ctread(ct_src, cmsize, cct); 64 | ctread(ct_src, cv::Size(16, 16), cct_ori); 65 | 66 | // read parameters 67 | read_paramsmap(buff, paramsmap); 68 | 69 | } 70 | pixkit::halftoning::dotdiffusion::CLiuGuo2015::~CLiuGuo2015(){} 71 | 72 | /************************************************************************/ 73 | /* INADD */ 74 | /************************************************************************/ 75 | bool pixkit::halftoning::dotdiffusion::CLiuGuo2015::ctread(const Mat &src, const Size cmsize, Mat &cct1b){ 76 | 77 | cct1b.create(src.size(), src.type()); 78 | int fz = cmsize.area(); 79 | static float L = 255; 80 | // 81 | float tv; 82 | for (int i = 0; i(i)[j]) * fz / (L + 1.); 85 | cct1b.ptr(i)[j] = cvFloor(tv); 86 | } 87 | } 88 | 89 | return true; 90 | } 91 | 92 | bool pixkit::halftoning::dotdiffusion::CLiuGuo2015::read_paramsmap(std::vector &vec_src, vector> ¶msmap){ 93 | 94 | // get space 95 | paramsmap.resize(128); // g 96 | for(int i=0;i(i)[j]; 106 | } 107 | } 108 | } 109 | 110 | return true; 111 | } 112 | 113 | void pixkit::halftoning::dotdiffusion::CLiuGuo2015::getPointList(const Size imgSize){ 114 | pointlist.resize(cmsize.area()); 115 | for (int i = 0; i < imgSize.height; i++){ 116 | for (int j = 0; j < imgSize.width; j++){ 117 | pointlist[cct.ptr(i%cct.rows)[j%cct.cols]].push_back(Point(j, i)); 118 | } 119 | } 120 | } 121 | 122 | bool pixkit::halftoning::dotdiffusion::CLiuGuo2015::process(const cv::Mat &src1b, cv::Mat &dst1b){ 123 | 124 | ////////////////////////////////////////////////////////////////////////// 125 | ///// exceptions 126 | if(src1b.type()!=CV_8U){ 127 | CV_Error(CV_BadNumChannels,""); 128 | } 129 | if(src1b.empty()){ 130 | CV_Error(CV_StsBadArg,"src is empty."); 131 | } 132 | if (pointlist.empty()){ 133 | CV_Error(CV_StsInternal, "`pointlist` is empty. Please run `getPointList()` with the source image size to get the `pointlist`."); 134 | } 135 | 136 | ////////////////////////////////////////////////////////////////////////// 137 | ///// initialization 138 | const float MAX_GRAYSCALE = 255; 139 | const float MIN_GRAYSCALE = 0; 140 | const int &height = src1b.rows; 141 | const int &width = src1b.cols; 142 | Mat tdst1f=src1b.clone(); // temporary space for the dst 143 | tdst1f.convertTo(tdst1f,CV_32FC1); 144 | 145 | ////////////////////////////////////////////////////////////////////////// 146 | ///// get ct 147 | // create CT for image processing 148 | Mat order(src1b.size(),CV_8UC1); 149 | for(int i=0;i(i)[j]=cct.ptr(i%cct.rows)[j%cct.cols]; 152 | } 153 | } 154 | Mat order_ori(src1b.size(),CV_8UC1); 155 | for(int i=0;i(i)[j]=cct_ori.ptr(i%cct_ori.rows)[j%cct_ori.cols]; 158 | } 159 | } 160 | 161 | ////////////////////////////////////////////////////////////////////////// 162 | ///// dot diffusion process 163 | // setting 164 | int DW_Size=3; // size of diffused matrix 165 | int hDW_Size=DW_Size/2; 166 | // perform dot diffusion 167 | float threshold,afa,beta; 168 | for(int k=0;k(i)[j]; 177 | uchar &ordv = order_ori.ptr(i)[j]; 178 | if(srcv<128){ 179 | threshold = paramsmap[srcv][ordv].coe[0]; 180 | afa = paramsmap[srcv][ordv].coe[1]; 181 | beta = paramsmap[srcv][ordv].coe[2]; 182 | }else{ 183 | threshold = paramsmap[MAX_GRAYSCALE-srcv][ordv].coe[0]; 184 | afa = paramsmap[MAX_GRAYSCALE-srcv][ordv].coe[1]; 185 | beta = paramsmap[MAX_GRAYSCALE-srcv][ordv].coe[2]; 186 | } 187 | 188 | ////////////////////////////////////////////////////////////////////////// 189 | // get error 190 | double error; 191 | if(tdst1f.ptr(i)[j](i)[j]; 193 | tdst1f.ptr(i)[j]=MIN_GRAYSCALE; 194 | }else{ 195 | error=tdst1f.ptr(i)[j]-MAX_GRAYSCALE; 196 | tdst1f.ptr(i)[j]=MAX_GRAYSCALE; 197 | } 198 | 199 | ////////////////////////////////////////////////////////////////////////// 200 | ///// check whether it needs to diffuse error, for the sake of saving time 201 | if(afa==0.&&beta==0.){ 202 | continue; 203 | }else{ 204 | 205 | ////////////////////////////////////////////////////////////////////////// 206 | ///// get DW 207 | double DW[9]={afa,beta,afa,beta,0.,beta,afa,beta,afa}; 208 | 209 | // get fm 210 | double fm=0.; 211 | for(int m=-hDW_Size;m<=hDW_Size;m++){ 212 | for(int n=-hDW_Size;n<=hDW_Size;n++){ 213 | if(i+m>=0&&i+m=0&&j+n(i+m)[j+n]>k){ // diffusible region 215 | fm+=DW[(m+hDW_Size)*DW_Size+(n+hDW_Size)]; 216 | } 217 | } 218 | } 219 | } 220 | // diffuse 221 | if(fm!=0){ 222 | for(int m=-hDW_Size;m<=hDW_Size;m++){ 223 | for(int n=-hDW_Size;n<=hDW_Size;n++){ 224 | if(i+m>=0&&i+m=0&&j+n(i+m)[j+n]>k){ // diffusible region 226 | tdst1f.ptr(i+m)[j+n]+=error*DW[(m+hDW_Size)*DW_Size+(n+hDW_Size)]/fm; 227 | } 228 | } 229 | } 230 | } 231 | } 232 | } 233 | } 234 | } 235 | 236 | // copy from tdst1f to dst1b 237 | dst1b.create(tdst1f.size(),CV_8UC1); 238 | for(int i=0;i(i)[j]=cvRound(tdst1f.ptr(i)[j]); 241 | } 242 | } 243 | 244 | return true; 245 | } 246 | -------------------------------------------------------------------------------- /examples-image/enhancement/enhancement.WadudKabirDewanChae2007/prog.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {1F160CC2-3EAA-429B-AAF8-1A54FD967981} 23 | test_prog 24 | 25 | 26 | 27 | Application 28 | true 29 | MultiByte 30 | v100 31 | 32 | 33 | Application 34 | true 35 | MultiByte 36 | v100 37 | 38 | 39 | Application 40 | false 41 | true 42 | MultiByte 43 | v100 44 | 45 | 46 | Application 47 | false 48 | true 49 | MultiByte 50 | v100 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | $(IncludePath) 70 | 71 | 72 | $(SourcePath) 73 | 74 | 75 | $(IncludePath) 76 | 77 | 78 | $(SourcePath) 79 | 80 | 81 | C:\OpenCV\opencv\build\install\include\opencv2;C:\OpenCV\opencv\build\install\include\opencv;C:\OpenCV\opencv\build\install\include;$(IncludePath) 82 | 83 | 84 | C:\OpenCV\opencv\build\install\include\opencv2;C:\OpenCV\opencv\build\install\include\opencv;C:\OpenCV\opencv\build\install\include;$(IncludePath) 85 | 86 | 87 | 88 | Level3 89 | Disabled 90 | C:\OpenCV\Build\install\include;C:\OpenCV\Build\install\include\opencv;C:\OpenCV\Build\install\include\opencv2 91 | 92 | 93 | true 94 | C:\OpenCV\opencv\build\install\lib 95 | opencv_core244d.lib;opencv_imgproc244d.lib;opencv_highgui244d.lib;opencv_ml244d.lib;opencv_video244d.lib;opencv_ts244d.lib;opencv_videostab244d.lib;opencv_photo244d.lib;opencv_stitching244d.lib;opencv_features2d244d.lib;opencv_calib3d244d.lib;opencv_nonfree244d.lib;opencv_objdetect244d.lib;opencv_contrib244d.lib;opencv_legacy244d.lib;opencv_flann244d.lib;opencv_gpu244d.lib;%(AdditionalDependencies) 96 | 97 | 98 | 99 | 100 | Level3 101 | Disabled 102 | C:\OpenCV\builds\install\include;C:\OpenCV\builds\install\include\opencv;C:\OpenCV\builds\install\include\opencv2 103 | 104 | 105 | true 106 | C:\OpenCV\builds\install\x64\vc10\lib 107 | opencv_core247d.lib;opencv_imgproc247d.lib;opencv_highgui247d.lib 108 | 109 | 110 | 111 | 112 | Level3 113 | MaxSpeed 114 | true 115 | true 116 | C:\OpenCV\Build\install\include;C:\OpenCV\Build\install\include\opencv;C:\OpenCV\Build\install\include\opencv2 117 | 118 | 119 | true 120 | true 121 | true 122 | C:\OpenCV\opencv\build\install\lib 123 | opencv_core244.lib;opencv_imgproc244.lib;opencv_highgui244.lib;opencv_ml244.lib;opencv_video244.lib;opencv_ts244.lib;opencv_videostab244.lib;opencv_photo244.lib;opencv_stitching244.lib;opencv_features2d244.lib;opencv_calib3d244.lib;opencv_nonfree244.lib;opencv_objdetect244.lib;opencv_contrib244.lib;opencv_legacy244.lib;opencv_flann244.lib;opencv_gpu244.lib;%(AdditionalDependencies) 124 | 125 | 126 | 127 | 128 | Level3 129 | MaxSpeed 130 | true 131 | true 132 | C:\OpenCV\builds\install\include;C:\OpenCV\builds\install\include\opencv;C:\OpenCV\builds\install\include\opencv2 133 | 134 | 135 | true 136 | true 137 | true 138 | C:\OpenCV\builds\install\x64\vc10\lib 139 | opencv_core247.lib;opencv_imgproc247.lib;opencv_highgui247.lib 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | -------------------------------------------------------------------------------- /examples-image/enhancement/enhancement.MaryKim2008/prog.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {1F160CC2-3EAA-429B-AAF8-1A54FD967981} 23 | test_prog 24 | 25 | 26 | 27 | Application 28 | true 29 | MultiByte 30 | v100 31 | 32 | 33 | Application 34 | true 35 | MultiByte 36 | v100 37 | 38 | 39 | Application 40 | false 41 | true 42 | MultiByte 43 | v100 44 | 45 | 46 | Application 47 | false 48 | true 49 | MultiByte 50 | v100 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | C:\OpenCV\build\include;$(IncludePath) 70 | 71 | 72 | $(SourcePath) 73 | C:\OpenCV\build\x64\vc10\lib;$(LibraryPath) 74 | 75 | 76 | C:\OpenCV\build\include;$(IncludePath) 77 | 78 | 79 | $(SourcePath) 80 | C:\OpenCV\build\x64\vc10\lib;$(LibraryPath) 81 | 82 | 83 | C:\OpenCV\opencv\build\install\include\opencv2;C:\OpenCV\opencv\build\install\include\opencv;C:\OpenCV\opencv\build\install\include;$(IncludePath) 84 | 85 | 86 | C:\OpenCV\opencv\build\install\include\opencv2;C:\OpenCV\opencv\build\install\include\opencv;C:\OpenCV\opencv\build\install\include;$(IncludePath) 87 | 88 | 89 | 90 | Level3 91 | Disabled 92 | C:\OpenCV\Build\install\include;C:\OpenCV\Build\install\include\opencv;C:\OpenCV\Build\install\include\opencv2 93 | 94 | 95 | true 96 | C:\OpenCV\opencv\build\install\lib 97 | opencv_core244d.lib;opencv_imgproc244d.lib;opencv_highgui244d.lib;opencv_ml244d.lib;opencv_video244d.lib;opencv_ts244d.lib;opencv_videostab244d.lib;opencv_photo244d.lib;opencv_stitching244d.lib;opencv_features2d244d.lib;opencv_calib3d244d.lib;opencv_nonfree244d.lib;opencv_objdetect244d.lib;opencv_contrib244d.lib;opencv_legacy244d.lib;opencv_flann244d.lib;opencv_gpu244d.lib;%(AdditionalDependencies) 98 | 99 | 100 | 101 | 102 | Level3 103 | Disabled 104 | C:\OpenCV\Build\install\include;C:\OpenCV\Build\install\include\opencv;C:\OpenCV\Build\install\include\opencv2;C:\pixkit\pixkit\modules 105 | 106 | 107 | true 108 | C:\OpenCV\Build\install\lib;%PIXKIT_LIB_PATH% 109 | opencv_core247d.lib;opencv_imgproc247d.lib;opencv_highgui247d.lib 110 | 111 | 112 | 113 | 114 | Level3 115 | MaxSpeed 116 | true 117 | true 118 | C:\OpenCV\Build\install\include;C:\OpenCV\Build\install\include\opencv;C:\OpenCV\Build\install\include\opencv2 119 | 120 | 121 | true 122 | true 123 | true 124 | C:\OpenCV\opencv\build\install\lib 125 | opencv_core244.lib;opencv_imgproc244.lib;opencv_highgui244.lib;opencv_ml244.lib;opencv_video244.lib;opencv_ts244.lib;opencv_videostab244.lib;opencv_photo244.lib;opencv_stitching244.lib;opencv_features2d244.lib;opencv_calib3d244.lib;opencv_nonfree244.lib;opencv_objdetect244.lib;opencv_contrib244.lib;opencv_legacy244.lib;opencv_flann244.lib;opencv_gpu244.lib;%(AdditionalDependencies) 126 | 127 | 128 | 129 | 130 | Level3 131 | MaxSpeed 132 | true 133 | true 134 | C:\OpenCV\Build\install\include;C:\OpenCV\Build\install\include\opencv;C:\OpenCV\Build\install\include\opencv2;C:\pixkit\pixkit\modules 135 | 136 | 137 | true 138 | true 139 | true 140 | C:\OpenCV\Build\install\lib;%PIXKIT_LIB_PATH% 141 | opencv_core247.lib;opencv_imgproc247.lib;opencv_highgui247.lib 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | -------------------------------------------------------------------------------- /examples-ml/clustering/fuzzyCMeans/prog.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {1F160CC2-3EAA-429B-AAF8-1A54FD967981} 23 | test_prog 24 | 25 | 26 | 27 | Application 28 | true 29 | MultiByte 30 | v100 31 | 32 | 33 | Application 34 | true 35 | MultiByte 36 | v100 37 | 38 | 39 | Application 40 | false 41 | true 42 | MultiByte 43 | v100 44 | 45 | 46 | Application 47 | false 48 | true 49 | MultiByte 50 | v100 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | $(IncludePath) 70 | 71 | 72 | $(SourcePath) 73 | 74 | 75 | $(IncludePath) 76 | 77 | 78 | $(SourcePath) 79 | 80 | 81 | C:\opencv\build\x86\vc10\bin;$(ExecutablePath) 82 | 83 | 84 | C:\openCV\build\include;$(IncludePath) 85 | 86 | 87 | C:\OpenCV\build\x86\vc10\lib;$(LibraryPath) 88 | 89 | 90 | C:\opencv\build\x86\vc10\bin;$(ExecutablePath) 91 | 92 | 93 | C:\openCV\build\include;$(IncludePath) 94 | 95 | 96 | C:\OpenCV\build\x86\vc10\lib;$(LibraryPath) 97 | 98 | 99 | 100 | Level3 101 | Disabled 102 | C:\OpenCV\Build\install\include;C:\OpenCV\Build\install\include\opencv;C:\OpenCV\Build\install\include\opencv2 103 | 104 | 105 | true 106 | C:\opencv\build\x86\vc11\lib 107 | opencv_core245d.lib;opencv_imgproc245d.lib;opencv_highgui245d.lib;opencv_ml245d.lib;opencv_video245d.lib;opencv_ts245d.lib;opencv_videostab245d.lib;opencv_photo245d.lib;opencv_stitching245d.lib;opencv_features2d245d.lib;opencv_calib3d245d.lib;opencv_nonfree245d.lib;opencv_objdetect245d.lib;opencv_contrib245d.lib;opencv_legacy245d.lib;opencv_flann245d.lib;opencv_gpu245d.lib;%(AdditionalDependencies) 108 | 109 | 110 | 111 | 112 | Level3 113 | Disabled 114 | C:\OpenCV\Build\install\include;C:\OpenCV\Build\install\include\opencv;C:\OpenCV\Build\install\include\opencv2 115 | false 116 | 117 | 118 | true 119 | C:\OpenCV\Build\install\lib 120 | opencv_core243d.lib;opencv_imgproc243d.lib;opencv_highgui243d.lib 121 | 122 | 123 | 124 | 125 | Level3 126 | MaxSpeed 127 | true 128 | true 129 | C:\OpenCV\Build\install\include;C:\OpenCV\Build\install\include\opencv;C:\OpenCV\Build\install\include\opencv2 130 | 131 | 132 | true 133 | true 134 | true 135 | C:\opencv\build\x86\vc11\lib 136 | opencv_core245.lib;opencv_imgproc245.lib;opencv_highgui245.lib;opencv_ml245.lib;opencv_video245.lib;opencv_ts245.lib;opencv_videostab245.lib;opencv_photo245.lib;opencv_stitching245.lib;opencv_features2d245.lib;opencv_calib3d245.lib;opencv_nonfree245.lib;opencv_objdetect245.lib;opencv_contrib245.lib;opencv_legacy245.lib;opencv_flann245.lib;opencv_gpu245.lib;%(AdditionalDependencies) 137 | 138 | 139 | 140 | 141 | Level3 142 | MaxSpeed 143 | true 144 | true 145 | C:\OpenCV\Build\install\include;C:\OpenCV\Build\install\include\opencv;C:\OpenCV\Build\install\include\opencv2 146 | 147 | 148 | true 149 | true 150 | true 151 | C:\OpenCV\Build\install\lib 152 | opencv_core243.lib;opencv_imgproc243.lib;opencv_highgui243.lib 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | -------------------------------------------------------------------------------- /modules/pixkit-image/src/POHE2013/pohe.cpp: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // 3 | // pohe.cpp 4 | // Authors: Yun-Fu Liu (1), Jing-Ming Guo (2), Bo-Syun Lai (3), Jiann-Der Lee (4) 5 | // Institutions: National Taiwan University of Science and Technology 6 | // Date: May 26, 2013 7 | // Email: yunfuliu@gmail.com, jmguo@seed.net.tw 8 | // Paper: Yun-Fu Liu, Jing-Ming Guo, Bo-Syun Lai, and Jiann-Der Lee, "High efficient 9 | // contrast enhancement using parametric approximation," IEEE Trans. 10 | // Image Processing, pp. 2444-2448, 26-31 May 2013. 11 | // 12 | // POHE Image Contrast Enhancement Copyright (c) 2013, Yun-Fu Liu, Jing-Ming Guo, 13 | // Bo-Syun Lai, and Jiann-Der Lee, all rights reserved. 14 | // 15 | // Redistribution and use in source and binary forms, with or without modification, 16 | // are permitted provided that the following conditions are met: 17 | // 18 | // * Redistributions of source code must retain the above copyright notice, 19 | // this list of conditions and the following disclaimer. 20 | // 21 | // * Redistributions in binary form must reproduce the above copyright notice, 22 | // this list of conditions and the following disclaimer in the documentation 23 | // and/or other materials provided with the distribution. 24 | // 25 | // * The name of the copyright holders may not be used to endorse or promote products 26 | // derived from this software without specific prior written permission. 27 | // 28 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 29 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 30 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 31 | // IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 32 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 33 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 34 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 35 | // AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 36 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 37 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | // 39 | //======================================================================== 40 | 41 | #include "../../include/pixkit-image.hpp" 42 | #include 43 | 44 | // calc cdf of Gaussian 45 | inline double calcCDF_Gaussian(double &src,double &mean,double &sd){ 46 | // exception when sd=0 47 | if(sd==0&&mean==src){ 48 | return 1.; 49 | } 50 | double x=(src-mean)/(sqrt(2.)*sd); 51 | double t=1./(1.+0.3275911*fabs(x)); 52 | double erf= 0.254829592 *t 53 | - 0.284496736 *t*t 54 | + 1.421413741 *t*t*t 55 | - 1.453152027 *t*t*t*t 56 | + 1.061405429 *t*t*t*t*t; 57 | erf=1.-erf*exp(-(x*x)); 58 | return 0.5*(1+(x<0?-erf:erf)); 59 | } 60 | 61 | // calc the sum of an area 62 | inline bool calcAreaMean(const cv::Mat &src, 63 | cv::Point currpos, 64 | cv::Size blockSize, 65 | const cv::Mat &sum=cv::Mat(), 66 | double *mean=NULL, 67 | const cv::Mat &sqsum=cv::Mat(), 68 | double *sd=NULL){ 69 | 70 | ////////////////////////////////////////////////////////////////////////// 71 | ///// exceptions 72 | if(blockSize.width%2==0||blockSize.height%2==0){ 73 | CV_Error(CV_StsBadArg,"[calcAreaMean] either block's height or width is 0."); 74 | } 75 | 76 | 77 | ////////////////////////////////////////////////////////////////////////// 78 | ///// initialization 79 | int SSFilterSize_h = blockSize.height/2; // SSFilterSize: Single Side Filter Size 80 | int SSFilterSize_w = blockSize.width/2; // SSFilterSize: Single Side Filter Size 81 | const int &height = src.rows; 82 | const int &width = src.cols; 83 | const int &i = currpos.y; 84 | const int &j = currpos.x; 85 | 86 | 87 | 88 | ////////////////////////////////////////////////////////////////////////// 89 | bool A=true, // bottom, top, left, right; thus br: bottom-right 90 | B=true, 91 | C=true, 92 | D=true; 93 | if((i+SSFilterSize_h)>=height){ 94 | A=false; 95 | } 96 | if((j+SSFilterSize_w)>=width){ 97 | B=false; 98 | } 99 | if((i-SSFilterSize_h-1)<0){ 100 | C=false; 101 | } 102 | if((j-SSFilterSize_w-1)<0){ 103 | D=false; 104 | } 105 | 106 | 107 | ////////////////////////////////////////////////////////////////////////// ok 108 | ///// get area size 109 | // width 110 | double areaWidth = blockSize.width, 111 | areaHeight = blockSize.height; 112 | if(!D){ 113 | areaWidth = j+SSFilterSize_w+1; 114 | }else if(!B){ 115 | areaWidth = width-j+SSFilterSize_w; 116 | } 117 | // height 118 | if(!C){ 119 | areaHeight = i+SSFilterSize_h+1; 120 | }else if(!A){ 121 | areaHeight = height-i+SSFilterSize_h; 122 | } 123 | 124 | 125 | ////////////////////////////////////////////////////////////////////////// 126 | ///// get value 127 | // get positions 128 | int y_up = i+SSFilterSize_h +1, // '+1' is the bias term of the integral image 129 | y_dn = i-SSFilterSize_h-1 +1; 130 | if(!A){ 131 | y_up = height-1 +1; 132 | } 133 | int x_left = j-SSFilterSize_w-1 +1, 134 | x_right = j+SSFilterSize_w +1; 135 | if(!B){ 136 | x_right = width-1 +1; 137 | } 138 | // get values 139 | double cTR_sum=0,cTR_sqsum=0, 140 | cTL_sum=0,cTL_sqsum=0, 141 | cBR_sum=0,cBR_sqsum=0, 142 | cBL_sum=0,cBL_sqsum=0; 143 | cTR_sum = sum.ptr(y_up)[x_right]; 144 | cTR_sqsum = sqsum.ptr(y_up)[x_right]; 145 | if(C&&D){ 146 | cBL_sum = sum.ptr(y_dn)[x_left]; 147 | cBL_sqsum = sqsum.ptr(y_dn)[x_left]; 148 | } 149 | if(D){ 150 | cTL_sum = -sum.ptr(y_up)[x_left]; 151 | cTL_sqsum = -sqsum.ptr(y_up)[x_left]; 152 | } 153 | if(C){ 154 | cBR_sum = -sum.ptr(y_dn)[x_right]; 155 | cBR_sqsum = -sqsum.ptr(y_dn)[x_right]; 156 | } 157 | 158 | 159 | ////////////////////////////////////////////////////////////////////////// ok 160 | ///// get mean and sd 161 | *mean =cTR_sum +cTL_sum +cBR_sum +cBL_sum; 162 | *mean /=areaHeight*areaWidth; 163 | CV_DbgAssert((*mean)>=0.&&(*mean)<=255.); 164 | *sd =cTR_sqsum +cTL_sqsum +cBR_sqsum +cBL_sqsum; 165 | *sd /=areaHeight*areaWidth; 166 | // compensate error 167 | if(fabs((*sd)-(*mean)*(*mean))<0.00001){ 168 | *sd=0; 169 | }else{ 170 | CV_DbgAssert((*sd)>=(*mean)*(*mean)); 171 | *sd =sqrt(*sd-(*mean)*(*mean)); 172 | } 173 | CV_DbgAssert((*sd)>=0.&&(*sd)<=255.); 174 | 175 | return true; 176 | } 177 | 178 | bool pixkit::enhancement::local::POHE2013(const cv::Mat &src,cv::Mat &dst,const cv::Size blockSize,const cv::Mat &sum,const cv::Mat &sqsum){ 179 | 180 | ////////////////////////////////////////////////////////////////////////// 181 | ///// Exceptions 182 | // blockSize 183 | if(blockSize.height>=src.rows || blockSize.width>=src.cols){ 184 | CV_Error(CV_StsBadArg,"[pixkit::enhancement::local::POHE2013] block size should be smaller than image size. "); 185 | } 186 | if(blockSize.height%2==0 || blockSize.width%2==0){ 187 | CV_Error(CV_StsBadArg,"[pixkit::enhancement::local::POHE2013] both block's width and height should be odd."); 188 | } 189 | if(blockSize.height==1&&blockSize.width==1){ 190 | CV_Error(CV_StsBadArg,"[pixkit::enhancement::local::POHE2013] blockSize=(1,1) will turn entire image to dead white."); 191 | } 192 | // src 193 | if(src.type()!=CV_8UC1&&src.type()!=CV_8UC3&&src.type()!=CV_32FC1){ 194 | CV_Error(CV_StsBadArg,"[pixkit::enhancement::local::POHE2013] src should be one of CV_8UC1, CV_8UC3, and CV_32FC1."); 195 | } 196 | // sum and sqsum 197 | if(!sum.empty()){ 198 | if(sum.type()!=CV_64FC1){ 199 | CV_Error(CV_StsBadArg,"[pixkit::enhancement::local::POHE2013] both sum and sqsum should be CV_64FC1"); 200 | } 201 | } 202 | if(!sqsum.empty()){ 203 | if(sqsum.type()!=CV_64FC1){ 204 | CV_Error(CV_StsBadArg,"[pixkit::enhancement::local::POHE2013] both sum and sqsum should be CV_64FC1"); 205 | } 206 | } 207 | 208 | ////////////////////////////////////////////////////////////////////////// 209 | ///// color image 210 | cv::Mat _src1x,_src3x; 211 | if(src.channels()==1){ 212 | _src1x=src; 213 | }else if(src.channels()==3){ 214 | // create space for _src1x 215 | if(src.type()==CV_8UC3){ 216 | _src1x.create(src.size(),CV_8UC1); 217 | }else if(src.type()==CV_32FC3){ 218 | _src1x.create(src.size(),CV_32FC1); 219 | }else{ 220 | CV_Assert(false); 221 | } 222 | // convert color 223 | cvtColor(src,_src3x,CV_BGR2Lab); 224 | int from_to[]={0,0}; 225 | mixChannels(&_src3x,1,&_src1x,1,from_to,1); 226 | }else{ 227 | CV_Error(CV_StsUnsupportedFormat,"[pixkit::enhancement::local::POHE2013] images should be grayscale or color."); 228 | } 229 | 230 | ////////////////////////////////////////////////////////////////////////// 231 | // initialization 232 | cv::Mat tdst; // temp dst. To avoid that when src == dst occur. 233 | tdst.create(_src1x.size(),_src1x.type()); 234 | const int &height=_src1x.rows; 235 | const int &width=_src1x.cols; 236 | 237 | ////////////////////////////////////////////////////////////////////////// 238 | ///// create integral images 239 | cv::Mat tsum,tsqsum; 240 | if(sum.empty()||sqsum.empty()){ 241 | cv::integral(_src1x,tsum,tsqsum,CV_64F); 242 | }else{ 243 | tsum = sum; 244 | tsqsum = sqsum; 245 | } 246 | 247 | ////////////////////////////////////////////////////////////////////////// 248 | ///// process 249 | for(int i=0;i(i)[j]; 262 | }else if(_src1x.type()==CV_32FC1){ 263 | current_src_value = _src1x.ptr(i)[j]; 264 | }else{ 265 | assert(false); 266 | } 267 | 268 | ////////////////////////////////////////////////////////////////////////// 269 | // calc Gaussian's cdf 270 | double cdf = calcCDF_Gaussian(current_src_value,mean,sd); 271 | 272 | ////////////////////////////////////////////////////////////////////////// 273 | // get output 274 | if(tdst.type()==CV_8UC1){ 275 | if(current_src_value >= mean-1.885*sd){ 276 | tdst.data[i*width+j] = cvRound(cdf*255.); 277 | }else{ 278 | tdst.data[i*width+j] = 0; 279 | } 280 | CV_DbgAssert(((uchar*)tdst.data)[i*width+j]>=0.&&((uchar*)tdst.data)[i*width+j]<=255.); 281 | }else if(tdst.type()==CV_32FC1){ 282 | if(current_src_value >= mean-1.885*sd){ 283 | ((float*)tdst.data)[i*width+j] = cvRound(cdf*255.); 284 | }else{ 285 | ((float*)tdst.data)[i*width+j] = 0; 286 | } 287 | CV_DbgAssert(((float*)tdst.data)[i*width+j]>=0.&&((float*)tdst.data)[i*width+j]<=255.); 288 | }else{ 289 | CV_Assert(false); 290 | } 291 | } 292 | } 293 | 294 | ////////////////////////////////////////////////////////////////////////// 295 | ///// copy to dst 296 | if(src.channels()==1){ 297 | dst = tdst.clone(); 298 | }else if(src.channels()==3){ 299 | int from_to[]={0,0}; 300 | mixChannels(&tdst,1,&_src3x,1,from_to,1); 301 | cvtColor(_src3x,dst,CV_Lab2BGR); 302 | }else{ 303 | CV_Error(CV_StsUnsupportedFormat,"[pixkit::enhancement::local::POHE2013] images should be grayscale or color."); 304 | } 305 | 306 | return true; 307 | } 308 | -------------------------------------------------------------------------------- /modules/pixkit-image/src/DBSBTC2011/DBSBTC2011.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "../../include/pixkit-image.hpp" 3 | 4 | // iteration-based converting for local min & max (quantization level version) 5 | bool DirectBinarySearch_QLver(const cv::Mat &src, cv::Mat &dst, double highValue, double lowValue){ 6 | 7 | ////////////////////////////////////////////////////////////////////////// 8 | // exception 9 | if(src.empty()){ 10 | CV_Error(CV_HeaderIsNull,"[DirectBinarySearch_QLver] image is empty"); 11 | return false; 12 | } 13 | 14 | if(src.type()!=CV_8U){ 15 | CV_Error(CV_BadNumChannels,"[DirectBinarySearch_QLver] image should be grayscale"); 16 | return false; 17 | } 18 | 19 | dst.create(src.size(), src.type()); 20 | srand( static_cast< unsigned int >(time(NULL)) ); 21 | // ========================================= 22 | // initialize the dst_reg 23 | for (int i=0; i(rand()) / static_cast(RAND_MAX); 26 | if (pixel < 0.5) { 27 | dst.data[i*dst.cols + j] = static_cast< unsigned char >(lowValue); 28 | } 29 | else { 30 | dst.data[i*dst.cols + j] = static_cast< unsigned char >(highValue); 31 | } 32 | } 33 | } 34 | 35 | // ======================================================== 36 | // gauss filter initial 37 | const int FilterHeight = 7; 38 | const int FilterWidth = 7; 39 | std::vector< std::vector< double > > G_filter(FilterHeight, std::vector(FilterWidth)); 40 | int FilterHalfSize = (static_cast(FilterHeight) - 1) / 2; 41 | double std = static_cast(FilterHeight-1)/6, sum = 0; 42 | 43 | for (int i=-FilterHalfSize; i<=FilterHalfSize; i++){ 44 | for (int j=-FilterHalfSize; j<=FilterHalfSize; j++){ 45 | G_filter[i+FilterHalfSize][j+FilterHalfSize] = exp( -1 * (i*i+j*j) / (2*std*std) ); 46 | sum += G_filter[i+FilterHalfSize][j+FilterHalfSize]; 47 | } 48 | } 49 | 50 | // Normalize to 0~1 51 | for (int i=-FilterHalfSize; i<=FilterHalfSize; i++){ 52 | for (int j=-FilterHalfSize; j<=FilterHalfSize; j++){ 53 | G_filter[i+FilterHalfSize][j+FilterHalfSize] /= sum; 54 | } 55 | } 56 | // ======================================================== 57 | // CPP, E initial 58 | int HalfSize = (FilterHeight-1)/2; 59 | int CPPHeight = FilterHeight + 2*HalfSize; 60 | int CPPWidth = FilterWidth + 2*HalfSize; 61 | int ErHeight = src.rows; 62 | int ErWidth = src.cols; 63 | std::vector< std::vector< double > > CPP_Image(CPPHeight, std::vector< double >(CPPWidth)); 64 | std::vector< std::vector< double > > Er_Image(ErHeight, std::vector< double >(ErWidth)); 65 | 66 | for (int i = 0 ; i < FilterHeight ; i++){ 67 | for (int j = 0 ; j < FilterWidth ; j++){ 68 | for (int y = 0 ; y < FilterHeight; y++){ 69 | for (int x = 0 ; x < FilterWidth ; x++){ 70 | CPP_Image[i+y][j+x] += G_filter[i][j]*G_filter[y][x]; 71 | } 72 | } 73 | } 74 | } 75 | 76 | for (int i = 0 ; i < ErHeight ; i++){ 77 | for (int j = 0 ; j < ErWidth ; j++){ 78 | dst.data[i*ErWidth + j] = static_cast((dst.data[i*ErWidth + j] - lowValue) / (highValue - lowValue)); 79 | Er_Image[i][j] = (dst.data[i*ErWidth + j]) - ((src.data[i*ErWidth + j] - lowValue) / (highValue - lowValue)); 80 | } 81 | } 82 | 83 | // ======================================================== 84 | // CEP initial 85 | int HalfCPPSize = (CPPHeight-1)/2; 86 | int CEPHeight = ErHeight + 2*HalfCPPSize; 87 | int CEPWidth = ErWidth + 2*HalfCPPSize; 88 | std::vector< std::vector< double > > CEP_Image(CEPHeight, std::vector< double >(CEPWidth)); 89 | 90 | for (int i = 0 ; i < ErHeight ; i++){ 91 | for (int j = 0 ; j < ErWidth ; j++){ 92 | double sum = 0.; 93 | for(int y = -HalfCPPSize ; y <= HalfCPPSize ; y++){ 94 | for(int x = -HalfCPPSize ; x <= HalfCPPSize ; x++){ 95 | if (i+y < 0 || i+y >= ErHeight || j+x < 0 || j+x >= ErWidth){ 96 | continue; 97 | } 98 | else{ 99 | sum += Er_Image[i+y][j+x] * CPP_Image[y+HalfCPPSize][x+HalfCPPSize]; 100 | } 101 | } 102 | } 103 | CEP_Image[i+HalfCPPSize][j+HalfCPPSize] = sum; 104 | } 105 | } 106 | 107 | // ======================================================== 108 | // DBS process 109 | double CurrentError = 0; 110 | for (int i = 0 ; i < CEPHeight ; i++){ 111 | for (int j = 0 ; j < CEPWidth ; j++){ 112 | CurrentError += CEP_Image[i][j]; 113 | } 114 | } 115 | double PastError = 0.; 116 | double EPS = 0.; 117 | double EPS_MIN = 0.; 118 | while (fabs(CurrentError - PastError)>=1) 119 | { 120 | PastError = CurrentError; 121 | 122 | double a0 = 0., a1 = 0., Current_a0 = 0., Current_a1 = 0.; 123 | CurrentError = 0; 124 | int CurrentPx = 0; 125 | int CurrentPy = 0; 126 | 127 | for (int i = 0 ; i < dst.rows ; i++){ 128 | for (int j = 0 ; j < dst.cols ; j++){ 129 | 130 | Current_a0 = 0.; 131 | Current_a1 = 0.; 132 | CurrentPx = 0; 133 | CurrentPy = 0; 134 | EPS_MIN = 0.; 135 | for (int y = -1 ; y <= 1 ; y++){ 136 | if (i+y < 0 || i+y >= dst.rows){ 137 | continue; 138 | } 139 | for (int x = -1 ; x <= 1 ; x++){ 140 | if (j+x < 0 || j+x >= dst.cols){ 141 | continue; 142 | } 143 | if (y == 0 && x == 0){ // toggle 144 | if (dst.data[i*dst.cols + j] == 1){ //dst.data[i*dst.cols + j] == highValue (1 -> 0) 145 | a0 = -1; //a0 = -(highValue - lowValue); 146 | a1 = 0; 147 | }else{ // 0 -> 1 148 | a0 = 1; //a0 = (highValue - lowValue); 149 | a1 = 0; 150 | } 151 | }else{ // Swap 152 | if (dst.data[(i+y)*dst.cols + (j+x)] != dst.data[i*dst.cols + j]){ 153 | if (dst.data[i*dst.cols + j] == 1){ //dst.data[i*dst.cols + j] == highValue (1 -> 0) 154 | a0 = -1; //a0 = -(h1ighValue - lowValue); 155 | a1 = -a0; 156 | }else{ // 0 -> 1 157 | a0 = 1; //a0 = (highValue - lowValue); 158 | a1 = -a0; 159 | } 160 | }else{ 161 | a0 = 0; 162 | a1 = 0; 163 | } 164 | } 165 | EPS = (a0*a0+a1*a1)*CPP_Image[HalfCPPSize][HalfCPPSize] + 166 | 2*a0*a1*CPP_Image[HalfCPPSize + y][HalfCPPSize + x] + 167 | 2*a0*CEP_Image[i + HalfCPPSize][j + HalfCPPSize] + 168 | 2*a1*CEP_Image[i + y + HalfCPPSize][j + x + HalfCPPSize]; 169 | 170 | if (EPS_MIN > EPS){ 171 | EPS_MIN = EPS; 172 | Current_a0 = a0; 173 | Current_a1 = a1; 174 | CurrentPx = x; 175 | CurrentPy = y; 176 | } 177 | } 178 | } 179 | if(EPS_MIN < 0){ 180 | for(int y = -HalfCPPSize ; y <= HalfCPPSize ; y++){ 181 | for(int x = -HalfCPPSize ; x <= HalfCPPSize ; x++){ 182 | CEP_Image[i+y+HalfCPPSize][j+x+HalfCPPSize] += Current_a0*CPP_Image[y+HalfCPPSize][x+HalfCPPSize]; 183 | } 184 | } 185 | for(int y = -HalfCPPSize ; y <= HalfCPPSize ; y++){ 186 | for(int x = -HalfCPPSize ; x <= HalfCPPSize ; x++){ 187 | CEP_Image[i+y+CurrentPy+HalfCPPSize][j+x+CurrentPx+HalfCPPSize] += Current_a1*CPP_Image[y+HalfCPPSize][x+HalfCPPSize]; 188 | } 189 | } 190 | dst.data[i*dst.cols + j] += static_cast < int > (Current_a0); 191 | dst.data[(i+CurrentPy)*dst.cols + (j+CurrentPx)] += static_cast < int > (Current_a1); 192 | } 193 | } 194 | } 195 | 196 | for (int y = 0 ; y < CEPHeight ; y++){ 197 | for (int x = 0 ; x < CEPWidth ; x++){ 198 | CurrentError += CEP_Image[y][x]; 199 | } 200 | } 201 | } 202 | // DBS process 203 | 204 | for (int i = 0 ; i < dst.rows ; i++){ 205 | for (int j = 0 ; j < dst.cols ; j++){ 206 | if (dst.data[i*ErWidth + j] == 1){ 207 | dst.data[i*ErWidth + j] = static_cast< unsigned char >(highValue); 208 | } 209 | else{ 210 | dst.data[i*ErWidth + j] = static_cast< unsigned char >(lowValue); 211 | } 212 | } 213 | } 214 | return true; 215 | } 216 | 217 | // BTC iteration-based converting by using "alpha data" 218 | bool pixkit::comp::DBSBTC2011(cv::Mat src, cv::Mat &dst, int blockSize) 219 | { 220 | ////////////////////////////////////////////////////////////////////////// 221 | // exception 222 | if(src.empty()){ 223 | CV_Error(CV_HeaderIsNull,"[comp::DBSBTC2011] image is empty"); 224 | return false; 225 | } 226 | if(src.type()!=CV_8U){ 227 | CV_Error(CV_BadNumChannels,"[comp::DBSBTC2011] image type should be gray scale"); 228 | return false; 229 | } 230 | if(blockSize!=8 && blockSize!=16){ 231 | CV_Error(CV_StsBadArg,"[comp::DBSBTC2011] BlockSize should be 8 or 16."); 232 | return false; 233 | } 234 | 235 | // ======================================== 236 | std::vector < int > histo(256); 237 | dst.create(src.size(), src.type()); 238 | int alphaSize = 0, segSize = 0; 239 | 240 | // Read training alpha data 241 | if(blockSize == 8){ 242 | alphaSize = 2; 243 | segSize = 3; 244 | }else if(blockSize == 16){ 245 | alphaSize = 3; 246 | segSize = 4; 247 | }else{ 248 | CV_Error(CV_StsBadArg,"[comp::DBSBTC2011] BlockSize should be 8 or 16."); 249 | return false; 250 | } 251 | 252 | std::vector < double > alphaData(alphaSize); 253 | std::vector < double > segData(segSize); 254 | 255 | if(blockSize == 8){ 256 | const double alpha[2][3] = { 257 | {0.180000, 0.200000}, 258 | {0.000000, 0.903090, 1.806180} }; 259 | 260 | for (int i=0; i!=alphaData.size(); i++){ 261 | alphaData[i] = alpha[0][i]; 262 | } 263 | for (int i=0; i!=segData.size(); i++){ 264 | segData[i] = alpha[1][i]; 265 | } 266 | 267 | }else if(blockSize == 16){ 268 | const double alpha[3][4] = { 269 | {0.080000, 0.170000, 0.170000}, 270 | {0.000000, 1.204120, 1.806180, 2.408240} }; 271 | 272 | for (int i=0; i!=alphaData.size(); i++){ 273 | alphaData[i] = alpha[0][i]; 274 | } 275 | for (int i=0; i!=segData.size(); i++){ 276 | segData[i] = alpha[1][i]; 277 | } 278 | }else{ 279 | CV_Error(CV_StsBadArg,"[comp::DBSBTC2011] BlockSize should be 8 or 16."); 280 | return false; 281 | } 282 | 283 | // ======================================== 284 | for (int i=0; i( src.data[(i+m)*src.cols + (j+n)] ); 296 | histo[pixelIndex]++; 297 | } 298 | } 299 | 300 | for (int k=0; k!=histo.size(); k++){ 301 | if (histo[k]!=0){ 302 | double prob = histo[k] / static_cast(blockSize*blockSize); 303 | entropy += (-log10(prob) * prob); 304 | } 305 | } 306 | 307 | // ========================================= 308 | // max & min & mean 309 | double alpha; 310 | double max = 0, min = 255, mean = 0; 311 | 312 | for (int m=0; m max){ 315 | max = src.data[(i+m)*src.cols +(j+n)]; 316 | } 317 | if (src.data[(i+m)*src.cols +(j+n)] < min){ 318 | min = src.data[(i+m)*src.cols +(j+n)]; 319 | } 320 | mean += src.data[(i+m)*src.cols +(j+n)]; 321 | } 322 | } 323 | mean /= static_cast(blockSize*blockSize); 324 | 325 | for (int k=0; k!=alphaData.size(); k++){ 326 | if (segData[k]<=entropy && segData[k+1]>entropy){ 327 | alpha = alphaData[k]; 328 | max = max-(alpha*(max-mean)); 329 | min = min+(alpha*(mean-min)); 330 | break; 331 | } 332 | } 333 | 334 | cv::Mat src_reg, dst_reg; 335 | src_reg.create(blockSize, blockSize, 0); 336 | 337 | // copy block information 338 | for (int m=0; m