Structural deformable models
Public Types | Public Member Functions | Protected Attributes | Friends | List of all members
Image< T > Class Template Reference

#include <Image.h>

Inheritance diagram for Image< T >:
Inheritance graph
[legend]
Collaboration diagram for Image< T >:
Collaboration graph
[legend]

Public Types

typedef std::vector< T >::iterator iterator
 
typedef std::vector< T >::const_iterator const_iterator
 

Public Member Functions

 Image ()
 
 Image (int sx, int sy)
 
 Image (int sx, int sy, const T &value)
 
 Image (const Image< T > &rhs)
 
virtual ~Image ()
 
void freeImage ()
 
void setSize (int nx, int ny)
 
void setSize (int nx, int ny, const T &value)
 
template<class S >
bool sameSize (const Image< S > &rhs)
 
const T * getData () const
 
T * getData ()
 
int getSizeX () const
 
int getSizeY () const
 
int getSize () const
 
Image< T > & operator= (const Image< T > &rhs)
 
Image< T > & operator= (const T &rhs)
 
Image< T > & copy (const Image< T > &rhs)
 
Image< T > & copy (const T *rhs)
 
int getIndex (int x, int y) const
 
int getBoundedIndex (int x, int y) const
 
const T getPixel (int x, int y) const
 
void setPixel (int x, int y, const T &value)
 
const T findMax () const
 calculate maximum More...
 
const T findMin () const
 calculate minimum More...
 
const T norm () const
 
double sum () const
 
Image< T > & operator*= (const T &v)
 
Image< T > & operator/= (const T &v)
 
Image< T > & operator+= (const T &v)
 
Image< T > & operator-= (const T &v)
 
Image< T > & operator*= (const Image< T > &rhs)
 
Image< T > & operator/= (const Image< T > &rhs)
 
Image< T > & operator+= (const Image< T > &rhs)
 
Image< T > & operator-= (const Image< T > &rhs)
 
void addLine (int x0, int y0, int x1, int y1, const T &value)
 
Image< T > & unsetNAN (double val=0)
 
Image< T > & threshold (const T &th, double binarize=0)
 
Image< T > & findMaxima (int env=3)
 
template<class S >
Image< T > & convertFrom (const Image< S > &rhs)
 
const Image< T > mirror (bool horiz=true, bool vert=true) const
 
template<class S >
const Image< T > convolve (const Image< S > &kernel) const
 
Image< T > & interleave (const std::vector< Image< T > > &img, dword ncomp=0)
 
Image< T > scaleBy (float s)
 
Image< T > scaleBy (float sx, float sy)
 
bool initialized () const
 
bool writePPM (const std::string &fname) const
 
bool writePPMstream (std::ostream &os) const
 
bool readPPM (const std::string &fname)
 
bool readPPMstream (std::istream &is)
 
void insert (const Image< T > &ii, const int x=0, const int y=0)
 
Image< T > & zeroPad (int brd, const T &col=0, bool smoothbrd=false)
 

Protected Attributes

int sizeX
 
int sizeY
 

Friends

std::ostream & operator<< (std::ostream &os, const Image< T > &rhs)
 
std::istream & operator>> (std::istream &is, Image< T > &rhs)
 

Detailed Description

template<class T>
class Image< T >

Definition at line 16 of file Image.h.

Member Typedef Documentation

template<class T>
typedef std::vector<T>::const_iterator Image< T >::const_iterator

Definition at line 20 of file Image.h.

template<class T>
typedef std::vector<T>::iterator Image< T >::iterator

Definition at line 19 of file Image.h.

Constructor & Destructor Documentation

template<class T >
Image< T >::Image ( )

Definition at line 249 of file Image.h.

References Image< T >::sizeX, and Image< T >::sizeY.

Referenced by Image< Point2D >::Image().

250 {
251  sizeX = sizeY = 0;
252 }
int sizeX
Definition: Image.h:245
int sizeY
Definition: Image.h:245
template<class T>
Image< T >::Image ( int  sx,
int  sy 
)
inline

Definition at line 23 of file Image.h.

24  : std::vector<T>(sx*sy), sizeX(sx), sizeY(sy) {};
int sizeX
Definition: Image.h:245
int sizeY
Definition: Image.h:245
template<class T>
Image< T >::Image ( int  sx,
int  sy,
const T &  value 
)
inline

Definition at line 25 of file Image.h.

26  : std::vector<T>(sx*sy, value), sizeX(sx), sizeY(sy) {};
int sizeX
Definition: Image.h:245
int sizeY
Definition: Image.h:245
template<class T>
Image< T >::Image ( const Image< T > &  rhs)

Definition at line 255 of file Image.h.

References Image< T >::operator=().

256 {
257  operator=(rhs);
258 }
Image< T > & operator=(const Image< T > &rhs)
Definition: Image.h:305
template<class T>
virtual Image< T >::~Image ( )
inlinevirtual

Definition at line 28 of file Image.h.

28 {};

Member Function Documentation

template<class T>
void Image< T >::addLine ( int  x0,
int  y0,
int  x1,
int  y1,
const T &  value 
)

Definition at line 441 of file Image.h.

References absint(), Image< T >::getData(), and Image< T >::sizeX.

Referenced by Image< Point2D >::setPixel().

442 {
443  if(std::vector<T>::empty()) return;
444  //left point first?
445  if(x0>x1) {
446  x0 += x1; x1 = x0-x1; x0 -= x1; //who needs a dummy?
447  y0 += y1; y1 = y0-y1; y0 -= y1;
448  }
449  T* dpos = getData() + x0 + y0*sizeX;
450  int pincY = sizeX;
451  int xinc = 1;
452  int yinc = 1;
453  int dy = y1 - y0;
454  int dx = x1 - x0;
455 
456  int nx = dy; //normal (negative reciprocal direction)
457  int ny = -dx;
458 
459  int dir = dx>absint(dy) ? 1 : -1;
460  if(dy<0)
461  {
462  yinc=-1;
463  pincY = -pincY;
464  }
465 
466  if(dir==1)
467  {
468  int diagInc = 2*(nx+ny*yinc);
469  int axisInc = 2*nx;
470 
471  int x = x0;
472  int y = y0;
473 
474  int d = 2*nx + ny*yinc;
475  while (x <= x1)
476  {
477  *dpos += value;
478  if (d*yinc >= 0) { // move diagonally
479  y += yinc;
480  dpos += pincY;
481  d += diagInc;
482  }
483  else d += axisInc;
484  x += xinc;
485  dpos += xinc;
486  }
487  } else {
488  int diagInc = 2*(nx+ny*yinc);
489  int axisInc = 2*ny*yinc;
490 
491  int x = x0;
492  int y = y0;
493  int d = 2*ny*yinc + nx;
494  int cnt = absint(dy);
495  while (cnt--)
496  {
497  *dpos += value;
498  if (d*yinc <= 0) { // move diagonally
499  x += xinc;
500  dpos += xinc;
501  d += diagInc;
502  }
503  else d += axisInc;
504  y += yinc;
505  dpos += pincY;
506  }
507  *dpos += value;
508  }
509 }
int sizeX
Definition: Image.h:245
int absint(int v)
Definition: mathutil.h:21
const T * getData() const
Definition: Image.h:39
template<class T>
template<class S >
Image<T>& Image< T >::convertFrom ( const Image< S > &  rhs)
inline

Definition at line 91 of file Image.h.

Referenced by ImageWindow::selectSensor().

92  {
93  setSize(rhs.getSizeX(),rhs.getSizeY());
94  const S* sd = rhs.getData();
95  T* dd = getData();
96  for(int i=getSize();i>0;i--,dd++,sd++)
97  *dd = T(*sd);
98  return *this;
99  }
int getSize() const
Definition: Image.h:44
int getSizeX() const
Definition: Image.h:42
void setSize(int nx, int ny)
Definition: Image.h:268
const T * getData() const
Definition: Image.h:39
int getSizeY() const
Definition: Image.h:43
template<class T>
template<class S >
const Image<T> Image< T >::convolve ( const Image< S > &  kernel) const
inline

Definition at line 116 of file Image.h.

Referenced by Image< T >::zeroPad().

117  {
118  Image<T> dst(sizeX,sizeY);
119  int ksx = kernel.getSizeX()/2;
120  int ksy = kernel.getSizeY()/2;
121  int endX = sizeX-ksx;
122  int endY = sizeY-ksy;
123  //int offset = ksy*sizeX+ksx;
124  int winskip = sizeX-kernel.getSizeX();
125  T* dstdat = dst.getData() + ksx + (ksy*sizeX);
126  const T* srcdat = getData();
127  for(int i=ksy;i<endY;i++)
128  {
129  for(int j=ksx;j<endX;j++,dstdat++,srcdat++)
130  {
131  S sum = 0;
132  const S *kdat = kernel.getData();
133  const T *sdat = srcdat;
134  for(int l=0;l<kernel.getSizeY();l++)
135  {
136  for(int k=0;k<kernel.getSizeX();k++, kdat++, sdat++)
137  {
138  sum += *kdat**sdat;
139  }
140  sdat += winskip;
141  }
142  *dstdat = T(sum);
143  }
144  dstdat+=ksx*2;
145  srcdat+=ksx*2;
146  }
147  return dst;
148  }
int getSizeX() const
Definition: Image.h:42
int sizeX
Definition: Image.h:245
double sum() const
Definition: Image.h:355
Definition: Image.h:16
int sizeY
Definition: Image.h:245
const T * getData() const
Definition: Image.h:39
int getSizeY() const
Definition: Image.h:43
template<class T>
Image< T > & Image< T >::copy ( const Image< T > &  rhs)

Definition at line 287 of file Image.h.

References Image< T >::getSizeX(), Image< T >::getSizeY(), Image< T >::sizeX, and Image< T >::sizeY.

Referenced by Image< Point2D >::getSize(), and Image< T >::operator=().

288 {
289  if(&rhs == this) return *this;
290  std::vector<T>::operator=(rhs);
291  sizeX = rhs.getSizeX();
292  sizeY = rhs.getSizeY();
293  return *this;
294 }
int getSizeX() const
Definition: Image.h:42
int sizeX
Definition: Image.h:245
int sizeY
Definition: Image.h:245
int getSizeY() const
Definition: Image.h:43
template<class T>
Image< T > & Image< T >::copy ( const T *  rhs)

Definition at line 297 of file Image.h.

298 {
299  for(iterator pnt = std::vector<T>::begin(); pnt != std::vector<T>::end(); pnt++, rhs++)
300  *pnt = *rhs;
301  return *this;
302 }
std::vector< T >::iterator iterator
Definition: Image.h:19
template<class T >
const T Image< T >::findMax ( ) const

calculate maximum

Definition at line 322 of file Image.h.

References Image< T >::getData(), and Image< T >::getSize().

Referenced by Image< Point2D >::setPixel().

323 {
324  if(std::vector<T>::empty()) return 0;
325  const T* pnt = getData();
326  T max = *pnt;
327  for(int i=getSize(); i>0; i--, pnt++)
328  if(*pnt>max) max = *pnt;
329  return max;
330 }
int getSize() const
Definition: Image.h:44
const T * getData() const
Definition: Image.h:39
template<class T >
Image< T > & Image< T >::findMaxima ( int  env = 3)

Definition at line 532 of file Image.h.

References Image< T >::getData(), Image< T >::sizeX, and Image< T >::sizeY.

Referenced by Image< Point2D >::setPixel().

533 {
534  env = (env/2)*2 + 1;
535  int ksx = env/2;
536  int ksy = env/2;
537  int endX = sizeX-ksx;
538  int endY = sizeY-ksy;
539  int offset = ksy*sizeX+ksx;
540  int winskip = sizeX-env;
541  T* srcdat = getData();
542  T* maxpnt = getData()+offset;
543  for(int i=ksy;i<endY;i++)
544  {
545  for(int j=ksx;j<endX;j++,srcdat++, maxpnt++)
546  {
547  bool ismax = true;
548  const T *sdat = srcdat;
549  maxpnt = srcdat+offset;
550  for(int l=0;l<env && ismax; l++)
551  {
552  for(int k=0;k<env && ismax; k++, sdat++)
553  {
554  if(*maxpnt<=*sdat &&
555  maxpnt != sdat) ismax=false;
556  }
557  sdat += winskip; //jump to next line
558  }
559  if(!ismax) *maxpnt = 0;
560  }
561  maxpnt+=ksx*2;
562  srcdat+=ksx*2;
563  }
564  return *this;
565 }
int sizeX
Definition: Image.h:245
int sizeY
Definition: Image.h:245
const T * getData() const
Definition: Image.h:39
template<class T >
const T Image< T >::findMin ( ) const

calculate minimum

Definition at line 333 of file Image.h.

References Image< T >::getData(), and Image< T >::getSize().

Referenced by Image< Point2D >::setPixel().

334 {
335  if(std::vector<T>::empty()) return 0;
336  const T* pnt = getData();
337  T min = *pnt;
338  for(int i=getSize(); i>0; i--, pnt++)
339  if(*pnt<min) min = *pnt;
340  return min;
341 }
int getSize() const
Definition: Image.h:44
const T * getData() const
Definition: Image.h:39
template<class T >
void Image< T >::freeImage ( )

Definition at line 261 of file Image.h.

References Image< T >::setSize(), Image< T >::sizeX, and Image< T >::sizeY.

Referenced by Image< Point2D >::~Image().

262 {
263  setSize(0);
264  sizeX = sizeY = 0;
265 }
int sizeX
Definition: Image.h:245
void setSize(int nx, int ny)
Definition: Image.h:268
int sizeY
Definition: Image.h:245
template<class T>
int Image< T >::getBoundedIndex ( int  x,
int  y 
) const
inline

Definition at line 52 of file Image.h.

52  {
53  if((dword)x < (dword)sizeX && (dword)y < (dword)sizeY)
54  return sizeX*y+x;
55  else
56  return -1;
57  }
int sizeX
Definition: Image.h:245
unsigned long dword
Definition: simpletypes.h:6
int sizeY
Definition: Image.h:245
template<class T>
const T* Image< T >::getData ( ) const
inline
template<class T>
T* Image< T >::getData ( )
inline

Definition at line 40 of file Image.h.

40 {return &(*std::vector<T>::begin());}
template<class T>
int Image< T >::getIndex ( int  x,
int  y 
) const
inline

Definition at line 51 of file Image.h.

Referenced by Image< Point2D >::getPixel(), Image< T >::insert(), and Image< Point2D >::setPixel().

51 { return sizeX*y+x; }
int sizeX
Definition: Image.h:245
template<class T>
const T Image< T >::getPixel ( int  x,
int  y 
) const
inline

Definition at line 59 of file Image.h.

Referenced by Image< Point2D >::mirror().

59  {
60  return std::vector<T>::at(getIndex(x,y));
61  }
int getIndex(int x, int y) const
Definition: Image.h:51
template<class T>
int Image< T >::getSize ( ) const
inline
template<class T>
int Image< T >::getSizeX ( ) const
inline
template<class T>
int Image< T >::getSizeY ( ) const
inline
template<class T>
bool Image< T >::initialized ( ) const
inline
Returns
true if image has been initialized (data is not NULL)

Definition at line 191 of file Image.h.

191 { return !std::vector<T>::empty(); }
template<class T>
void Image< T >::insert ( const Image< T > &  ii,
const int  x = 0,
const int  y = 0 
)

Definition at line 568 of file Image.h.

References Image< T >::getIndex(), Image< T >::getSizeX(), and Image< T >::getSizeY().

Referenced by Dataset::load(), GLImage::setImage(), and Image< T >::zeroPad().

569 {
570  const int iwidth = std::min(getSizeX() - x, ii.getSizeX());
571  const int iheight = std::min(getSizeY() - y, ii.getSizeY());
572  if(iwidth>0 && iheight>0)
573  {
574  for(int j=0; j<iheight; j++) {
575  const_iterator src = ii.begin()+ii.getIndex(0,j);
576  iterator dst = std::vector<T>::begin()+getIndex(x,j+y);
577  for(int i=0; i<iwidth; i++, src++, dst++)
578  {
579  *dst = *src;
580  }
581  }
582  }
583 }
std::vector< T >::iterator iterator
Definition: Image.h:19
std::vector< T >::const_iterator const_iterator
Definition: Image.h:20
int getSizeX() const
Definition: Image.h:42
int getIndex(int x, int y) const
Definition: Image.h:51
int getSizeY() const
Definition: Image.h:43
template<class T>
Image<T>& Image< T >::interleave ( const std::vector< Image< T > > &  img,
dword  ncomp = 0 
)
inline

Definition at line 150 of file Image.h.

Referenced by GLImage::setImage().

152  {
153  if(!ncomp) ncomp = img.size();
154  const int comp = img.size()>ncomp ? ncomp : img.size();
155  const int size = img[0].size();
156  setSize(img[0].getSizeX()*ncomp, img[0].getSizeY());
158  for(int a=0; a<comp; a++) bi[a] = img[a].begin();
159  T *cv = getData();
160  const int cvinc = ncomp-comp;
161  for(int i=0; i<size; i++) {
162  for(int a=0; a<comp; a++) {
163  *(cv++) = *bi[a];
164  bi[a]++;
165  }
166  cv += cvinc;
167  }
168  return *this;
169  }
int getSizeX() const
Definition: Image.h:42
Definition: Image.h:16
void setSize(int nx, int ny)
Definition: Image.h:268
const T * getData() const
Definition: Image.h:39
int getSizeY() const
Definition: Image.h:43
template<class T>
const Image<T> Image< T >::mirror ( bool  horiz = true,
bool  vert = true 
) const
inline

Definition at line 101 of file Image.h.

102  {
103  Image<T> dimg(getSizeX(),getSizeY());
104  int i,j;
105  for(j=0;j<getSizeY();j++)
106  for(i=0;i<getSizeX();i++)
107  {
108  int si = horiz ? getSizeX()-i-1 : i;
109  int sj = vert ? getSizeY()-j-1 : j;
110  dimg.setPixel(i,j,getPixel(si,sj));
111  }
112  return dimg;
113  }
int getSizeX() const
Definition: Image.h:42
const T getPixel(int x, int y) const
Definition: Image.h:59
Definition: Image.h:16
int getSizeY() const
Definition: Image.h:43
template<class T >
const T Image< T >::norm ( ) const

calculate 2-norm of 2D array internally using double, so only works on scalar data types

Definition at line 344 of file Image.h.

References Image< T >::getData(), Image< T >::getSize(), dmutil::sqrt(), and Image< T >::sum().

Referenced by Image< Point2D >::setPixel().

345 {
346  double sum=0;
347  const T* pnt = getData();
348  for(int i=getSize(); i>0; i--, pnt++)
349  sum += *pnt**pnt;
350  sum = T(sqrt(sum));
351  return T(sum);
352 }
int getSize() const
Definition: Image.h:44
double sum() const
Definition: Image.h:355
const T * getData() const
Definition: Image.h:39
DMatrix< T > & sqrt(DMatrix< T > &mat)
Definition: DMatrixUtil.h:81
template<class T>
Image< T > & Image< T >::operator*= ( const T &  v)

Definition at line 365 of file Image.h.

References Image< T >::getData(), and Image< T >::getSize().

Referenced by Image< Point2D >::setPixel().

366 {
367  T* pnt = getData();
368  for(int i=getSize(); i>0; i--, pnt++)
369  *pnt *= v;
370  return *this;
371 }
int getSize() const
Definition: Image.h:44
const T * getData() const
Definition: Image.h:39
template<class T>
Image< T > & Image< T >::operator*= ( const Image< T > &  rhs)

Definition at line 401 of file Image.h.

References Image< T >::getData(), and Image< T >::getSize().

402 {
403  T* pnt = getData();
404  const T* rval = rhs.getData();
405  for(int i=getSize(); i>0; i--, pnt++, rval++)
406  *pnt *= *rval;
407  return *this;
408 }
int getSize() const
Definition: Image.h:44
const T * getData() const
Definition: Image.h:39
template<class T>
Image< T > & Image< T >::operator+= ( const T &  v)

Definition at line 383 of file Image.h.

References Image< T >::getData(), and Image< T >::getSize().

Referenced by Image< Point2D >::setPixel().

384 {
385  T* pnt = getData();
386  for(int i=getSize(); i>0; i--, pnt++)
387  *pnt += v;
388  return *this;
389 }
int getSize() const
Definition: Image.h:44
const T * getData() const
Definition: Image.h:39
template<class T>
Image< T > & Image< T >::operator+= ( const Image< T > &  rhs)

Definition at line 421 of file Image.h.

References Image< T >::getData(), and Image< T >::getSize().

422 {
423  T* pnt = getData();
424  const T* rval = rhs.getData();
425  for(int i=getSize(); i>0; i--, pnt++)
426  *pnt += *rval;
427  return *this;
428 }
int getSize() const
Definition: Image.h:44
const T * getData() const
Definition: Image.h:39
template<class T>
Image< T > & Image< T >::operator-= ( const T &  v)

Definition at line 392 of file Image.h.

References Image< T >::getData(), and Image< T >::getSize().

Referenced by Image< Point2D >::setPixel().

393 {
394  T* pnt = getData();
395  for(int i=getSize(); i>0; i--, pnt++)
396  *pnt -= v;
397  return *this;
398 }
int getSize() const
Definition: Image.h:44
const T * getData() const
Definition: Image.h:39
template<class T>
Image< T > & Image< T >::operator-= ( const Image< T > &  rhs)

Definition at line 431 of file Image.h.

References Image< T >::getData(), and Image< T >::getSize().

432 {
433  T* pnt = getData();
434  const T* rval = rhs.getData();
435  for(int i=getSize(); i>0; i--, pnt++)
436  *pnt -= *rval;
437  return *this;
438 }
int getSize() const
Definition: Image.h:44
const T * getData() const
Definition: Image.h:39
template<class T>
Image< T > & Image< T >::operator/= ( const T &  v)

Definition at line 374 of file Image.h.

References Image< T >::getData(), and Image< T >::getSize().

Referenced by Image< Point2D >::setPixel().

375 {
376  T* pnt = getData();
377  for(int i=getSize(); i>0; i--, pnt++)
378  *pnt /= v;
379  return *this;
380 }
int getSize() const
Definition: Image.h:44
const T * getData() const
Definition: Image.h:39
template<class T>
Image< T > & Image< T >::operator/= ( const Image< T > &  rhs)

Definition at line 411 of file Image.h.

References Image< T >::getData(), and Image< T >::getSize().

412 {
413  T* pnt = getData();
414  const T* rval = rhs.getData();
415  for(int i=getSize(); i>0; i--, pnt++)
416  *pnt /= *rval;
417  return *this;
418 }
int getSize() const
Definition: Image.h:44
const T * getData() const
Definition: Image.h:39
template<class T>
Image< T > & Image< T >::operator= ( const Image< T > &  rhs)

Definition at line 305 of file Image.h.

References Image< T >::copy().

Referenced by Image< Point2D >::getSize(), and Image< T >::Image().

306 {
307  return copy(rhs);
308 }
Image< T > & copy(const Image< T > &rhs)
Definition: Image.h:287
template<class T>
Image< T > & Image< T >::operator= ( const T &  rhs)

Definition at line 311 of file Image.h.

References Image< T >::sizeX, and Image< T >::sizeY.

312 {
313  if(!std::vector<T>::empty() && sizeX>0 && sizeY>0)
314  {
315  for(iterator pnt = std::vector<T>::begin(); pnt != std::vector<T>::end(); pnt++)
316  *pnt = rhs;
317  }
318  return *this;
319 }
std::vector< T >::iterator iterator
Definition: Image.h:19
int sizeX
Definition: Image.h:245
int sizeY
Definition: Image.h:245
template<class T>
bool Image< T >::readPPM ( const std::string &  fname)
inline

Definition at line 218 of file Image.h.

218  {
219  std::fstream ifile(fname.c_str(), std::ios::binary|std::ios::in);
220  return readPPMstream(ifile);
221  }
bool readPPMstream(std::istream &is)
Definition: Image.h:223
template<class T>
bool Image< T >::readPPMstream ( std::istream &  is)
inline

Definition at line 223 of file Image.h.

Referenced by Image< Point2D >::readPPM().

223  {
224  if(!is) return false;
225  is >> sizeX;
226  is >> sizeY;
227  std::vector<T>::resize(sizeX*sizeY);
228  is.read((char*)&std::vector<T>::front(), sizeX*sizeY);
229  return true;
230  }
int sizeX
Definition: Image.h:245
int sizeY
Definition: Image.h:245
template<class T>
template<class S >
bool Image< T >::sameSize ( const Image< S > &  rhs)
inline

Definition at line 35 of file Image.h.

36  { return rhs.getSizeX()==sizeX && rhs.getSizeY()==sizeY; }
int getSizeX() const
Definition: Image.h:42
int sizeX
Definition: Image.h:245
int sizeY
Definition: Image.h:245
int getSizeY() const
Definition: Image.h:43
template<class T>
Image<T> Image< T >::scaleBy ( float  s)
inline

Definition at line 171 of file Image.h.

Referenced by Image< Point2D >::scaleBy().

171 { return scaleBy(s,s); }
Image< T > scaleBy(float s)
Definition: Image.h:171
template<class T>
Image<T> Image< T >::scaleBy ( float  sx,
float  sy 
)
inline

Definition at line 172 of file Image.h.

173  {
174  //can only scale down by integral numbers
175  int stepx = (int)round(1/sx); if(stepx<=0) stepx=1;
176  int stepy = (int)round(1/sy); if(stepy<=0) stepy=1;
177  Image<T> nimg(getSizeX()/stepx, getSizeY()/stepy);
178  Image<T>::const_iterator src = std::vector<T>::begin();
179  Image<T>::iterator dst = nimg.begin();
180  for(int j=0; j<nimg.sizeY; j++) {
181  Image<T>::const_iterator linebegin = src;
182  for(int i=0; i<nimg.sizeX; i++, dst++, src+=stepx) {
183  *dst = *src;
184  }
185  src = linebegin+(stepy*sizeX);
186  }
187  return nimg;
188  }
std::vector< T >::iterator iterator
Definition: Image.h:19
std::vector< T >::const_iterator const_iterator
Definition: Image.h:20
int getSizeX() const
Definition: Image.h:42
int sizeX
Definition: Image.h:245
Definition: Image.h:16
int getSizeY() const
Definition: Image.h:43
template<class T>
void Image< T >::setPixel ( int  x,
int  y,
const T &  value 
)
inline

Definition at line 62 of file Image.h.

Referenced by Sensor::createSensorImage(), and Image< Point2D >::mirror().

62  {
63  std::vector<T>::at(getIndex(x,y)) = value;
64  }
int getIndex(int x, int y) const
Definition: Image.h:51
template<class T >
void Image< T >::setSize ( int  nx,
int  ny 
)

Definition at line 268 of file Image.h.

References Image< T >::sizeX, and Image< T >::sizeY.

Referenced by Image< Point2D >::convertFrom(), copyFXImage2Image(), PPSensor::fitSheets(), Image< T >::freeImage(), Image< Point2D >::interleave(), ImageWindow::onLoadImage(), and Image< Point2D >::~Image().

269 {
270  if(!std::vector<T>::empty() && nx==sizeX && ny==sizeY) return;
271  sizeX = nx;
272  sizeY = ny;
273  std::vector<T>::clear();
274  if(nx*ny) std::vector<T>::resize(nx*ny);
275 }
int sizeX
Definition: Image.h:245
int sizeY
Definition: Image.h:245
template<class T>
void Image< T >::setSize ( int  nx,
int  ny,
const T &  value 
)

Definition at line 278 of file Image.h.

References Image< T >::sizeX, and Image< T >::sizeY.

279 {
280  sizeX = nx;
281  sizeY = ny;
282  std::vector<T>::clear();
283  if(nx*ny) resize(nx*ny, value);
284 }
int sizeX
Definition: Image.h:245
int sizeY
Definition: Image.h:245
template<class T >
double Image< T >::sum ( ) const

Definition at line 355 of file Image.h.

References Image< T >::getData(), and Image< T >::getSize().

Referenced by Dataset::load(), Image< T >::norm(), and Image< Point2D >::setPixel().

356 {
357  double sum=0;
358  const T* pnt = getData();
359  for(int i=getSize(); i>0; i--, pnt++)
360  sum += (double)*pnt;
361  return sum;
362 }
int getSize() const
Definition: Image.h:44
double sum() const
Definition: Image.h:355
const T * getData() const
Definition: Image.h:39
template<class T>
Image< T > & Image< T >::threshold ( const T &  th,
double  binarize = 0 
)

Definition at line 512 of file Image.h.

References Image< T >::getData(), and Image< T >::getSize().

Referenced by Image< Point2D >::setPixel().

513 {
514  bool bin = (binarize>0);
515  T* pnt = getData();
516  for(int i=getSize(); i>0; i--, pnt++)
517  if(*pnt<th) *pnt = 0;
518  else if (bin) *pnt = T(binarize);
519  return *this;
520 }
int getSize() const
Definition: Image.h:44
const T * getData() const
Definition: Image.h:39
template<class T >
Image< T > & Image< T >::unsetNAN ( double  val = 0)

Definition at line 523 of file Image.h.

References Image< T >::getData(), and Image< T >::getSize().

Referenced by ImageWindow::selectSensor(), and Image< Point2D >::setPixel().

524 {
525  T* pnt = getData();
526  for(int i=getSize(); i>0; i--, pnt++)
527  if(isnan(*pnt)) *pnt = val;
528  return *this;
529 }
int getSize() const
Definition: Image.h:44
const T * getData() const
Definition: Image.h:39
template<class T>
bool Image< T >::writePPM ( const std::string &  fname) const
inline

Definition at line 206 of file Image.h.

206  {
207  std::fstream ofile(fname.c_str(), std::ios::binary|std::ios::out);
208  return writePPMstream(ofile);
209  }
bool writePPMstream(std::ostream &os) const
Definition: Image.h:211
template<class T>
bool Image< T >::writePPMstream ( std::ostream &  os) const
inline

Definition at line 211 of file Image.h.

Referenced by Image< Point2D >::writePPM().

211  {
212  if(!os) return false;
213  os << sizeX << " " << sizeY << std::endl;
214  os.write((const char*)&std::vector<T>::front(), sizeX*sizeY);
215  return true;
216  }
int sizeX
Definition: Image.h:245
int sizeY
Definition: Image.h:245
template<class T>
Image< T > & Image< T >::zeroPad ( int  brd,
const T &  col = 0,
bool  smoothbrd = false 
)

Definition at line 586 of file Image.h.

References Image< T >::convolve(), Image< T >::getSizeX(), Image< T >::getSizeY(), and Image< T >::insert().

587 {
588  if(brd>0)
589  {
590  Image<T> ni(getSizeX()+2*brd, getSizeY()+2*brd, col);
591  ni.insert(*this, brd, brd);
592  if(smoothbrd) {
593  //smooth the inner image and blit again
594  Image<float> flt(2*brd,2*brd, 1.0f/(4*brd*brd));
595  ni.convolve(flt);
596  ni.insert(*this, brd, brd);
597  }
598  *this = ni;
599  }
600  return *this;
601 }
int getSizeX() const
Definition: Image.h:42
Definition: Image.h:16
int getSizeY() const
Definition: Image.h:43

Friends And Related Function Documentation

template<class T>
std::ostream& operator<< ( std::ostream &  os,
const Image< T > &  rhs 
)
friend

Definition at line 193 of file Image.h.

193  {
194  os << rhs.sizeX << " " << rhs.sizeY << std::endl;
195  int xc = rhs.sizeX;
196  for(const_iterator pnt = rhs.begin(); pnt != rhs.end(); pnt++) {
197  os<<*pnt;
198  if(--xc == 0) {
199  std::cout << std::endl;
200  xc = rhs.sizeX;
201  } else std::cout << " ";
202  }
203  return os;
204  }
std::vector< T >::const_iterator const_iterator
Definition: Image.h:20
int sizeX
Definition: Image.h:245
int sizeY
Definition: Image.h:245
template<class T>
std::istream& operator>> ( std::istream &  is,
Image< T > &  rhs 
)
friend

Definition at line 232 of file Image.h.

232  {
233  is >> rhs.sizeX;
234  is >> rhs.sizeY;
235  rhs.resize(rhs.sizeX*rhs.sizeY);
236  for(iterator pnt = rhs.begin(); is && pnt != rhs.end(); pnt++)
237  is>>*pnt;
238  return is;
239  }
std::vector< T >::iterator iterator
Definition: Image.h:19
int sizeX
Definition: Image.h:245
int sizeY
Definition: Image.h:245

Member Data Documentation

template<class T>
int Image< T >::sizeX
protected
template<class T>
int Image< T >::sizeY
protected

The documentation for this class was generated from the following file: