| 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 | static PPersist* Create() { return new Image<T>;}
|
|---|
| 37 |
|
|---|
| 38 | virtual void ReadSelf(PInPersist&);
|
|---|
| 39 |
|
|---|
| 40 | Image<T>& operator= (const Image<T> &);
|
|---|
| 41 | Image<T>& operator= (T);
|
|---|
| 42 |
|
|---|
| 43 | Image<T>& operator+= (Image<T> const&);
|
|---|
| 44 | Image<T>& operator-= (Image<T> const&);
|
|---|
| 45 | Image<T>& operator*= (Image<T> const&);
|
|---|
| 46 | Image<T>& operator/= (Image<T> const&);
|
|---|
| 47 |
|
|---|
| 48 | Image<T>& operator+= (double);
|
|---|
| 49 | Image<T>& operator-= (double);
|
|---|
| 50 | Image<T>& operator*= (double);
|
|---|
| 51 | Image<T>& operator/= (double);
|
|---|
| 52 |
|
|---|
| 53 | Image<T> WhereNonZero();
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 | // Impression de tout le contenu de l'image
|
|---|
| 57 | virtual void PrintImage(ostream& os) const;
|
|---|
| 58 | inline void PrintImage() const { PrintImage(cout); }
|
|---|
| 59 |
|
|---|
| 60 | void Zero();
|
|---|
| 61 | void Allocate(int sizx, int sizy, int zero=1, ImgVectP* pvpsh=NULL);
|
|---|
| 62 |
|
|---|
| 63 | inline T& operator() (int x, int y);
|
|---|
| 64 | inline T operator() (int x, int y) const;
|
|---|
| 65 | inline T& operator[] (int i);
|
|---|
| 66 | inline T operator[] (int i) const;
|
|---|
| 67 | T* ImagePtr() {return imagePtr;}
|
|---|
| 68 | const T* ImagePtr() const {return imagePtr;}
|
|---|
| 69 |
|
|---|
| 70 | int CheckDyn(double min=-9.e19, double max=9.e19);
|
|---|
| 71 |
|
|---|
| 72 | void SeuilBas(double seuil, double val);
|
|---|
| 73 | void SeuilHaut(double seuil, double val);
|
|---|
| 74 | void SeuilBas(double seuil);
|
|---|
| 75 | void SeuilHaut(double seuil);
|
|---|
| 76 | void SetPixels(int szx, int szy, T* pim);
|
|---|
| 77 |
|
|---|
| 78 | int EstimeFdSg(float& xbmax,float& sgbmax,float nbsig=3.5,float frac=0.33
|
|---|
| 79 | ,float lowbad=1.,float highbad=-1.,int deb=0);
|
|---|
| 80 | float FondCiel(int nbin,float bin_low,float bin_high
|
|---|
| 81 | ,int degre=2,float frac=0.5f,int modu=1,int deb=0);
|
|---|
| 82 | float SigmaCiel(int nbin,float bin_low,float bin_high,float& means
|
|---|
| 83 | ,float lowbad=1.,float highbad=-1.
|
|---|
| 84 | ,float nsig=4.f,int modu=1,int deb=0);
|
|---|
| 85 | int MoySigma(float& mean,float& sigma
|
|---|
| 86 | ,float lowbad=1.,float highbad=-1.,int modu=1);
|
|---|
| 87 | int MoySigmaIter(float& mean,float& sigma,float lowbad=1.,float highbad=-1.
|
|---|
| 88 | ,int modu=1,int nitermx=10
|
|---|
| 89 | ,float perdiff=0.1f,float scut=3.5f, int deb=0);
|
|---|
| 90 | int FondSigmaCiel(float lowbad,float highbad,int pvsz=100
|
|---|
| 91 | ,float nbsig1=3.5f,float nbsig2=7.f,float nbsig3=5.f
|
|---|
| 92 | ,float binsg=0.5f,float frac=0.33f,int modu=1,int deb=0);
|
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 | protected:
|
|---|
| 96 |
|
|---|
| 97 | void HBinInt(int& nbin,float& xmin,float& xmax);
|
|---|
| 98 |
|
|---|
| 99 | T* imagePtr;
|
|---|
| 100 | };
|
|---|
| 101 |
|
|---|
| 102 | // Definition de l'operateur <<
|
|---|
| 103 | //template <class T>
|
|---|
| 104 | //ostream& operator << (ostream& s, Image<T> const& img)
|
|---|
| 105 | // { img.Print(s); return(s); }
|
|---|
| 106 |
|
|---|
| 107 |
|
|---|
| 108 | /* ....................................................... */
|
|---|
| 109 | /* Implementation inline des acces pixels */
|
|---|
| 110 | /* ....................................................... */
|
|---|
| 111 |
|
|---|
| 112 | // ----- Macro de verification des indices ------
|
|---|
| 113 |
|
|---|
| 114 | #ifdef IMGRGCHECK
|
|---|
| 115 | #define CHECKIMG(_x_,_y_) \
|
|---|
| 116 | if ((_x_ >= siz_x) || (_y_ >= siz_y) || \
|
|---|
| 117 | (_x_ < 0) || (_y_ < 0)) THROW(rangeCheckErr); \
|
|---|
| 118 | if (!imagePtr) THROW(nullPtrErr)
|
|---|
| 119 | #else
|
|---|
| 120 | #if defined(IMGVOIDCHECK)
|
|---|
| 121 | #define CHECKIMG(_x_,_y_) \
|
|---|
| 122 | if (!imagePtr) THROW(NullPtrErr)
|
|---|
| 123 | #else
|
|---|
| 124 | #define CHECKIMG(_x_,_y_)
|
|---|
| 125 | #endif
|
|---|
| 126 | #endif /* IMGRGCHECK */
|
|---|
| 127 |
|
|---|
| 128 | #define INRANGE(_x_,_y_) ((_x_ < siz_x) && (_y_ < siz_y) && \
|
|---|
| 129 | (_x_ >= 0) && (_y_ >= 0))
|
|---|
| 130 |
|
|---|
| 131 |
|
|---|
| 132 | // Fin des macros ------
|
|---|
| 133 |
|
|---|
| 134 |
|
|---|
| 135 | template <class T>
|
|---|
| 136 | inline T & Image<T>::operator() (int x, int y)
|
|---|
| 137 | {
|
|---|
| 138 | CHECKIMG(x,y);
|
|---|
| 139 | return imagePtr[x+y*siz_x];
|
|---|
| 140 | }
|
|---|
| 141 |
|
|---|
| 142 | template <class T>
|
|---|
| 143 | inline T Image<T>::operator() (int x, int y) const
|
|---|
| 144 | {
|
|---|
| 145 | CHECKIMG(x,y);
|
|---|
| 146 | return imagePtr[x+y*siz_x];
|
|---|
| 147 | }
|
|---|
| 148 |
|
|---|
| 149 | template <class T>
|
|---|
| 150 | inline T & Image<T>::operator[] (int i)
|
|---|
| 151 | {
|
|---|
| 152 | CHECKIMG(0,0);
|
|---|
| 153 | return imagePtr[i];
|
|---|
| 154 | }
|
|---|
| 155 |
|
|---|
| 156 | template <class T>
|
|---|
| 157 | inline T Image<T>::operator[] (int i) const
|
|---|
| 158 | {
|
|---|
| 159 | CHECKIMG(0,0);
|
|---|
| 160 | return imagePtr[i];
|
|---|
| 161 | }
|
|---|
| 162 |
|
|---|
| 163 | // Operateurs addition, multiplication, ... (+ - * / ) avec des doubles
|
|---|
| 164 |
|
|---|
| 165 | template <class T>
|
|---|
| 166 | Image<T> operator+ (Image<T> const& a, double b)
|
|---|
| 167 | {
|
|---|
| 168 | Image<T> c(a);
|
|---|
| 169 | c += b;
|
|---|
| 170 | return c;
|
|---|
| 171 | }
|
|---|
| 172 |
|
|---|
| 173 | template <class T>
|
|---|
| 174 | Image<T> operator- (Image<T> const& a, double b)
|
|---|
| 175 | {
|
|---|
| 176 | Image<T> c(a);
|
|---|
| 177 | c -= b;
|
|---|
| 178 | return c;
|
|---|
| 179 | }
|
|---|
| 180 |
|
|---|
| 181 | template <class T>
|
|---|
| 182 | Image<T> operator* (Image<T> const& a, double b)
|
|---|
| 183 | {
|
|---|
| 184 | Image<T> c(a);
|
|---|
| 185 | c *= b;
|
|---|
| 186 | return c;
|
|---|
| 187 | }
|
|---|
| 188 |
|
|---|
| 189 | template <class T>
|
|---|
| 190 | Image<T> operator/ (Image<T> const& a, double b)
|
|---|
| 191 | {
|
|---|
| 192 | Image<T> c(a);
|
|---|
| 193 | c /= b;
|
|---|
| 194 | return c;
|
|---|
| 195 | }
|
|---|
| 196 |
|
|---|
| 197 | // Operateurs addition, multiplication, ... (+ - * / ) entre images
|
|---|
| 198 | template <class T>
|
|---|
| 199 | Image<T> operator+ (Image<T> const& a, Image<T> const& b)
|
|---|
| 200 | {
|
|---|
| 201 | Image<T> c(a);
|
|---|
| 202 | c += b;
|
|---|
| 203 | return c;
|
|---|
| 204 | }
|
|---|
| 205 |
|
|---|
| 206 | template <class T>
|
|---|
| 207 | Image<T> operator- (Image<T> const& a, Image<T> const& b)
|
|---|
| 208 | {
|
|---|
| 209 | Image<T> c(a);
|
|---|
| 210 | c -= b;
|
|---|
| 211 | return c;
|
|---|
| 212 | }
|
|---|
| 213 |
|
|---|
| 214 | template <class T>
|
|---|
| 215 | Image<T> operator* (Image<T> const& a, Image<T> const& b)
|
|---|
| 216 | {
|
|---|
| 217 | Image<T> c(a);
|
|---|
| 218 | c *= b;
|
|---|
| 219 | return c;
|
|---|
| 220 | }
|
|---|
| 221 |
|
|---|
| 222 | template <class T>
|
|---|
| 223 | Image<T> operator/ (Image<T> const& a, Image<T> const& b)
|
|---|
| 224 | {
|
|---|
| 225 | Image<T> c(a);
|
|---|
| 226 | c /= b;
|
|---|
| 227 | return c;
|
|---|
| 228 | }
|
|---|
| 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 |
|
|---|
| 298 | #endif
|
|---|
| 299 |
|
|---|
| 300 |
|
|---|