[2615] | 1 | #include "sopnamsp.h"
|
---|
[244] | 2 | #include "machdefs.h"
|
---|
[220] | 3 | #include <stdlib.h>
|
---|
| 4 | #include <stdio.h>
|
---|
| 5 |
|
---|
| 6 | #include "fmath.h"
|
---|
| 7 | #include "perandom.h"
|
---|
| 8 |
|
---|
| 9 | #include "cimage.h"
|
---|
| 10 |
|
---|
| 11 | #include "dynccd.h"
|
---|
| 12 |
|
---|
| 13 | //++
|
---|
| 14 | // Class DynCCD
|
---|
| 15 | // Lib Images++
|
---|
| 16 | // include dynccd.h
|
---|
| 17 | //
|
---|
| 18 | // Cette classe permet la specification des parametres
|
---|
| 19 | // definissant la dynamique du CCD, et doit etre utilise
|
---|
| 20 | // pour le calcul des images de bruit.
|
---|
| 21 | // - TypNoise = 1 :
|
---|
| 22 | // Bruit = Sqrt( (RONoise/Gain)**2 + ValPix/Gain )
|
---|
| 23 | // - TypNoise = 2 :
|
---|
| 24 | // Bruit = Sqrt( RefSFond**2 + (ValPix-RefFond)/Gain )
|
---|
| 25 | // - TypNoise = 0
|
---|
| 26 | // Bruit = 1 (Constant pour tous les pixels)
|
---|
| 27 | // - TypNoise = 3
|
---|
| 28 | // Bruit = Sqrt(Abs(ValPix))
|
---|
| 29 | //
|
---|
| 30 | // Les pixels hors dynamique sont marques (Bruit = 0)
|
---|
| 31 | // ( < MinADU ou > MaxADU) pour toutes valeurs de TypNoise.
|
---|
| 32 | // Gain est exprime en electron par ADU, RONoise en electron,
|
---|
| 33 | // Bruit, ValPix et RefFond en ADU.
|
---|
| 34 | //--
|
---|
| 35 |
|
---|
| 36 | //++
|
---|
| 37 | // Links Parents
|
---|
| 38 | // PPersist
|
---|
| 39 | //--
|
---|
| 40 | //++
|
---|
| 41 | // Links Autres
|
---|
| 42 | // RzImage
|
---|
| 43 | // Image<T>
|
---|
| 44 | //--
|
---|
| 45 | //++
|
---|
| 46 | // Titre Methodes
|
---|
| 47 | //--
|
---|
| 48 | //++
|
---|
[1104] | 49 | // DynCCD(int_4TypNoise=0, r_8 MinADU=-9.e19, r_8 MaxADU=9.e19, r_8 Gain=1., r_8 RONoise=0., r_8 RefFond=0., r_8 RefSFond=0.);
|
---|
[220] | 50 | // Creation d'un objet DynCCD ("typ" determine la methode de calcul du bruit)
|
---|
| 51 | // |Test verbatim
|
---|
| 52 | //
|
---|
[1104] | 53 | // void Set(int_4TypNoise=0, r_8 MinADU=-9.e19, r_8 MaxADU=9.e19, r_8 Gain=1., r_8 RONoise=0., r_8 RefFond=0., r_8 RefSFond=0.);
|
---|
[220] | 54 | // Modification des parametres de la dynamique
|
---|
| 55 | // void Print()
|
---|
[1104] | 56 | // r_8 Noise(r_8 pixel) const
|
---|
[220] | 57 | // Renvoie la valeur du bruit pour "pixel" en ADU.
|
---|
| 58 | //--
|
---|
| 59 |
|
---|
| 60 | /* ............................................................ */
|
---|
| 61 | /* ::::::::::::: methode de la classe DynCCD :::::::::::::::: */
|
---|
| 62 | /* ............................................................ */
|
---|
| 63 |
|
---|
| 64 | /* --Methode-- */
|
---|
[1104] | 65 | DynCCD::DynCCD(int_4 typ, r_8 min, r_8 max, r_8 g,
|
---|
| 66 | r_8 ron, r_8 rf, r_8 rfs)
|
---|
[220] | 67 | {
|
---|
| 68 | if ( (typ >= kConstantNoise) && (typ <= kSqrtADUNoise) ) TypNoise = typ;
|
---|
| 69 | else TypNoise = kConstantNoise;
|
---|
| 70 | MinADU = min; MaxADU = max;
|
---|
| 71 | Gain = g; RONoise = ron;
|
---|
| 72 | RefFond = rf; RefSFond = rfs;
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | /* --Methode-- */
|
---|
[1104] | 76 | void DynCCD::Set(int_4 typ, r_8 min, r_8 max, r_8 g,
|
---|
| 77 | r_8 ron, r_8 rf, r_8 rfs)
|
---|
[220] | 78 | {
|
---|
| 79 | if ( (typ >= kConstantNoise) && (typ <= kSqrtADUNoise) ) TypNoise = typ;
|
---|
| 80 | MinADU = min; MaxADU = max;
|
---|
| 81 | Gain = g; RONoise = ron;
|
---|
| 82 | RefFond = rf; RefSFond = rfs;
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | /* --Methode-- */
|
---|
| 86 | void DynCCD::Print()
|
---|
| 87 | {
|
---|
| 88 | printf("DynCCD: Type= %d Min/MaxADU= %g %g Gain/RoN= %g %g\n",
|
---|
| 89 | TypNoise, MinADU, MaxADU, Gain, RONoise);
|
---|
| 90 | if (TypNoise == 2)
|
---|
| 91 | printf("... RefFond= %g RefSFond= %g \n", RefFond, RefSFond);
|
---|
| 92 | return;
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | /* --Methode-- */
|
---|
[1104] | 96 | r_8 DynCCD::Noise(r_8 pixel) const
|
---|
[220] | 97 |
|
---|
| 98 | /* Cette fonction calcule la valeur du bruit pour pixel */
|
---|
| 99 | /* Si TypNoise = 1 : */
|
---|
| 100 | /* Bruit = Sqrt( (RONoise/Gain)**2 + ValPix/Gain ) */
|
---|
| 101 | /* Si TypNoise = 2 : */
|
---|
| 102 | /* Bruit = Sqrt( RefSFond**2 + (ValPix-RefFond)/Gain ) */
|
---|
| 103 | /* Si TypNoise = 0 */
|
---|
| 104 | /* Bruit = 1 (Constant pour tous les pixels) */
|
---|
| 105 | /* Si TypNoise = 3 */
|
---|
| 106 | /* Bruit = Sqrt(Abs(PixelADU)) */
|
---|
| 107 | /* Les pixels hors dynamique sont marques (Bruit = 0) */
|
---|
| 108 | /* ( < MinADU ou > MaxADU) pour tout valeur de TypNoise */
|
---|
| 109 |
|
---|
| 110 | {
|
---|
[1104] | 111 | r_8 h,s,ronsq;
|
---|
| 112 | r_8 fond;
|
---|
[220] | 113 |
|
---|
| 114 | if ( (pixel > MaxADU) || (pixel < MinADU) ) return(0.);
|
---|
| 115 | if ( TypNoise == kConstantNoise) return(1.);
|
---|
[2145] | 116 | if ( TypNoise == kSqrtADUNoise ) return(sqrt(fabs(pixel)));
|
---|
[220] | 117 |
|
---|
| 118 | if ( TypNoise == kSigFondNoise)
|
---|
| 119 | { fond = RefFond;
|
---|
| 120 | ronsq = RefSFond * RefSFond; }
|
---|
| 121 | else
|
---|
| 122 | { fond = 0;
|
---|
| 123 | ronsq = RONoise/Gain; ronsq *= ronsq; }
|
---|
| 124 |
|
---|
[1104] | 125 | h = (pixel>fond) ? (r_8)(pixel-fond) : 0.;
|
---|
[220] | 126 | s = ronsq+h/Gain;
|
---|
[2145] | 127 | s = sqrt(s);
|
---|
[220] | 128 | return(s);
|
---|
| 129 | }
|
---|
| 130 |
|
---|
| 131 | /* -------------------------------------------------------------- */
|
---|
| 132 | /* Quelques fonctions pour manipuler des images de bruit */
|
---|
| 133 | /* -------------------------------------------------------------- */
|
---|
| 134 |
|
---|
| 135 | //++
|
---|
| 136 | // Module Images de bruit
|
---|
| 137 | // Lib Images++
|
---|
| 138 | // include dynccd.h
|
---|
| 139 | //
|
---|
| 140 | // Ces fonctions permettent le calcul d'image de bruit a partir d'une
|
---|
| 141 | // image (RzImage ou Image<T>) et d'un objet DynCCD
|
---|
| 142 | //--
|
---|
| 143 | //++
|
---|
| 144 | // Links Voir classes
|
---|
| 145 | // DynCCD
|
---|
| 146 | // RzImage
|
---|
| 147 | // Image<T>
|
---|
| 148 | //--
|
---|
| 149 | //++
|
---|
| 150 | // Titre Les fonctions
|
---|
| 151 | //--
|
---|
| 152 |
|
---|
| 153 | //++
|
---|
| 154 | // Function RzImage * NoiseImage(RzImage const *pim, DynCCD const * dynccd)
|
---|
| 155 | // Construit et renvoie l'image du bruit pour l'image "*pim" (RzImage)
|
---|
| 156 | // Function Image<T> * NoiseImage(Image<T> const * pim, DynCCD const * dynccd)
|
---|
| 157 | // Meme fonctionalite pour une image typee (ImageU2, ImageR4, ...)
|
---|
| 158 | // Function ImgAddNoise(Image<T>&, DynCCD const&)
|
---|
| 159 | // Calcule l'image du bruit et le rajoute a l'image originale
|
---|
| 160 | //--
|
---|
| 161 |
|
---|
| 162 | /* Nouvelle-Fonction */
|
---|
| 163 | template <class T>
|
---|
[1110] | 164 | Image<T> NoiseImage(Image<T> const & pim, DynCCD const & dynccd)
|
---|
[220] | 165 |
|
---|
| 166 | /* Creation et Calcul d'une image de bruit a partir de l'image */
|
---|
| 167 | /* pim et de dynccd. Voir la methode DynCCD::Noise() pour la */
|
---|
| 168 | /* description du calcul */
|
---|
| 169 |
|
---|
| 170 | {
|
---|
[1104] | 171 | r_8 h,s,ronsq;
|
---|
| 172 | r_8 fond, min,max;
|
---|
| 173 | int_4 k, npix;
|
---|
| 174 | r_8 minois, offnois;
|
---|
[220] | 175 |
|
---|
[1104] | 176 | npix = pim.XSize()*pim.YSize();
|
---|
| 177 | Image<T> nois(pim.XSize(), pim.YSize());
|
---|
| 178 | nois.SetOrg(pim.XOrg(), pim.YOrg());
|
---|
[220] | 179 |
|
---|
[1104] | 180 | min = dynccd.MinADU; max = dynccd.MaxADU;
|
---|
| 181 | for(k=0; k<npix; k++) {
|
---|
| 182 | if ( (pim[k] <= max) && (pim[k] >= min) ) nois[k] = (T)1;
|
---|
| 183 | else nois[k] = 0;
|
---|
| 184 | }
|
---|
[220] | 185 |
|
---|
| 186 |
|
---|
| 187 | return(nois);
|
---|
| 188 | }
|
---|
| 189 |
|
---|
| 190 |
|
---|
| 191 | /* Nouvelle-Fonction */
|
---|
| 192 | template <class T>
|
---|
| 193 | void ImgAddNoise(Image<T>& img, DynCCD const& dyn)
|
---|
| 194 | {
|
---|
[1104] | 195 | int_4 nPix = img.XSize() * img.YSize();
|
---|
[220] | 196 |
|
---|
[1104] | 197 | for (int_4 i=0; i<nPix; i++)
|
---|
| 198 | img[i] += (T) (dyn.Noise(img[i])*NorRand());
|
---|
[220] | 199 | }
|
---|
| 200 |
|
---|
| 201 |
|
---|
| 202 |
|
---|
| 203 |
|
---|
| 204 |
|
---|
| 205 | #ifdef __CXX_PRAGMA_TEMPLATES__
|
---|
| 206 | #pragma define_template NoiseImage<uint_2>
|
---|
| 207 | #pragma define_template NoiseImage<int_4>
|
---|
| 208 | #pragma define_template NoiseImage<r_4>
|
---|
| 209 |
|
---|
| 210 | #pragma define_template ImgAddNoise<uint_2>
|
---|
| 211 | #pragma define_template ImgAddNoise<int_4>
|
---|
| 212 | #pragma define_template ImgAddNoise<r_4>
|
---|
| 213 | #endif
|
---|
| 214 |
|
---|
[1110] | 215 | #if defined(ANSI_TEMPLATES) || defined(__GNU_TEMPLATES__)
|
---|
| 216 | template Image<uint_2> NoiseImage<uint_2>(Image<uint_2> const& , DynCCD const&);
|
---|
| 217 | template Image< int_4> NoiseImage< int_4>(Image< int_4> const& , DynCCD const&);
|
---|
| 218 | template Image< r_4> NoiseImage< r_4>(Image< r_4> const& , DynCCD const&);
|
---|
[220] | 219 |
|
---|
| 220 | template void ImgAddNoise<uint_2>(Image<uint_2>&, DynCCD const&);
|
---|
| 221 | template void ImgAddNoise< int_4>(Image< int_4>&, DynCCD const&);
|
---|
| 222 | template void ImgAddNoise< r_4>(Image< r_4>&, DynCCD const&);
|
---|
| 223 | #endif
|
---|