PLearn 0.1
|
#include <RGBImage.h>
Public Member Functions | |
RGBImageDB (char *dbfilename, int the_subsample_factor=1, int remove_border=0, int the_max_n_images_in_memory=10) | |
RGBImage | getImage (int imageid) |
Mat | computeHistogramRepresentation (int r_bins=16, int g_bins=16, int b_bins=16, bool do_normalize=false) |
Returns for each image a vector of size r_bins*g_bins*b_bins+1 which contains the number of image pixels whose colors fell in the corresponding RGB range, and last element is the class number. | |
~RGBImageDB () | |
Public Attributes | |
Mat | imageIdAndClass |
These are two column matrices (first column: imageid, second column: classnum) | |
Protected Member Functions | |
int | append (char *filename) |
void | load (char *dbfile) |
RGBImageDB (int the_subsample_factor=1, int remove_border=0, int the_max_n_images_in_memory=10) | |
Protected Attributes | |
Array< char * > | filenames |
Array< RGBImage * > | images |
int | subsample_factor |
int | remove_border |
int | max_n_images_in_memory |
int | n_images_in_memory |
Definition at line 176 of file RGBImage.h.
PLearn::RGBImageDB::RGBImageDB | ( | int | the_subsample_factor = 1 , |
int | remove_border = 0 , |
||
int | the_max_n_images_in_memory = 10 |
||
) | [protected] |
Definition at line 286 of file RGBImage.cc.
: subsample_factor(the_subsample_factor), remove_border(the_remove_border), max_n_images_in_memory(the_max_n_images_in_memory), n_images_in_memory(0) { }
PLearn::RGBImageDB::RGBImageDB | ( | char * | dbfilename, |
int | the_subsample_factor = 1 , |
||
int | remove_border = 0 , |
||
int | the_max_n_images_in_memory = 10 |
||
) |
Definition at line 292 of file RGBImage.cc.
References load().
: subsample_factor(the_subsample_factor), remove_border(the_remove_border), max_n_images_in_memory(the_max_n_images_in_memory), n_images_in_memory(0) { load(dbfilename); }
PLearn::RGBImageDB::~RGBImageDB | ( | ) |
int PLearn::RGBImageDB::append | ( | char * | filename | ) | [protected] |
Definition at line 323 of file RGBImage.cc.
References PLearn::TVec< T >::append(), filenames, images, and PLearn::TVec< T >::size().
Referenced by load().
Mat PLearn::RGBImageDB::computeHistogramRepresentation | ( | int | r_bins = 16 , |
int | g_bins = 16 , |
||
int | b_bins = 16 , |
||
bool | do_normalize = false |
||
) |
Returns for each image a vector of size r_bins*g_bins*b_bins+1 which contains the number of image pixels whose colors fell in the corresponding RGB range, and last element is the class number.
Definition at line 356 of file RGBImage.cc.
References PLearn::RGBImage::computeHistogram(), getImage(), i, imageIdAndClass, PLearn::TMat< T >::lastColumn(), PLearn::TMat< T >::length(), and PLearn::TMat< T >::subMatColumns().
{ Mat dataset(imageIdAndClass.length(), r_bins*g_bins*b_bins+1); Mat histograms = dataset.subMatColumns(0,r_bins*g_bins*b_bins); Mat classnums = dataset.lastColumn(); for(int i=0; i<imageIdAndClass.length(); i++) { RGBImage im = getImage((int)imageIdAndClass(i,0)); histograms(i) << im.computeHistogram(r_bins,g_bins,b_bins,do_normalize); classnums(i,0) = imageIdAndClass(i,0); } return dataset; }
Definition at line 331 of file RGBImage.cc.
References filenames, i, images, PLearn::RGBImage::loadJPEG(), max_n_images_in_memory, n_images_in_memory, remove_border, PLearn::RGBImage::removeBorders(), PLearn::TVec< T >::size(), and subsample_factor.
Referenced by computeHistogramRepresentation(), PLearn::RGBImagesVMatrix::reset(), PLearn::RGBImagesVMatrix::RGBImagesVMatrix(), PLearn::RGBImagesVMatrix::sample(), and PLearn::RGBImagesVMatrix::seek().
{ if(!images[imageid]) { RGBImage* newimage = new RGBImage; newimage->loadJPEG(filenames[imageid],subsample_factor); if (remove_border>0) newimage->removeBorders(remove_border); n_images_in_memory++; if (n_images_in_memory>max_n_images_in_memory) { for(int i=0; i<images.size(); i++) if(images[i]!=0) { delete images[i]; images[i] = 0; } } images[imageid] = newimage; } return *images[imageid]; }
void PLearn::RGBImageDB::load | ( | char * | dbfile | ) | [protected] |
Definition at line 300 of file RGBImage.cc.
References append(), imageIdAndClass, in, n, PLERROR, and PLearn::TMat< T >::resize().
Referenced by RGBImageDB().
{ ifstream in(dbfile); if(!in) PLERROR("In RGBImageDB::load could not open dbfile %s for reading",dbfile); char filename[300]; int classnum; int n = 0; in >> filename >> classnum; while(in) { int imageid = append(filename); n++; imageIdAndClass.resize(n,2); imageIdAndClass(n-1,0) = imageid; imageIdAndClass(n-1,1) = classnum; in >> filename >> classnum; } }
Array<char*> PLearn::RGBImageDB::filenames [protected] |
Definition at line 179 of file RGBImage.h.
Referenced by append(), getImage(), and ~RGBImageDB().
These are two column matrices (first column: imageid, second column: classnum)
Definition at line 194 of file RGBImage.h.
Referenced by computeHistogramRepresentation(), load(), PLearn::RGBImagesVMatrix::nObjects(), PLearn::RGBImagesVMatrix::reset(), PLearn::RGBImagesVMatrix::RGBImagesVMatrix(), PLearn::RGBImagesVMatrix::sample(), and PLearn::RGBImagesVMatrix::seek().
Array<RGBImage*> PLearn::RGBImageDB::images [protected] |
Definition at line 180 of file RGBImage.h.
Referenced by append(), getImage(), and ~RGBImageDB().
int PLearn::RGBImageDB::max_n_images_in_memory [protected] |
Definition at line 183 of file RGBImage.h.
Referenced by getImage().
int PLearn::RGBImageDB::n_images_in_memory [protected] |
Definition at line 184 of file RGBImage.h.
Referenced by getImage().
int PLearn::RGBImageDB::remove_border [protected] |
Definition at line 182 of file RGBImage.h.
Referenced by getImage().
int PLearn::RGBImageDB::subsample_factor [protected] |
Definition at line 181 of file RGBImage.h.
Referenced by getImage().