| 1 | // Utilisation des flots d'entree-sortie C++
 | 
|---|
| 2 | #include <iostream>
 | 
|---|
| 3 | // Utilisation de la classe Image<T>
 | 
|---|
| 4 | #include "sopnamsp.h"
 | 
|---|
| 5 | #include "ntoolsinit.h"
 | 
|---|
| 6 | #include "array.h"
 | 
|---|
| 7 | #include "cimage.h"
 | 
|---|
| 8 | // Utilisation des generateurs aleatoires
 | 
|---|
| 9 | #include "srandgen.h"
 | 
|---|
| 10 | 
 | 
|---|
| 11 | // Test des NDataBlock
 | 
|---|
| 12 | #include "ndatablock.h"
 | 
|---|
| 13 | #include "fiondblock.h"
 | 
|---|
| 14 | #include <complex>
 | 
|---|
| 15 | 
 | 
|---|
| 16 | 
 | 
|---|
| 17 | // -------- Le programme principal ---------
 | 
|---|
| 18 | 
 | 
|---|
| 19 | main(int narg, char *arg[])
 | 
|---|
| 20 | {
 | 
|---|
| 21 | int i,j;
 | 
|---|
| 22 | double mean,sig;
 | 
|---|
| 23 | 
 | 
|---|
| 24 | try {
 | 
|---|
| 25 | // ----- ATTENTION -------
 | 
|---|
| 26 | // Initialisation de Sophya
 | 
|---|
| 27 | // A faire au debut de main()
 | 
|---|
| 28 | SophyaInit();
 | 
|---|
| 29 | 
 | 
|---|
| 30 | cout << " ........ Debut de timg.cc ....... " << endl;
 | 
|---|
| 31 | // declaration et creation d'une image de type flottant 300x200
 | 
|---|
| 32 | ImageR4  img(300, 200);
 | 
|---|
| 33 | ImageR4  imgo(300, 200);
 | 
|---|
| 34 | // Remplissage de l'image Tirage aleatoire plat entre 1000-2000
 | 
|---|
| 35 | for(i=0; i<300; i++)
 | 
|---|
| 36 |   for(j=0; j<200; j++) img(i,j) = imgo(i,j) =  drand01()*1000.+1000.;
 | 
|---|
| 37 | // Verification de la dynamique de l'image
 | 
|---|
| 38 | MeanSigma(img, mean, sig);
 | 
|---|
| 39 | cout << " img: Mean= " << mean << " Sigma= " << sig << endl;
 | 
|---|
| 40 | cout << img ; 
 | 
|---|
| 41 | 
 | 
|---|
| 42 | // On sauve l'image ds img.ppf (fichier  format PPersist)
 | 
|---|
| 43 | {
 | 
|---|
| 44 | POutPersist po("img.ppf");
 | 
|---|
| 45 | po << img;
 | 
|---|
| 46 | }
 | 
|---|
| 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
 | 
|---|
| 53 | MeanSigma(img, mean, sig);
 | 
|---|
| 54 | cout << "ApresNoise img: Mean= " << mean << " Sigma= " << sig << endl;
 | 
|---|
| 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 |   }
 | 
|---|
| 63 | 
 | 
|---|
| 64 | // On cree une nouvelle image 
 | 
|---|
| 65 | ImageR4  img2;
 | 
|---|
| 66 | // On lit le contenu du fichier imgin.ppf
 | 
|---|
| 67 | {
 | 
|---|
| 68 | PInPersist pi("img.ppf");
 | 
|---|
| 69 | pi >> img2;
 | 
|---|
| 70 | }
 | 
|---|
| 71 | 
 | 
|---|
| 72 | // On calcule la difference entre les images img et img2
 | 
|---|
| 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
 | 
|---|
| 77 | r_4 min,max;
 | 
|---|
| 78 | imgo.MinMax(min, max);
 | 
|---|
| 79 | cout << " Min(imgo) = " << min << " Max(imgo) = " << max << endl;
 | 
|---|
| 80 | 
 | 
|---|
| 81 | //    Apres  ajout de bruit
 | 
|---|
| 82 | cout << " img(avecbruit) - img2 (fromfile) == Noise, sigma=3 ? " << endl;
 | 
|---|
| 83 | img -= img2;
 | 
|---|
| 84 | // Verification de la dynamique de l'image soustraite
 | 
|---|
| 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;
 | 
|---|
| 89 | 
 | 
|---|
| 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;
 | 
|---|
| 96 | NDataBlock<r_8> db2(db,false);
 | 
|---|
| 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 | 
 | 
|---|
| 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;
 | 
|---|
| 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 | 
 | 
|---|
| 139 | cout << "\n ========= Fin de timg.cc ======== " << endl;
 | 
|---|
| 140 | exit(0);
 | 
|---|
| 141 | }
 | 
|---|