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

Last change on this file since 3427 was 2882, checked in by ansari, 20 years ago

Pb instanciation explicite ds namespace (compil magique) - Reza 3/01/2006

File size: 5.2 KB
RevLine 
[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
[2808]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.
[220]20
[2808]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.
[220]34
[2808]35 \sa SOPHYA::Image
36*/
37
38
[220]39/* ............................................................ */
40/* ::::::::::::: methode de la classe DynCCD :::::::::::::::: */
41/* ............................................................ */
42
43/* --Methode-- */
[2808]44//! Creation d'un objet DynCCD ("typ" determine la methode de calcul du bruit)
[1104]45DynCCD::DynCCD(int_4 typ, r_8 min, r_8 max, r_8 g,
46 r_8 ron, r_8 rf, r_8 rfs)
[220]47{
48if ( (typ >= kConstantNoise) && (typ <= kSqrtADUNoise) ) TypNoise = typ;
49else TypNoise = kConstantNoise;
50MinADU = min; MaxADU = max;
51Gain = g; RONoise = ron;
52RefFond = rf; RefSFond = rfs;
53}
54
55/* --Methode-- */
[2808]56//! Modification des parametres de la dynamique
[1104]57void DynCCD::Set(int_4 typ, r_8 min, r_8 max, r_8 g,
58 r_8 ron, r_8 rf, r_8 rfs)
[220]59{
60if ( (typ >= kConstantNoise) && (typ <= kSqrtADUNoise) ) TypNoise = typ;
61MinADU = min; MaxADU = max;
62Gain = g; RONoise = ron;
63RefFond = rf; RefSFond = rfs;
64}
65
66/* --Methode-- */
67void DynCCD::Print()
68{
69printf("DynCCD: Type= %d Min/MaxADU= %g %g Gain/RoN= %g %g\n",
70 TypNoise, MinADU, MaxADU, Gain, RONoise);
71if (TypNoise == 2)
72 printf("... RefFond= %g RefSFond= %g \n", RefFond, RefSFond);
73return;
74}
75
[2808]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*/
[220]91/* --Methode-- */
[1104]92r_8 DynCCD::Noise(r_8 pixel) const
[220]93{
[1104]94r_8 h,s,ronsq;
95r_8 fond;
[220]96
97if ( (pixel > MaxADU) || (pixel < MinADU) ) return(0.);
98if ( TypNoise == kConstantNoise) return(1.);
[2145]99if ( TypNoise == kSqrtADUNoise ) return(sqrt(fabs(pixel)));
[220]100
101if ( TypNoise == kSigFondNoise)
102 { fond = RefFond;
103 ronsq = RefSFond * RefSFond; }
104else
105 { fond = 0;
106 ronsq = RONoise/Gain; ronsq *= ronsq; }
107
[1104]108h = (pixel>fond) ? (r_8)(pixel-fond) : 0.;
[220]109s = ronsq+h/Gain;
[2145]110s = sqrt(s);
[220]111return(s);
112}
113
114/* -------------------------------------------------------------- */
115/* Quelques fonctions pour manipuler des images de bruit */
116/* -------------------------------------------------------------- */
117
118
119/* Nouvelle-Fonction */
[2808]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*/
[220]127template <class T>
[1110]128Image<T> NoiseImage(Image<T> const & pim, DynCCD const & dynccd)
[220]129
130{
[1104]131r_8 h,s,ronsq;
132r_8 fond, min,max;
133int_4 k, npix;
134r_8 minois, offnois;
[220]135
[1104]136npix = pim.XSize()*pim.YSize();
137Image<T> nois(pim.XSize(), pim.YSize());
138nois.SetOrg(pim.XOrg(), pim.YOrg());
[220]139
[1104]140min = dynccd.MinADU; max = dynccd.MaxADU;
141for(k=0; k<npix; k++) {
142 if ( (pim[k] <= max) && (pim[k] >= min) ) nois[k] = (T)1;
143 else nois[k] = 0;
144}
[220]145
146
147return(nois);
148}
149
150
151/* Nouvelle-Fonction */
[2808]152//! Calcule l'image du bruit et le rajoute a l'image originale
[220]153template <class T>
154void ImgAddNoise(Image<T>& img, DynCCD const& dyn)
[2808]155
[220]156{
[1104]157 int_4 nPix = img.XSize() * img.YSize();
[220]158
[1104]159 for (int_4 i=0; i<nPix; i++)
160 img[i] += (T) (dyn.Noise(img[i])*NorRand());
[220]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
[1110]177#if defined(ANSI_TEMPLATES) || defined(__GNU_TEMPLATES__)
[2882]178#if defined( __IBMCPP__ )
[2870]179namespace SOPHYA {
[2882]180#endif
[1110]181template Image<uint_2> NoiseImage<uint_2>(Image<uint_2> const& , DynCCD const&);
182template Image< int_4> NoiseImage< int_4>(Image< int_4> const& , DynCCD const&);
183template Image< r_4> NoiseImage< r_4>(Image< r_4> const& , DynCCD const&);
[220]184
185template void ImgAddNoise<uint_2>(Image<uint_2>&, DynCCD const&);
186template void ImgAddNoise< int_4>(Image< int_4>&, DynCCD const&);
187template void ImgAddNoise< r_4>(Image< r_4>&, DynCCD const&);
[2882]188#if defined( __IBMCPP__ )
[2870]189}
[220]190#endif
[2882]191
192#endif
Note: See TracBrowser for help on using the repository browser.