Merge pull request #2887 from ilya-lavrenov:ipp_morph_fix
[platform/upstream/opencv.git] / samples / cpp / logpolar_bsm.cpp
1 /*Authors
2 * Manuela Chessa, Fabio Solari, Fabio Tatti, Silvio P. Sabatini
3 *
4 * manuela.chessa@unige.it, fabio.solari@unige.it
5 *
6 * PSPC-lab - University of Genoa
7 */
8
9 #include "opencv2/contrib.hpp"
10 #include "opencv2/highgui.hpp"
11
12 #include <iostream>
13 #include <cmath>
14
15 using namespace cv;
16 using namespace std;
17
18 static void help()
19 {
20     cout << "LogPolar Blind Spot Model sample.\nShortcuts:"
21         "\n\tn for nearest pixel technique"
22         "\n\tb for bilinear interpolation technique"
23         "\n\to for overlapping circular receptive fields"
24         "\n\ta for adjacent receptive fields"
25         "\n\tq or ESC quit\n";
26 }
27
28 int main(int argc, char** argv)
29 {
30     Mat img = imread(argc > 1 ? argv[1] : "lena.jpg",1); // open the image
31     if(img.empty()) // check if we succeeded
32     {
33         cout << "can not load image\n";
34         return 0;
35     }
36     help();
37
38     Size s=img.size();
39     int w=s.width, h=s.height;
40     int ro0=3; //radius of the blind spot
41     int R=120;  //number of rings
42
43     //Creation of the four different objects that implement the four log-polar transformations
44     //Off-line computation
45     Point2i center(w/2,h/2);
46     LogPolar_Interp nearest(w, h, center, R, ro0, INTER_NEAREST);
47     LogPolar_Interp bilin(w,h, center,R,ro0);
48     LogPolar_Overlapping overlap(w,h,center,R,ro0);
49     LogPolar_Adjacent adj(w,h,center,R,ro0,0.25);
50
51     namedWindow("Cartesian",1);
52     namedWindow("retinal",1);
53     namedWindow("cortical",1);
54     int wk='n';
55     Mat Cortical, Retinal;
56
57     //On-line computation
58     for(;;)
59     {
60         if(wk=='n'){
61             Cortical=nearest.to_cortical(img);
62             Retinal=nearest.to_cartesian(Cortical);
63         }else if (wk=='b'){
64             Cortical=bilin.to_cortical(img);
65             Retinal=bilin.to_cartesian(Cortical);
66         }else if (wk=='o'){
67             Cortical=overlap.to_cortical(img);
68             Retinal=overlap.to_cartesian(Cortical);
69         }else if (wk=='a'){
70             Cortical=adj.to_cortical(img);
71             Retinal=adj.to_cartesian(Cortical);
72         }
73
74         imshow("Cartesian", img);
75         imshow("cortical", Cortical);
76         imshow("retinal", Retinal);
77
78         int c=waitKey(15);
79         if (c>0) wk=c;
80         if(wk =='q' || (wk & 255) == 27) break;
81     }
82
83     return 0;
84 }