1 | #include "sopnamsp.h"
|
---|
2 | #include "machdefs.h"
|
---|
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 SOPHYA::DynCCD
|
---|
15 | \ingroup NTools
|
---|
16 |
|
---|
17 | Cette classe permet la specification des parametres
|
---|
18 | definissant la dynamique du CCD, et doit etre utilise
|
---|
19 | pour le calcul des images de bruit.
|
---|
20 |
|
---|
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 | \sa SOPHYA::Image
|
---|
36 | */
|
---|
37 |
|
---|
38 |
|
---|
39 | /* ............................................................ */
|
---|
40 | /* ::::::::::::: methode de la classe DynCCD :::::::::::::::: */
|
---|
41 | /* ............................................................ */
|
---|
42 |
|
---|
43 | /* --Methode-- */
|
---|
44 | //! Creation d'un objet DynCCD ("typ" determine la methode de calcul du bruit)
|
---|
45 | DynCCD::DynCCD(int_4 typ, r_8 min, r_8 max, r_8 g,
|
---|
46 | r_8 ron, r_8 rf, r_8 rfs)
|
---|
47 | {
|
---|
48 | if ( (typ >= kConstantNoise) && (typ <= kSqrtADUNoise) ) TypNoise = typ;
|
---|
49 | else TypNoise = kConstantNoise;
|
---|
50 | MinADU = min; MaxADU = max;
|
---|
51 | Gain = g; RONoise = ron;
|
---|
52 | RefFond = rf; RefSFond = rfs;
|
---|
53 | }
|
---|
54 |
|
---|
55 | /* --Methode-- */
|
---|
56 | //! Modification des parametres de la dynamique
|
---|
57 | void DynCCD::Set(int_4 typ, r_8 min, r_8 max, r_8 g,
|
---|
58 | r_8 ron, r_8 rf, r_8 rfs)
|
---|
59 | {
|
---|
60 | if ( (typ >= kConstantNoise) && (typ <= kSqrtADUNoise) ) TypNoise = typ;
|
---|
61 | MinADU = min; MaxADU = max;
|
---|
62 | Gain = g; RONoise = ron;
|
---|
63 | RefFond = rf; RefSFond = rfs;
|
---|
64 | }
|
---|
65 |
|
---|
66 | /* --Methode-- */
|
---|
67 | void DynCCD::Print()
|
---|
68 | {
|
---|
69 | printf("DynCCD: Type= %d Min/MaxADU= %g %g Gain/RoN= %g %g\n",
|
---|
70 | TypNoise, MinADU, MaxADU, Gain, RONoise);
|
---|
71 | if (TypNoise == 2)
|
---|
72 | printf("... RefFond= %g RefSFond= %g \n", RefFond, RefSFond);
|
---|
73 | return;
|
---|
74 | }
|
---|
75 |
|
---|
76 | //! Renvoie la valeur du bruit pour "pixel" en ADU.
|
---|
77 | /*!
|
---|
78 | Cette fonction calcule la valeur du bruit pour pixel
|
---|
79 | - Si TypNoise = 1 :
|
---|
80 | Bruit = Sqrt( (RONoise/Gain)**2 + ValPix/Gain )
|
---|
81 | - Si TypNoise = 2 :
|
---|
82 | Bruit = Sqrt( RefSFond**2 + (ValPix-RefFond)/Gain )
|
---|
83 | - Si TypNoise = 0
|
---|
84 | Bruit = 1 (Constant pour tous les pixels)
|
---|
85 | - Si TypNoise = 3
|
---|
86 | Bruit = Sqrt(Abs(PixelADU))
|
---|
87 |
|
---|
88 | Les pixels hors dynamique sont marques (Bruit = 0)
|
---|
89 | ( < MinADU ou > MaxADU) pour tout valeur de TypNoise
|
---|
90 | */
|
---|
91 | /* --Methode-- */
|
---|
92 | r_8 DynCCD::Noise(r_8 pixel) const
|
---|
93 | {
|
---|
94 | r_8 h,s,ronsq;
|
---|
95 | r_8 fond;
|
---|
96 |
|
---|
97 | if ( (pixel > MaxADU) || (pixel < MinADU) ) return(0.);
|
---|
98 | if ( TypNoise == kConstantNoise) return(1.);
|
---|
99 | if ( TypNoise == kSqrtADUNoise ) return(sqrt(fabs(pixel)));
|
---|
100 |
|
---|
101 | if ( TypNoise == kSigFondNoise)
|
---|
102 | { fond = RefFond;
|
---|
103 | ronsq = RefSFond * RefSFond; }
|
---|
104 | else
|
---|
105 | { fond = 0;
|
---|
106 | ronsq = RONoise/Gain; ronsq *= ronsq; }
|
---|
107 |
|
---|
108 | h = (pixel>fond) ? (r_8)(pixel-fond) : 0.;
|
---|
109 | s = ronsq+h/Gain;
|
---|
110 | s = sqrt(s);
|
---|
111 | return(s);
|
---|
112 | }
|
---|
113 |
|
---|
114 | /* -------------------------------------------------------------- */
|
---|
115 | /* Quelques fonctions pour manipuler des images de bruit */
|
---|
116 | /* -------------------------------------------------------------- */
|
---|
117 |
|
---|
118 |
|
---|
119 | /* Nouvelle-Fonction */
|
---|
120 | /*!
|
---|
121 | Construit et renvoie l'image du bruit pour l'image "*pim"
|
---|
122 |
|
---|
123 | Creation et Calcul d'une image de bruit a partir de l'image
|
---|
124 | pim et de dynccd. Voir la methode DynCCD::Noise() pour la
|
---|
125 | description du calcul
|
---|
126 | */
|
---|
127 | template <class T>
|
---|
128 | Image<T> NoiseImage(Image<T> const & pim, DynCCD const & dynccd)
|
---|
129 |
|
---|
130 | {
|
---|
131 | r_8 h,s,ronsq;
|
---|
132 | r_8 fond, min,max;
|
---|
133 | int_4 k, npix;
|
---|
134 | r_8 minois, offnois;
|
---|
135 |
|
---|
136 | npix = pim.XSize()*pim.YSize();
|
---|
137 | Image<T> nois(pim.XSize(), pim.YSize());
|
---|
138 | nois.SetOrg(pim.XOrg(), pim.YOrg());
|
---|
139 |
|
---|
140 | min = dynccd.MinADU; max = dynccd.MaxADU;
|
---|
141 | for(k=0; k<npix; k++) {
|
---|
142 | if ( (pim[k] <= max) && (pim[k] >= min) ) nois[k] = (T)1;
|
---|
143 | else nois[k] = 0;
|
---|
144 | }
|
---|
145 |
|
---|
146 |
|
---|
147 | return(nois);
|
---|
148 | }
|
---|
149 |
|
---|
150 |
|
---|
151 | /* Nouvelle-Fonction */
|
---|
152 | //! Calcule l'image du bruit et le rajoute a l'image originale
|
---|
153 | template <class T>
|
---|
154 | void ImgAddNoise(Image<T>& img, DynCCD const& dyn)
|
---|
155 |
|
---|
156 | {
|
---|
157 | int_4 nPix = img.XSize() * img.YSize();
|
---|
158 |
|
---|
159 | for (int_4 i=0; i<nPix; i++)
|
---|
160 | img[i] += (T) (dyn.Noise(img[i])*NorRand());
|
---|
161 | }
|
---|
162 |
|
---|
163 |
|
---|
164 |
|
---|
165 |
|
---|
166 |
|
---|
167 | #ifdef __CXX_PRAGMA_TEMPLATES__
|
---|
168 | #pragma define_template NoiseImage<uint_2>
|
---|
169 | #pragma define_template NoiseImage<int_4>
|
---|
170 | #pragma define_template NoiseImage<r_4>
|
---|
171 |
|
---|
172 | #pragma define_template ImgAddNoise<uint_2>
|
---|
173 | #pragma define_template ImgAddNoise<int_4>
|
---|
174 | #pragma define_template ImgAddNoise<r_4>
|
---|
175 | #endif
|
---|
176 |
|
---|
177 | #if defined(ANSI_TEMPLATES) || defined(__GNU_TEMPLATES__)
|
---|
178 | #if defined( __IBMCPP__ )
|
---|
179 | namespace SOPHYA {
|
---|
180 | #endif
|
---|
181 | template Image<uint_2> NoiseImage<uint_2>(Image<uint_2> const& , DynCCD const&);
|
---|
182 | template Image< int_4> NoiseImage< int_4>(Image< int_4> const& , DynCCD const&);
|
---|
183 | template Image< r_4> NoiseImage< r_4>(Image< r_4> const& , DynCCD const&);
|
---|
184 |
|
---|
185 | template void ImgAddNoise<uint_2>(Image<uint_2>&, DynCCD const&);
|
---|
186 | template void ImgAddNoise< int_4>(Image< int_4>&, DynCCD const&);
|
---|
187 | template void ImgAddNoise< r_4>(Image< r_4>&, DynCCD const&);
|
---|
188 | #if defined( __IBMCPP__ )
|
---|
189 | }
|
---|
190 | #endif
|
---|
191 |
|
---|
192 | #endif
|
---|