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