Structural deformable models
Functions
Data.cpp File Reference
#include <fstream>
#include <sstream>
#include <math.h>
#include <GL/gl.h>
#include "Data.h"
#include "fxconfig.h"
#include <fx.h>
#include <FXPNGImage.h>
#include <FXJPGImage.h>
#include <FXTIFImage.h>
#include <FXICOImage.h>
#include <FXTGAImage.h>
#include <FXRGBImage.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <signal.h>
#include <unistd.h>
Include dependency graph for Data.cpp:

Go to the source code of this file.

Functions

static void copyFXImage2Image (vector< Image< byte > > &dimg, const FXImage &img)
 
static void copyFXImage2Image (Image< byte > &dimg, const FXImage &img)
 
static void copyImage2FXImage (FXImage &img, const vector< Image< byte > > &dimg)
 
template<class T >
Image< T > & makeNoiseImage (Image< T > &nimg, T mean, T sigma)
 
byteinterleave (const vector< Image< byte > > &img)
 
static void copyImage2FXImage (FXImage &img, const Image< byte > &dimg)
 

Function Documentation

static void copyFXImage2Image ( vector< Image< byte > > &  dimg,
const FXImage &  img 
)
static

Definition at line 280 of file Data.cpp.

Referenced by Dataset::loadImage().

281 {
282  //FXImage *img=imgv->getImage();
283  // copy to image buffer
284  int height = img.getHeight();
285  int width = img.getWidth();
286  int size = width*height;
287  byte *imgdat = (byte*)img.getData();
288  const int nchan = 4;
289  dimg.clear();
290  dimg.resize(nchan);//, Image<byte>(width,height));
291  for(vector< Image<byte> >::iterator ii = dimg.begin();
292  ii!=dimg.end(); ii++)
293  ii->setSize(width, height);
294  //dimg.setSize(width,height);
295  int sind = 0;
296  for(int i=size;i>0;i--,imgdat+=nchan,sind++)
297  {
298  for(int c=0; c<nchan; c++) {
299  dimg[c][sind] = imgdat[c];
300  }
301  }
302 }
unsigned char byte
Definition: simpletypes.h:4
static void copyFXImage2Image ( Image< byte > &  dimg,
const FXImage &  img 
)
static

Definition at line 304 of file Data.cpp.

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

305 {
306  //FXImage *img=imgv->getImage();
307  // copy to image buffer
308  int height = img.getHeight();
309  int width = img.getWidth();
310  int size = width*height;
311  byte *imgdat = (byte*)img.getData();
312  dimg.setSize(width,height);
313  byte *htimg = dimg.getData();
314  int nchan = 4;
315  for(int i=size;i>0;i--,imgdat+=nchan,htimg++)
316  {
317  //int val = int(0.299f*imgdat[0]+0.587f*imgdat[1]+0.114f*imgdat[2]);
318  //int val = (int(imgdat[0])+imgdat[1]+imgdat[2])/3;
319  int val = imgdat[0];
320  //*htimg = val > 255 ? 255 : val;
321  *htimg = byte(val);
322  }
323 }
unsigned char byte
Definition: simpletypes.h:4
void setSize(int nx, int ny)
Definition: Image.h:268
const T * getData() const
Definition: Image.h:39
static void copyImage2FXImage ( FXImage &  img,
const vector< Image< byte > > &  dimg 
)
static
static void copyImage2FXImage ( FXImage &  img,
const Image< byte > &  dimg 
)
static

Definition at line 326 of file Data.cpp.

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

327 {
328  int height = img.getHeight();
329  int width = img.getWidth();
330  img.resize(dimg.getSizeX(), dimg.getSizeY());
331  int size = width*height;
332  byte *imgdat = (byte*)img.getData();
333  const byte *htimg = dimg.getData();
334  int nchan = 4;
335  for(int i=size;i>0;i--,imgdat+=nchan,htimg++)
336  {
337  imgdat[0] = *htimg;
338  imgdat[1] = *htimg;
339  imgdat[2] = *htimg;
340  }
341 
342  img.create();
343 }
int getSizeX() const
Definition: Image.h:42
unsigned char byte
Definition: simpletypes.h:4
const T * getData() const
Definition: Image.h:39
int getSizeY() const
Definition: Image.h:43
byte* interleave ( const vector< Image< byte > > &  img)

Definition at line 241 of file Data.cpp.

Referenced by Dataset::drawImage().

241  {
242  const int comp = img.size()>3 ? 3 : img.size();
243  int size = img[0].size();
244  byte *b = new byte[size*3];
245  if(comp<3) {
246  Image<byte>::const_iterator bi = img[0].begin();
247  byte *cv = b;
248  for(int i=0; i!=size; i++, cv++, bi++)
249  *cv = *bi;
250  } else { // comp == 3
252  for(int a=0; a<comp; a++) bi[a] = img[a].begin();
253  byte *cv = b;
254  for(int i=0; i<size; i++) {
255  *(cv++) = *bi[0]; bi[0]++;
256  *(cv++) = *bi[1]; bi[1]++;
257  *(cv++) = *bi[2]; bi[2]++;
258  }
259  }
260  return b;
261 }
unsigned char byte
Definition: simpletypes.h:4
Definition: Image.h:16
template<class T >
Image< T > & makeNoiseImage ( Image< T > &  nimg,
mean,
sigma 
)

Definition at line 346 of file Data.cpp.

References Dataset::data, fgauss01(), Image< T >::getData(), Image< T >::getSizeX(), Image< T >::getSizeY(), and Sensor::mean.

347 {
348  T* data = nimg.getData();
349  for(int j=0; j<nimg.getSizeY(); j++)
350  for(int i=0; i<nimg.getSizeX(); i++, data++)
351  {
352  *data = (T)(fgauss01()*sigma+mean);
353  }
354  return nimg;
355 }
int getSizeX() const
Definition: Image.h:42
float fgauss01()
Definition: mathutil.h:53
const T * getData() const
Definition: Image.h:39
int getSizeY() const
Definition: Image.h:43