Doxygen
commonUtil.cpp File Reference

common routines for image IO More...

#include <iostream>
#include <algorithm>
#include <fstream>
#include <sys/time.h>
#include <string>
#include <limits>
#include <utility>
#include <vector>
#include "io_png.h"
#include "commonUtil.h"
#include "Detector.h"
#include <Eigen/Dense>
+ Include dependency graph for commonUtil.cpp:

Go to the source code of this file.

Macros

#define VERBOSE   true
 
#define UNIT   1e2
 
#define STORAGE   "trainData"
 

Typedefs

typedef Matrix< long double,
Dynamic, Dynamic > 
MatrixXld
 

Functions

void fail (string const &message)
 print an error message and then quit More...
 
void times (const char *which)
 timer More...
 
void imread (const char *fileName, int &nRows, int &nCols, int &nChannels, MatrixXf *&image, bool outputGray)
 read in fileName as it is or gray More...
 
void imwrite (const char *fileName, MatrixXf *image, int nChannels)
 write out an image as PNG More...
 
void buildIntegralImage (MatrixXf &image, MatrixXld &integralImage)
 integral image in linear time More...
 
long double sumImagePart (MatrixXld &integralImage, int ui, int uj, int ir, int jr)
 sum up the pixels in a sub-rectangle of the image More...
 
int pathFile2charArray (const char *pathFile, char **&addr, VectorXi *blackList, int sign)
 format pathFile so that it's more readable More...
 
int readImagesFromPathFile (const char *pathFile, MatrixXf **&images, VectorXi *blackList, int sign)
 read in images in the pathFile More...
 
void writeToDisk (VectorXf &dataVector, char const *prefix, int index)
 write a vector to the external disk More...
 
bool fileExist (const char *fname, bool del)
 test whether fname's already there More...
 
float readFromDisk (char const *prefix, int index, int entry)
 read a vector entry from data files More...
 
bool myPairOrder (const pair< float, int > &one, const pair< float, int > &other)
 an auxiliary function for pair ordering More...
 
vector< pair< float, int > > * writeOrganizedFeatures (int featureCount, int sampleCount, RowVectorXf *&featureVectors)
 sort every feature and write them out in ascending order More...
 
void removeFeatures (int featureCount, int sampleCount)
 remove all the traces More...
 
void removeFile (const char *fname)
 
void whatFeature (int featureIndex)
 print some additional information about this feature More...
 

Detailed Description

common routines for image IO

Author
Yi-Qing WANG yiqin.nosp@m.g.wa.nosp@m.ng@po.nosp@m.lyte.nosp@m.chniq.nosp@m.ue.e.nosp@m.du

Definition in file commonUtil.cpp.

Macro Definition Documentation

#define STORAGE   "trainData"

Definition at line 40 of file commonUtil.cpp.

#define UNIT   1e2

Definition at line 39 of file commonUtil.cpp.

#define VERBOSE   true

Definition at line 38 of file commonUtil.cpp.

Typedef Documentation

typedef Matrix<long double,Dynamic,Dynamic> MatrixXld

Definition at line 44 of file commonUtil.cpp.

Function Documentation

void buildIntegralImage ( MatrixXf &  image,
MatrixXld integralImage 
)

integral image in linear time

Parameters
imageoriginal image
Returns
integralImage integral image

Definition at line 145 of file commonUtil.cpp.

void fail ( string const &  message)

print an error message and then quit

Definition at line 47 of file commonUtil.cpp.

bool fileExist ( const char *  fname,
bool  del = true 
)

test whether fname's already there

Parameters
fnamewhich file
deldelete this unexpected file
Returns
true if so, false otherwise

Definition at line 371 of file commonUtil.cpp.

void imread ( const char *  fileName,
int &  nRows,
int &  nCols,
int &  nChannels,
MatrixXf *&  image,
bool  outputGray 
)

read in fileName as it is or gray

Parameters
fileNamepath of the image to read in
nRowsnumber of image rows
nColsnumber of image columns
nChannelsnumber of image channels
outputGrayread in as gray
Returns
image format image as a matrix

Definition at line 77 of file commonUtil.cpp.

void imwrite ( const char *  fileName,
MatrixXf *  image,
int  nChannels 
)

write out an image as PNG

Parameters
fileNamepath of the image to read in
nRowsnumber of image rows
nColsnumber of image columns
nChannelsnumber of image channels
outputGrayread in as gray
Returns
image format image as a matrix

Definition at line 115 of file commonUtil.cpp.

bool myPairOrder ( const pair< float, int > &  one,
const pair< float, int > &  other 
)

an auxiliary function for pair ordering

Definition at line 422 of file commonUtil.cpp.

int pathFile2charArray ( const char *  pathFile,
char **&  addr,
VectorXi *  blackList,
int  sign 
)

format pathFile so that it's more readable

Parameters
pathFilepaths to images
addrchar array
blackListdelete those in the blackList before formatting
signPOSITIVE or NEGATIVE
Returns
number of samples collected

Definition at line 183 of file commonUtil.cpp.

float readFromDisk ( char const *  prefix,
int  index,
int  entry 
)

read a vector entry from data files

Parameters
prefixwhich vector content
indexwhich vector
entrywhich entry in the vector
Returns
feature value of this example

Definition at line 390 of file commonUtil.cpp.

int readImagesFromPathFile ( const char *  pathFile,
MatrixXf **&  images,
VectorXi *  blackList,
int  sign 
)

read in images in the pathFile

Parameters
pathFilepaths to images
blackListdelete those in the blackList before formatting
signPOSITIVE or NEGATIVE
Returns
images
number of samples collected

Definition at line 289 of file commonUtil.cpp.

void removeFeatures ( int  featureCount,
int  sampleCount 
)

remove all the traces

Parameters
featureCount
sampleCount

Definition at line 484 of file commonUtil.cpp.

void removeFile ( const char *  fname)

Definition at line 501 of file commonUtil.cpp.

long double sumImagePart ( MatrixXld integralImage,
int  ui,
int  uj,
int  ir,
int  jr 
)

sum up the pixels in a sub-rectangle of the image

Parameters
integralImageits integral image
uirow index of this sub-rectangle's up left corner
ujcolumn index of this sub-rectangle's up left corner
irnumber of rows of this sub-rectangle
jrnumber of columns of this sub-rectangle
Returns
the sum

Definition at line 162 of file commonUtil.cpp.

void times ( const char *  which)

timer

Definition at line 53 of file commonUtil.cpp.

void whatFeature ( int  featureIndex)

print some additional information about this feature

Definition at line 509 of file commonUtil.cpp.

vector< pair<float, int> >* writeOrganizedFeatures ( int  featureCount,
int  sampleCount,
RowVectorXf *&  featureVectors 
)

sort every feature and write them out in ascending order

Parameters
featureCount
sampleCount
ifyou choose to read features from memory instead of disk

Definition at line 431 of file commonUtil.cpp.

void writeToDisk ( VectorXf &  dataVector,
char const *  prefix,
int  index 
)

write a vector to the external disk

Parameters
dataVectorthe vector itself
prefix
indexwhich

Definition at line 335 of file commonUtil.cpp.