├── 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 | [](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 | 
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