source: Sophya/trunk/SophyaLib/NTools/cimage.h@ 757

Last change on this file since 757 was 220, checked in by ansari, 26 years ago

Creation module DPC/NTools Reza 09/04/99

File size: 7.8 KB
Line 
1// This may look like C code, but it is really -*- C++ -*-
2// Classes image typee E.Aubourg , E. Lesquoy
3// Modifs R. Ansari 04/95
4
5// LAL (Orsay) / IN2P3-CNRS DAPNIA/SPP (Saclay) / CEA
6
7#ifndef CIMAGE_SEEN
8#define CIMAGE_SEEN
9
10#include <iostream.h>
11#include <iomanip.h>
12#include "rzimage.h"
13
14// Flags de verifications sur les indices dans rzimage.h
15
16//#define IMGRGCHECK
17//#define IMGVOIDCHECK
18
19
20// **********************************************************
21// Classe Image
22
23
24template <class T>
25class Image : public RzImage {
26
27public:
28 Image(int sizx, int sizy, int zero=1);
29 Image();
30 Image(const Image<T>&, int sharePixels=0);
31 Image(const Image<T>&, int orgx, int orgy, int sizx=-1, int sizy=-1);
32 EXPLICIT Image(const RzImage&); // Pour Reza. Partage les pixels
33 Image(char *flnm);
34 virtual ~Image();
35
36 int_4 ClassId() const { return (ClassId_Image+DataType((T)0)); }
37 static PPersist* Create() { return new Image<T>;}
38
39 virtual void ReadSelf(PInPersist&);
40
41 Image<T>& operator= (const Image<T> &);
42 Image<T>& operator= (T);
43
44 Image<T>& operator+= (Image<T> const&);
45 Image<T>& operator-= (Image<T> const&);
46 Image<T>& operator*= (Image<T> const&);
47 Image<T>& operator/= (Image<T> const&);
48
49 Image<T>& operator+= (double);
50 Image<T>& operator-= (double);
51 Image<T>& operator*= (double);
52 Image<T>& operator/= (double);
53
54 Image<T> WhereNonZero();
55
56
57// Impression de tout le contenu de l'image
58 virtual void PrintImage(ostream& os) const;
59 inline void PrintImage() const { PrintImage(cout); }
60
61 void Zero();
62 void Allocate(int sizx, int sizy, int zero=1, ImgVectP* pvpsh=NULL);
63
64 inline T& operator() (int x, int y);
65 inline T operator() (int x, int y) const;
66 inline T& operator[] (int i);
67 inline T operator[] (int i) const;
68 T* ImagePtr() {return imagePtr;}
69 const T* ImagePtr() const {return imagePtr;}
70
71 int CheckDyn(double min=-9.e19, double max=9.e19);
72
73 void SeuilBas(double seuil, double val);
74 void SeuilHaut(double seuil, double val);
75 void SeuilBas(double seuil);
76 void SeuilHaut(double seuil);
77 void SetPixels(int szx, int szy, T* pim);
78
79 int EstimeFdSg(float& xbmax,float& sgbmax,float nbsig=3.5,float frac=0.33
80 ,float lowbad=1.,float highbad=-1.,int deb=0);
81 float FondCiel(int nbin,float bin_low,float bin_high
82 ,int degre=2,float frac=0.5f,int modu=1,int deb=0);
83 float SigmaCiel(int nbin,float bin_low,float bin_high,float& means
84 ,float lowbad=1.,float highbad=-1.
85 ,float nsig=4.f,int modu=1,int deb=0);
86 int MoySigma(float& mean,float& sigma
87 ,float lowbad=1.,float highbad=-1.,int modu=1);
88 int MoySigmaIter(float& mean,float& sigma,float lowbad=1.,float highbad=-1.
89 ,int modu=1,int nitermx=10
90 ,float perdiff=0.1f,float scut=3.5f, int deb=0);
91 int FondSigmaCiel(float lowbad,float highbad,int pvsz=100
92 ,float nbsig1=3.5f,float nbsig2=7.f,float nbsig3=5.f
93 ,float binsg=0.5f,float frac=0.33f,int modu=1,int deb=0);
94
95
96protected:
97
98 void HBinInt(int& nbin,float& xmin,float& xmax);
99
100 T* imagePtr;
101};
102
103// Definition de l'operateur <<
104//template <class T>
105//ostream& operator << (ostream& s, Image<T> const& img)
106// { img.Print(s); return(s); }
107
108
109/* ....................................................... */
110/* Implementation inline des acces pixels */
111/* ....................................................... */
112
113// ----- Macro de verification des indices ------
114
115#ifdef IMGRGCHECK
116#define CHECKIMG(_x_,_y_) \
117 if ((_x_ >= siz_x) || (_y_ >= siz_y) || \
118 (_x_ < 0) || (_y_ < 0)) THROW(rangeCheckErr); \
119 if (!imagePtr) THROW(nullPtrErr)
120#else
121#if defined(IMGVOIDCHECK)
122#define CHECKIMG(_x_,_y_) \
123 if (!imagePtr) THROW(NullPtrErr)
124#else
125#define CHECKIMG(_x_,_y_)
126#endif
127#endif /* IMGRGCHECK */
128
129#define INRANGE(_x_,_y_) ((_x_ < siz_x) && (_y_ < siz_y) && \
130 (_x_ >= 0) && (_y_ >= 0))
131
132
133// Fin des macros ------
134
135
136template <class T>
137inline T & Image<T>::operator() (int x, int y)
138{
139 CHECKIMG(x,y);
140 return imagePtr[x+y*siz_x];
141}
142
143template <class T>
144inline T Image<T>::operator() (int x, int y) const
145{
146 CHECKIMG(x,y);
147 return imagePtr[x+y*siz_x];
148}
149
150template <class T>
151inline T & Image<T>::operator[] (int i)
152{
153 CHECKIMG(0,0);
154 return imagePtr[i];
155}
156
157template <class T>
158inline T Image<T>::operator[] (int i) const
159{
160 CHECKIMG(0,0);
161 return imagePtr[i];
162}
163
164// Operateurs addition, multiplication, ... (+ - * / ) avec des doubles
165
166template <class T>
167Image<T> operator+ (Image<T> const& a, double b)
168{
169 Image<T> c(a);
170 c += b;
171 return c;
172}
173
174template <class T>
175Image<T> operator- (Image<T> const& a, double b)
176{
177 Image<T> c(a);
178 c -= b;
179 return c;
180}
181
182template <class T>
183Image<T> operator* (Image<T> const& a, double b)
184{
185 Image<T> c(a);
186 c *= b;
187 return c;
188}
189
190template <class T>
191Image<T> operator/ (Image<T> const& a, double b)
192{
193 Image<T> c(a);
194 c /= b;
195 return c;
196}
197
198// Operateurs addition, multiplication, ... (+ - * / ) entre images
199template <class T>
200Image<T> operator+ (Image<T> const& a, Image<T> const& b)
201{
202 Image<T> c(a);
203 c += b;
204 return c;
205}
206
207template <class T>
208Image<T> operator- (Image<T> const& a, Image<T> const& b)
209{
210 Image<T> c(a);
211 c -= b;
212 return c;
213}
214
215template <class T>
216Image<T> operator* (Image<T> const& a, Image<T> const& b)
217{
218 Image<T> c(a);
219 c *= b;
220 return c;
221}
222
223template <class T>
224Image<T> operator/ (Image<T> const& a, Image<T> const& b)
225{
226 Image<T> c(a);
227 c /= b;
228 return c;
229}
230
231/* ....................................................... */
232/* Fonctions de copie d'images et de paves */
233/* ....................................................... */
234
235template <class T2, class T1>
236void CopieImageF(Image<T2>& copie, Image<T1> const& pim,
237 int org_pim_x=0, int org_pim_y=0,
238 int pim_lpav_x=0, int pim_lpav_y=0,
239 int org_copie_x=0, int org_copie_y=0,
240 double cutmin=0., double cutmax=0.);
241
242template <class T2, class T1>
243void CopieImage(Image<T2>& copie, Image<T1> const& pim);
244
245template <class T2, class T1>
246void CopieImage(Image<T2>& copie, Image<T1> const& pim,
247 int org_pim_x, int org_pim_y,
248 int pim_lpav_x=0, int pim_lpav_y=0,
249 int org_copie_x=0, int org_copie_y=0,
250 double cutmin=0, double cutmax=0);
251
252
253template <class T2, class T1>
254void
255CopiePave(Image<T2>& pave, Image<T1> const& pim,
256 float xc, float yc,
257 double cutmin=0, double cutmax=0);
258
259
260template <class T>
261void
262RzCopieImage(Image<T>& copie, RzImage const& pim,
263 int org_pim_x, int org_pim_y,
264 int pim_lpav_x=0, int pim_lpav_y=0,
265 int org_copie_x=0, int org_copie_y=0,
266 double cutmin=0, double cutmax=0);
267
268template <class T>
269void
270RzCopieImage(Image<T>& copie, RzImage const& pim);
271
272template <class T>
273void
274RzCopiePave(Image<T> & pave, RzImage const & pim,
275 float xc, float yc,
276 double cutmin=0, double cutmax=0);
277/* ....................................................... */
278/* Autres fonctions utilitaires pour RzImage */
279/* ....................................................... */
280
281void RzPrintImage(RzImage & img);
282
283/* Images de types usuels */
284
285typedef Image<uint_1> ImageU1;
286typedef Image<uint_2> ImageU2;
287typedef Image<int_2> ImageI2;
288typedef Image<int_4> ImageI4;
289typedef Image<r_4> ImageR4;
290
291
292#ifdef __MWERKS__
293template <class T>
294ostream& operator << (ostream& s, Image<T> const& pim);
295#endif
296
297#endif
298
299
Note: See TracBrowser for help on using the repository browser.