PLearn 0.1
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes
PLearn::RGBImageDB Class Reference

#include <RGBImage.h>

Collaboration diagram for PLearn::RGBImageDB:
Collaboration graph
[legend]

List of all members.

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

Detailed Description

Definition at line 176 of file RGBImage.h.


Constructor & Destructor Documentation

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);
}

Here is the call graph for this function:

PLearn::RGBImageDB::~RGBImageDB ( )

Definition at line 372 of file RGBImage.cc.

References filenames, i, images, and PLearn::TVec< T >::size().

{
  for(int i=0; i<filenames.size(); i++)
    {
      free(filenames[i]);
      if(images[i])
        delete images[i];
    }
}

Here is the call graph for this function:


Member Function Documentation

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().

{
  filenames.append(strdup(filename));
  images.append(0);
  return filenames.size()-1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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;
}

Here is the call graph for this function:

RGBImage PLearn::RGBImageDB::getImage ( int  imageid)

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];
}

Here is the call graph for this function:

Here is the caller graph for this function:

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;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 179 of file RGBImage.h.

Referenced by append(), getImage(), and ~RGBImageDB().

Definition at line 180 of file RGBImage.h.

Referenced by append(), getImage(), and ~RGBImageDB().

Definition at line 183 of file RGBImage.h.

Referenced by getImage().

Definition at line 184 of file RGBImage.h.

Referenced by getImage().

Definition at line 182 of file RGBImage.h.

Referenced by getImage().

Definition at line 181 of file RGBImage.h.

Referenced by getImage().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines