[220] | 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 |
|
---|
| 24 | template <class T>
|
---|
| 25 | class Image : public RzImage {
|
---|
| 26 |
|
---|
| 27 | public:
|
---|
| 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 |
|
---|
| 96 | protected:
|
---|
| 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 |
|
---|
| 136 | template <class T>
|
---|
| 137 | inline T & Image<T>::operator() (int x, int y)
|
---|
| 138 | {
|
---|
| 139 | CHECKIMG(x,y);
|
---|
| 140 | return imagePtr[x+y*siz_x];
|
---|
| 141 | }
|
---|
| 142 |
|
---|
| 143 | template <class T>
|
---|
| 144 | inline T Image<T>::operator() (int x, int y) const
|
---|
| 145 | {
|
---|
| 146 | CHECKIMG(x,y);
|
---|
| 147 | return imagePtr[x+y*siz_x];
|
---|
| 148 | }
|
---|
| 149 |
|
---|
| 150 | template <class T>
|
---|
| 151 | inline T & Image<T>::operator[] (int i)
|
---|
| 152 | {
|
---|
| 153 | CHECKIMG(0,0);
|
---|
| 154 | return imagePtr[i];
|
---|
| 155 | }
|
---|
| 156 |
|
---|
| 157 | template <class T>
|
---|
| 158 | inline 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 |
|
---|
| 166 | template <class T>
|
---|
| 167 | Image<T> operator+ (Image<T> const& a, double b)
|
---|
| 168 | {
|
---|
| 169 | Image<T> c(a);
|
---|
| 170 | c += b;
|
---|
| 171 | return c;
|
---|
| 172 | }
|
---|
| 173 |
|
---|
| 174 | template <class T>
|
---|
| 175 | Image<T> operator- (Image<T> const& a, double b)
|
---|
| 176 | {
|
---|
| 177 | Image<T> c(a);
|
---|
| 178 | c -= b;
|
---|
| 179 | return c;
|
---|
| 180 | }
|
---|
| 181 |
|
---|
| 182 | template <class T>
|
---|
| 183 | Image<T> operator* (Image<T> const& a, double b)
|
---|
| 184 | {
|
---|
| 185 | Image<T> c(a);
|
---|
| 186 | c *= b;
|
---|
| 187 | return c;
|
---|
| 188 | }
|
---|
| 189 |
|
---|
| 190 | template <class T>
|
---|
| 191 | Image<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
|
---|
| 199 | template <class T>
|
---|
| 200 | Image<T> operator+ (Image<T> const& a, Image<T> const& b)
|
---|
| 201 | {
|
---|
| 202 | Image<T> c(a);
|
---|
| 203 | c += b;
|
---|
| 204 | return c;
|
---|
| 205 | }
|
---|
| 206 |
|
---|
| 207 | template <class T>
|
---|
| 208 | Image<T> operator- (Image<T> const& a, Image<T> const& b)
|
---|
| 209 | {
|
---|
| 210 | Image<T> c(a);
|
---|
| 211 | c -= b;
|
---|
| 212 | return c;
|
---|
| 213 | }
|
---|
| 214 |
|
---|
| 215 | template <class T>
|
---|
| 216 | Image<T> operator* (Image<T> const& a, Image<T> const& b)
|
---|
| 217 | {
|
---|
| 218 | Image<T> c(a);
|
---|
| 219 | c *= b;
|
---|
| 220 | return c;
|
---|
| 221 | }
|
---|
| 222 |
|
---|
| 223 | template <class T>
|
---|
| 224 | Image<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 |
|
---|
| 235 | template <class T2, class T1>
|
---|
| 236 | void 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 |
|
---|
| 242 | template <class T2, class T1>
|
---|
| 243 | void CopieImage(Image<T2>& copie, Image<T1> const& pim);
|
---|
| 244 |
|
---|
| 245 | template <class T2, class T1>
|
---|
| 246 | void 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 |
|
---|
| 253 | template <class T2, class T1>
|
---|
| 254 | void
|
---|
| 255 | CopiePave(Image<T2>& pave, Image<T1> const& pim,
|
---|
| 256 | float xc, float yc,
|
---|
| 257 | double cutmin=0, double cutmax=0);
|
---|
| 258 |
|
---|
| 259 |
|
---|
| 260 | template <class T>
|
---|
| 261 | void
|
---|
| 262 | RzCopieImage(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 |
|
---|
| 268 | template <class T>
|
---|
| 269 | void
|
---|
| 270 | RzCopieImage(Image<T>& copie, RzImage const& pim);
|
---|
| 271 |
|
---|
| 272 | template <class T>
|
---|
| 273 | void
|
---|
| 274 | RzCopiePave(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 |
|
---|
| 281 | void RzPrintImage(RzImage & img);
|
---|
| 282 |
|
---|
| 283 | /* Images de types usuels */
|
---|
| 284 |
|
---|
| 285 | typedef Image<uint_1> ImageU1;
|
---|
| 286 | typedef Image<uint_2> ImageU2;
|
---|
| 287 | typedef Image<int_2> ImageI2;
|
---|
| 288 | typedef Image<int_4> ImageI4;
|
---|
| 289 | typedef Image<r_4> ImageR4;
|
---|
| 290 |
|
---|
| 291 |
|
---|
| 292 | #ifdef __MWERKS__
|
---|
| 293 | template <class T>
|
---|
| 294 | ostream& operator << (ostream& s, Image<T> const& pim);
|
---|
| 295 | #endif
|
---|
| 296 |
|
---|
| 297 | #endif
|
---|
| 298 |
|
---|
| 299 |
|
---|