source: Sophya/trunk/SophyaLib/NTools/dynccd.cc@ 1159

Last change on this file since 1159 was 1110, checked in by ansari, 25 years ago

on vire imageop.o de objlis.list
instanciations GNU des fct de dynccd.cc Noise... etc...
des fct passees en const dans GeneralFitData
objfitter prend les Histo/Histo2D/HProf/GeneralFitData

cmv 28/7/00

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