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

Last change on this file since 3879 was 3615, checked in by cmv, 16 years ago

Modifs relatives a l'introduction de RandomGeneratorInterface + delete de srandgen.c, cmv 01/05/2009

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