| [224] | 1 | // Utilisation des flots d'entree-sortie C++ | 
|---|
| [2322] | 2 | #include <iostream> | 
|---|
| [224] | 3 | // Utilisation de la classe Image<T> | 
|---|
| [768] | 4 | #include "ntoolsinit.h" | 
|---|
| [1161] | 5 | #include "array.h" | 
|---|
| [224] | 6 | #include "cimage.h" | 
|---|
|  | 7 | // Utilisation des generateurs aleatoires | 
|---|
|  | 8 | #include "nbrandom.h" | 
|---|
|  | 9 |  | 
|---|
| [271] | 10 | // Test des NDataBlock | 
|---|
|  | 11 | #include "ndatablock.h" | 
|---|
| [837] | 12 | #include "fiondblock.h" | 
|---|
| [271] | 13 | #include <complex> | 
|---|
| [224] | 14 |  | 
|---|
| [271] | 15 |  | 
|---|
| [224] | 16 | // -------- Le programme principal --------- | 
|---|
|  | 17 |  | 
|---|
|  | 18 | main(int narg, char *arg[]) | 
|---|
|  | 19 | { | 
|---|
|  | 20 | int i,j; | 
|---|
| [1161] | 21 | double mean,sig; | 
|---|
| [224] | 22 |  | 
|---|
| [1161] | 23 | try { | 
|---|
| [224] | 24 | // ----- ATTENTION ------- | 
|---|
| [768] | 25 | // Initialisation de Sophya | 
|---|
| [224] | 26 | // A faire au debut de main() | 
|---|
| [768] | 27 | SophyaInit(); | 
|---|
| [224] | 28 |  | 
|---|
|  | 29 | cout << " ........ Debut de timg.cc ....... " << endl; | 
|---|
|  | 30 | // declaration et creation d'une image de type flottant 300x200 | 
|---|
|  | 31 | ImageR4  img(300, 200); | 
|---|
| [254] | 32 | ImageR4  imgo(300, 200); | 
|---|
| [224] | 33 | // Remplissage de l'image Tirage aleatoire plat entre 1000-2000 | 
|---|
|  | 34 | for(i=0; i<300; i++) | 
|---|
| [254] | 35 | for(j=0; j<200; j++) img(i,j) = imgo(i,j) =  frand01()*1000.+1000.; | 
|---|
| [224] | 36 | // Verification de la dynamique de l'image | 
|---|
| [1161] | 37 | MeanSigma(img, mean, sig); | 
|---|
|  | 38 | cout << " img: Mean= " << mean << " Sigma= " << sig << endl; | 
|---|
|  | 39 | cout << img ; | 
|---|
|  | 40 |  | 
|---|
| [224] | 41 | // On sauve l'image ds img.ppf (fichier  format PPersist) | 
|---|
| [1161] | 42 | { | 
|---|
|  | 43 | POutPersist po("img.ppf"); | 
|---|
|  | 44 | po << img; | 
|---|
|  | 45 | } | 
|---|
| [224] | 46 |  | 
|---|
|  | 47 | // On rajoute du bruit a l'image (Gaussienne de sigma=3) | 
|---|
|  | 48 | for(i=0; i<300; i++) | 
|---|
|  | 49 | for(j=0; j<200; j++) img(i,j) += NorRand()*3. ; | 
|---|
|  | 50 |  | 
|---|
|  | 51 | // Verification de la dynamique de l'image | 
|---|
| [1161] | 52 | MeanSigma(img, mean, sig); | 
|---|
|  | 53 | cout << "ApresNoise img: Mean= " << mean << " Sigma= " << sig << endl; | 
|---|
| [224] | 54 |  | 
|---|
|  | 55 | // On verifie la date de creation du fichier .ppf | 
|---|
|  | 56 | { | 
|---|
|  | 57 | string ppfname = "img.ppf"; | 
|---|
|  | 58 | PInPersist pin(ppfname, false); | 
|---|
|  | 59 | cout << "Fichier PPF: " << ppfname << " Version= " << pin.Version() | 
|---|
|  | 60 | << " Created: " << pin.CreationDate() << endl; | 
|---|
|  | 61 | } | 
|---|
| [1161] | 62 |  | 
|---|
| [224] | 63 | // On cree une nouvelle image | 
|---|
|  | 64 | ImageR4  img2; | 
|---|
|  | 65 | // On lit le contenu du fichier imgin.ppf | 
|---|
| [1161] | 66 | { | 
|---|
|  | 67 | PInPersist pi("img.ppf"); | 
|---|
|  | 68 | pi >> img2; | 
|---|
|  | 69 | } | 
|---|
|  | 70 |  | 
|---|
| [224] | 71 | // On calcule la difference entre les images img et img2 | 
|---|
| [254] | 72 | //    Avant ajout de bruit | 
|---|
|  | 73 | cout << "\n imgo(sansbruit) - img2 (fromfile) == 0 ? " << endl; | 
|---|
|  | 74 | imgo -= img2; | 
|---|
|  | 75 | // Verification de la dynamique de l'image soustraite | 
|---|
| [1161] | 76 | r_4 min,max; | 
|---|
|  | 77 | imgo.MinMax(min, max); | 
|---|
|  | 78 | cout << " Min(imgo) = " << min << " Max(imgo) = " << max << endl; | 
|---|
| [254] | 79 |  | 
|---|
|  | 80 | //    Apres  ajout de bruit | 
|---|
| [1161] | 81 | cout << " img(avecbruit) - img2 (fromfile) == Noise, sigma=3 ? " << endl; | 
|---|
| [224] | 82 | img -= img2; | 
|---|
|  | 83 | // Verification de la dynamique de l'image soustraite | 
|---|
| [1161] | 84 | imgo.MinMax(min, max); | 
|---|
|  | 85 | cout << " Min(img) = " << min << " Max(img) = " << max << endl; | 
|---|
|  | 86 | MeanSigma(img, mean, sig); | 
|---|
|  | 87 | cout << "Apres img -= img2 img: Mean= " << mean << " Sigma= " << sig << endl; | 
|---|
| [224] | 88 |  | 
|---|
| [271] | 89 | // ---- Test des NDataBlock | 
|---|
|  | 90 | cout << "\n ----------> Test des NDataBlock <r_8>" << endl; | 
|---|
|  | 91 | NDataBlock<r_8> db(20); | 
|---|
|  | 92 | for(i=0; i<20; i++) db(i) = i*5.; | 
|---|
|  | 93 | cout << " DataBlock<r_8> i*5 : (db)" << endl; | 
|---|
|  | 94 | cout << db << endl; | 
|---|
| [274] | 95 | NDataBlock<r_8> db2(db,false); | 
|---|
| [271] | 96 | cout << " DataBlock<r_8> (db2=db) - db" << endl; | 
|---|
|  | 97 | cout << db2-db << endl; | 
|---|
|  | 98 |  | 
|---|
|  | 99 | FIO_NDataBlock<r_8> fdb(db); | 
|---|
|  | 100 | fdb.Write("db_r8.ppf"); | 
|---|
|  | 101 | cout << " DataBlock<r_8> db -> File db_r8.ppf" << endl; | 
|---|
|  | 102 | FIO_NDataBlock<r_8> fdb2("db_r8.ppf"); | 
|---|
|  | 103 | cout << " DataBlock<r_8> Frome file(db_r8.ppf) - db" << endl; | 
|---|
|  | 104 | cout << (NDataBlock<r_8>)fdb2-db << endl; | 
|---|
|  | 105 |  | 
|---|
|  | 106 | cout << "\n\n ----------> Test des NDataBlock <complex<double>>" << endl; | 
|---|
|  | 107 | NDataBlock< complex<double> > zb(20); | 
|---|
|  | 108 | for(i=0; i<20; i++) {complex<double> z(i*10., 0.1*i); zb(i) = z; } | 
|---|
|  | 109 | cout << " DataBlock<complex<double>>  (zb) = " << endl; | 
|---|
|  | 110 | cout << zb << endl; | 
|---|
|  | 111 | FIO_NDataBlock< complex<double> > fzb(zb); | 
|---|
|  | 112 | fzb.Write("zb_z8.ppf"); | 
|---|
|  | 113 | FIO_NDataBlock< complex<double> > fzb2("zb_z8.ppf"); | 
|---|
|  | 114 | cout << " DataBlock<complex<double>> Frome file(zb_z8.ppf) - db" << endl; | 
|---|
|  | 115 | cout << (NDataBlock< complex<double> >)(fzb2) ; | 
|---|
|  | 116 |  | 
|---|
| [298] | 117 | cout << "\n -------> Test de typeinfo : " << endl; | 
|---|
|  | 118 | string st; | 
|---|
|  | 119 | ImageR4 ir; | 
|---|
|  | 120 | ImageU2* irp; | 
|---|
|  | 121 |  | 
|---|
|  | 122 | st = typeid(NDataBlock<r_8>).name(); | 
|---|
|  | 123 | cout << "typeid(NDataBlock<r_8>).name() = " << st << endl; | 
|---|
|  | 124 | st = typeid(ir).name(); | 
|---|
|  | 125 | cout << "typeid(ir).name() - " << st << endl; | 
|---|
|  | 126 | st = typeid(irp).name(); | 
|---|
|  | 127 | cout << "typeid(irp).name() - " << st << endl; | 
|---|
| [1161] | 128 | } | 
|---|
|  | 129 |  | 
|---|
|  | 130 | catch (PThrowable & exc) { | 
|---|
|  | 131 | cerr << "timg/Error Catched Exception " << (string)typeid(exc).name() | 
|---|
|  | 132 | << " - Msg= " << exc.Msg() << endl; | 
|---|
|  | 133 | } | 
|---|
|  | 134 | catch (...) { | 
|---|
|  | 135 | cerr << "timg/Error some other exception was caught ! " << endl; | 
|---|
|  | 136 | } | 
|---|
|  | 137 |  | 
|---|
| [271] | 138 | cout << "\n ========= Fin de timg.cc ======== " << endl; | 
|---|
| [224] | 139 | exit(0); | 
|---|
|  | 140 | } | 
|---|