PLearn 0.1
Public Member Functions | Protected Attributes | Friends
PLearn::RGBImageVMatrix Class Reference

#include <RGBImage.h>

Inheritance diagram for PLearn::RGBImageVMatrix:
Inheritance graph
[legend]
Collaboration diagram for PLearn::RGBImageVMatrix:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 RGBImageVMatrix (RGBImage image, const Vec &delta_row, const Vec &delta_col, real scale=1.0, real offset_=0.0)
virtual int width ()
virtual int length ()
virtual void reset ()
virtual void sample (Vec &samplevec)
virtual void seek (int position)
virtual int position ()
virtual bool first ()
 short hand for (position()==0)
void setImage (RGBImage new_image)
 replace the active image by this one

Protected Attributes

RGBImage image
Vec delta_row
 row displacement of neighbors
Vec delta_column
 column displacement of neighbors
real scale
 preprocessing of RGB values:
real offset_
 new_pixel = (old_pixel + offset_)*scale;
int width_
 (neighbors.length()+1)*3
int max_delta_row
int max_delta_column
int first_row
 first row that we can sample
int first_column
 first column that we can sample
int bottom_border_row
 first row that is in the bottom border
int right_border_col
 first column that is in the right border
int n_cols
 right_border_col-first_column
int current_i
int current_j
 current (row,column) of target pixel

Friends

class RGBImagesVMatrix

Detailed Description

RGBImageVMatrix is a subclass of distribution that allows to sample pixels from an RGB image, along with neighboring pixels. Sampling from this distribution gives a vector containing first the value of the chosen neighbors of the pixel and after the the value of the pixel itself. The neighbors are specified by relative row and column positions. The distribution cycles in left-to-right top-down order through all the pixels (except the borders where the neighbors are outside the image). RGB values may be translated and then scaled if scale and offset_are given.

Definition at line 222 of file RGBImage.h.


Constructor & Destructor Documentation

PLearn::RGBImageVMatrix::RGBImageVMatrix ( RGBImage  image,
const Vec delta_row,
const Vec delta_col,
real  scale = 1.0,
real  offset_ = 0.0 
)

The delta_row and delta_col vectors specify the relative position of the neighbors whose RGB values will be put before the "target" pixel's RGB values in each sample. Scale and offset_allow to linearly transform each R, G, and B value, with new_pixel = (old_pixel + offset_)*scale

Definition at line 390 of file RGBImage.cc.

References bottom_border_row, delta_column, delta_row, first_column, first_row, PLearn::RGBImage::height(), image, PLearn::TVec< T >::length(), MAX, PLearn::max(), max_delta_column, max_delta_row, MIN, PLearn::min(), n_cols, PLERROR, reset(), right_border_col, PLearn::RGBImage::width(), and width_.

  :image(the_image),
   delta_row(drow), delta_column(dcol),
   scale(the_scale), offset_(the_offset)
{
  if (delta_row.length()!=delta_column.length())
    PLERROR("RGBImageVMatrix: delta_row(%d) and delta_column(%d) have"
          " differing sizes",delta_row.length(),delta_column.length());
  width_ = 3 * (delta_row.length() + 1);
  if (delta_row.length()>0)
    {
      max_delta_row = (int)max(delta_row);
      int min_delta_row = (int)min(delta_row);
      max_delta_column = (int)max(delta_column);
      int min_delta_column = (int)min(delta_column);
      first_row = MAX(0,-min_delta_row);
      first_column = MAX(0,-min_delta_column);
      bottom_border_row = MIN(image.height(),image.height()-max_delta_row);
      right_border_col = MIN(image.width(),image.width()-max_delta_column);
    }
  else
    {
      first_row = 0;
      first_column = 0;
      bottom_border_row = image.height();
      right_border_col = image.width();
    }
  n_cols = right_border_col - first_column;
  reset();
}

Here is the call graph for this function:


Member Function Documentation

virtual bool PLearn::RGBImageVMatrix::first ( ) [inline, virtual]

short hand for (position()==0)

Definition at line 261 of file RGBImage.h.

Referenced by PLearn::RGBImagesVMatrix::firstSampleOfObject(), and PLearn::RGBImagesVMatrix::sample().

    { return (current_i==first_row) && (current_j==first_column); }

Here is the caller graph for this function:

int PLearn::RGBImageVMatrix::length ( ) [virtual]

Definition at line 443 of file RGBImage.cc.

References bottom_border_row, first_row, and n_cols.

Referenced by PLearn::RGBImagesVMatrix::nSamplesOfObject(), PLearn::RGBImagesVMatrix::RGBImagesVMatrix(), and seek().

Here is the caller graph for this function:

int PLearn::RGBImageVMatrix::position ( ) [virtual]

Definition at line 464 of file RGBImage.cc.

References current_i, current_j, first_column, first_row, and n_cols.

Referenced by PLearn::RGBImagesVMatrix::position().

Here is the caller graph for this function:

void PLearn::RGBImageVMatrix::reset ( ) [virtual]

Definition at line 449 of file RGBImage.cc.

References current_i, current_j, first_column, and first_row.

Referenced by PLearn::RGBImagesVMatrix::reset(), RGBImageVMatrix(), and setImage().

Here is the caller graph for this function:

void PLearn::RGBImageVMatrix::sample ( Vec samplevec) [virtual]

Definition at line 469 of file RGBImage.cc.

References PLearn::RGB::b, bottom_border_row, current_i, current_j, PLearn::TVec< T >::data(), delta_column, delta_row, first_column, first_row, PLearn::RGB::g, PLearn::RGBImage::getPixel(), image, PLearn::TVec< T >::length(), offset_, PLearn::RGB::r, PLearn::TVec< T >::resize(), right_border_col, scale, and width_.

Referenced by PLearn::RGBImagesVMatrix::sample().

{
  samplevec.resize(width_);
  real *sample = samplevec.data();
  real *dr = delta_row.data();
  real *dc = delta_column.data();
  int np = delta_row.length();
  // copy the value of its neighbors
  for (int p=0; p<np; p++) {
    int offset_i=(int)dr[p];
    int offset_j=(int)dc[p];
    RGB parent_rgb = image.getPixel(current_i+offset_i,current_j+offset_j);
    *(sample++) = (parent_rgb.r+offset_)*scale;
    *(sample++) = (parent_rgb.g+offset_)*scale;
    *(sample++) = (parent_rgb.b+offset_)*scale;
  }   

  // copy the value of the pixel
  RGB target_rgb = image.getPixel(current_i,current_j);
  *(sample++) = (target_rgb.r+offset_)*scale;
  *(sample++) = (target_rgb.g+offset_)*scale;
  *(sample++) = (target_rgb.b+offset_)*scale;

  // update current_i and current_j, traversing in
  // the usual left-to-right / top-to-bottom order:
  current_j++;
  if (current_j==right_border_col)
    {
      current_j = first_column;
      current_i++;
      if (current_i==bottom_border_row)
        current_i = first_row;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void PLearn::RGBImageVMatrix::seek ( int  position) [virtual]

Definition at line 455 of file RGBImage.cc.

References current_i, current_j, first_column, first_row, i, length(), n_cols, and PLERROR.

Referenced by PLearn::RGBImagesVMatrix::seek().

{
  if (position>=length())
    PLERROR("RGBImageVMatrix::seek(%d > size=%d)",position,length());
  int i = position / n_cols;
  current_i = first_row + i;
  current_j = first_column + position - i*n_cols;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void PLearn::RGBImageVMatrix::setImage ( RGBImage  new_image)

replace the active image by this one

Definition at line 424 of file RGBImage.cc.

References bottom_border_row, delta_row, first_column, PLearn::RGBImage::height(), image, PLearn::TVec< T >::length(), max_delta_column, max_delta_row, MIN, n_cols, reset(), right_border_col, and PLearn::RGBImage::width().

Referenced by PLearn::RGBImagesVMatrix::reset(), PLearn::RGBImagesVMatrix::RGBImagesVMatrix(), PLearn::RGBImagesVMatrix::sample(), and PLearn::RGBImagesVMatrix::seek().

{
  image = new_image;
  if (delta_row.length()>0)
    {
      bottom_border_row = 
        MIN(image.height(),image.height()-max_delta_row);
      right_border_col = 
        MIN(image.width(),image.width()-max_delta_column);
    }
  else
    {
      bottom_border_row = image.height();
      right_border_col = image.width();
    }
  n_cols = right_border_col - first_column;
  reset();
}

Here is the call graph for this function:

Here is the caller graph for this function:

int PLearn::RGBImageVMatrix::width ( ) [virtual]

Definition at line 446 of file RGBImage.cc.

References width_.

Referenced by PLearn::RGBImagesVMatrix::RGBImagesVMatrix().

{ return width_; }

Here is the caller graph for this function:


Friends And Related Function Documentation

friend class RGBImagesVMatrix [friend]

Definition at line 224 of file RGBImage.h.


Member Data Documentation

first row that is in the bottom border

Definition at line 236 of file RGBImage.h.

Referenced by length(), RGBImageVMatrix(), sample(), and setImage().

Definition at line 239 of file RGBImage.h.

Referenced by position(), reset(), sample(), and seek().

current (row,column) of target pixel

Definition at line 239 of file RGBImage.h.

Referenced by position(), reset(), sample(), and seek().

column displacement of neighbors

Definition at line 229 of file RGBImage.h.

Referenced by RGBImageVMatrix(), and sample().

row displacement of neighbors

Definition at line 228 of file RGBImage.h.

Referenced by RGBImageVMatrix(), sample(), and setImage().

first column that we can sample

Definition at line 235 of file RGBImage.h.

Referenced by position(), reset(), RGBImageVMatrix(), sample(), seek(), and setImage().

first row that we can sample

Definition at line 234 of file RGBImage.h.

Referenced by length(), position(), reset(), RGBImageVMatrix(), sample(), and seek().

Definition at line 227 of file RGBImage.h.

Referenced by RGBImageVMatrix(), sample(), and setImage().

Definition at line 233 of file RGBImage.h.

Referenced by RGBImageVMatrix(), and setImage().

Definition at line 233 of file RGBImage.h.

Referenced by RGBImageVMatrix(), and setImage().

right_border_col-first_column

Definition at line 238 of file RGBImage.h.

Referenced by length(), position(), RGBImageVMatrix(), seek(), and setImage().

new_pixel = (old_pixel + offset_)*scale;

Definition at line 231 of file RGBImage.h.

Referenced by sample().

first column that is in the right border

Definition at line 237 of file RGBImage.h.

Referenced by RGBImageVMatrix(), sample(), and setImage().

preprocessing of RGB values:

Definition at line 230 of file RGBImage.h.

Referenced by sample().

(neighbors.length()+1)*3

Definition at line 232 of file RGBImage.h.

Referenced by RGBImageVMatrix(), sample(), and width().


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