Conjecture::OptIm Class Reference

#include <OptIm.h>

Inheritance diagram for Conjecture::OptIm:

Conjecture::Root List of all members.

Detailed Description

An Optimized Image class (but only for small images).

****************************************************************

This class provides functionality and data for analyzing features of images of size 31x31 or less.

IMPORTANT: There are two stages of initialization associated with this class (it partially violates the Conjecture programming mandate that all classes be fully initialized by their constructors).

One bit is used to represent each pixel, and is either "on" (black) or "off" (white). Additional "meta" information about each row and column is also maintained, including the number of holes and the number of black pixels. This information can be used to create very efficient feature-detection algorithms.

The 'str' method is a useful debugging tool that shows the information maintained within an instance of this class in a very concise fashion. An example of the output for the call:

optim->str('#','.',7)

which generates:

0111110 0 #...... 1 0 #...... 1 0 #...... 1 0 #...... 1 1 #.###.. 4 1 ##...#. 3 1 #.....# 2 1 #.....# 2 0 .#####. 5 8222222

assuming that 'optim' is an Image* represents a 'b'. The numbers around the borders are interpreted as follows:

IMPORTANT: A "hole" in a line is a sequence of contiguous zero's (off or white bits) enclosed in 1's (on or black bits) on BOTH sides.

FUTURE FIX: Optimization issue. This class currently stores partially redundant information because the PixelLines for columns are repeating pixel information already present in the row PixelLines. However, the column PixelLines are also providing non-redundant information (the metadata). In order to remove this redundancy, we will most likely need to throw away PixelLine and simply use this class as an atomic unit. Instead of a vector of PixelLines, we would maintain an array of pixel data, a parallel array of row hole counts, a parallel array of row black counts, a transposed array of column black counts, and a transposed array of column hole counts. This would improve both space utilization, and the efficiency of 'set' and 'clear' methods.


Public Types

typedef std::vector< PixelLinePixelMatrix

Public Member Functions

 OptIm (const std::vector< unsigned int > &rows, u1 width=PixelLine::MaxPixels)
 OptIm (const Image *image, const ImageArgs &config)
const u1 & width () const
const PixelMatrix & cols () const
const PixelMatrix & rows () const
void updateMeta ()
int rblack (u1 i) const
int rholes (u1 i) const
int cblack (u1 i) const
int choles (u1 i) const
u1 height () const
bool get (u2 x, u2 y) const
std::string str (char on= '#', char off= '.') const
std::string str (const std::string &title, int valign=0, char on= '#', char off= '.') const
bool crop (int level=0)
bool crop (int topthick, int bottomthick, int leftthick, int rightthick)
bool crop (int topthick, int bottomthick, int leftthick, int rightthick, int &topref, int &bottomref, int &leftref, int &rightref)
void identifyFeatures (GlyphFeatures &features)
const PixelLinerow (int i) const
bool removeBottomSerifs ()
bool removeTopSerifs ()
void print (ostream &os=cout) const

Static Public Member Functions

static void test (int argc=0, const char *argv[]=NULL)

Protected Member Functions

bool updated () const
void updatedIs (const bool &updated)
void widthIs (const u1 &width)
void colsIs (const PixelMatrix &cols)
void rowsIs (const PixelMatrix &rows)
std::string rawstr (const PixelMatrix &vec, char on= '1', char off= '0', unsigned char size=PixelLine::MaxPixels) const
*Obtain a specific writeable
PixelLine by row Negative
*indexes are relative to the 
end (-1 is last index,-2 is *second last, etc.) inline PixelLine &row(int i)
GlyphFeatures::Variant analyzeLines (u1 min, u2 max, const PixelMatrix &matrix, u1 dom, u1 rec, u1 halfn)

Friends

class PixFilt


Member Function Documentation

int Conjecture::OptIm::cblack u1  i  )  const [inline]
 

Number of black pixels in column 'i'

int Conjecture::OptIm::choles u1  i  )  const [inline]
 

Number of holes in column 'i'

bool Conjecture::OptIm::crop int  level = 0  ) 
 

Crop the image

An image in which there are no black pixels along any border can be auto-cropped to a smaller image. More aggressive cropping can also be performed, in which continguous regions of "on" pixels that have a matching "on" pixel in the adjacent row/column are turned off (and the result potentially cropped).

Parameters:
level If 0, basic cropping. If 1, perform contiguous region cropping in the one pixel thick boundary. If greater than 1, performs region cropping on the 'level'-pixel thick boundary.

bool Conjecture::OptIm::get u2  x,
u2  y
const [inline]
 

Returns the pixel value at image coord <x,y> (origin at top-left corner of image).

void Conjecture::OptIm::identifyFeatures GlyphFeatures features  ) 
 

Performs some serious work. Feature detection.

Parameters:
features out parameter - fields initialized by this method
Note: Method is non-const because it auto-updates metadata if necessary. Should we throw exceptions in such cases instead?

int Conjecture::OptIm::rblack u1  i  )  const [inline]
 

Number of black pixels in row 'i'

bool Conjecture::OptIm::removeBottomSerifs  ) 
 

This method performs bottom serif removal on the image.

NOTE: metadata is not needed for this method, and it is more efficient if this method is invoked before metadata is computed.

bool Conjecture::OptIm::removeTopSerifs  ) 
 

This method performs top serif removal on the image.

NOTE: metadata is not needed for this method, and it is more efficient if this method is invoked before metadata is computed.

int Conjecture::OptIm::rholes u1  i  )  const [inline]
 

Number of holes in row 'i'

const PixelLine& Conjecture::OptIm::row int  i  )  const [inline]
 

Obtain a specific const PixelLine by row. Negative indexes are relative to the end (-1 is last index, -2 is second last, etc.)

std::string Conjecture::OptIm::str const std::string &  title,
int  valign = 0,
char  on = '#',
char  off = '.'
const
 

Create a string representation

Parameters:
title The title, placed above the column
valign The number of rows to insert between title and start of data

std::string Conjecture::OptIm::str char  on = '#',
char  off = '.'
const [inline]
 

Create printable representation of this OptIm.

See the class comments for more details.


The documentation for this class was generated from the following files:
Generated on Thu Jun 15 19:56:11 2006 for Conjecture by  doxygen 1.4.6