Direct Graphical Models  v.1.7.0
DirectGraphicalModels::fex::CSparseCoding Class Reference

Sparse Coding feature extraction class. More...

#include <SparseCoding.h>

Inheritance diagram for DirectGraphicalModels::fex::CSparseCoding:
Collaboration diagram for DirectGraphicalModels::fex::CSparseCoding:

Public Member Functions

 CSparseCoding (const Mat &img)
 Constructor. More...
 
virtual ~CSparseCoding (void)
 
virtual Mat get (void) const
 Extracts and returns the required feature. More...
 
- Public Member Functions inherited from DirectGraphicalModels::fex::ILocalFeatureExtractor
 ILocalFeatureExtractor (const Mat &img)
 Constructor. More...
 
virtual ~ILocalFeatureExtractor (void)
 
- Public Member Functions inherited from DirectGraphicalModels::fex::IFeatureExtractor
 IFeatureExtractor (const Mat &img)
 Constructor. More...
 
virtual ~IFeatureExtractor (void)
 
- Public Member Functions inherited from DirectGraphicalModels::fex::CSparseDictionary
 CSparseDictionary (void)
 
virtual ~CSparseDictionary (void)
 
void train (const Mat &X, word nWords, dword batch=2000, unsigned int nIt=1000, float lRate=SC_LRATE_D, const std::string &fileName=std::string())
 Trains dictionary \(D\). More...
 
void save (const std::string &fileName) const
 Saves dictionary \(D\) into a binary file. More...
 
void load (const std::string &fileName)
 Loads dictionary \(D\) from the file. More...
 
bool empty (void) const
 Checks whether the dictionary has been trained or loaded. More...
 
Mat getDictionary (void) const
 Returns dictionary \(D\). More...
 
int getBlockSize (void) const
 Returns size of the block, i.e. \(\sqrt{sampleLen}\). More...
 
word getNumWords (void) const
 Returns the number words in dictionary \(D\). More...
 

Static Public Member Functions

static Mat get (const Mat &img, const Mat &D, SqNeighbourhood nbhd=sqNeighbourhood(3))
 Extracts the sparse coding feature. More...
 
static vec_mat_t get_v (const Mat &img, const Mat &D, SqNeighbourhood nbhd=sqNeighbourhood(3))
 Extracts the sparse coding feature. More...
 
- Static Public Member Functions inherited from DirectGraphicalModels::fex::CSparseDictionary
static Mat getDictionary (const std::string &fileName)
 Returns dictionary \(D\) from file. More...
 
static Mat img2data (const Mat &img, int blockSize, float varianceThreshold=0.0f)
 Converts image into data \(X\). More...
 
static Mat data2img (const Mat &X, cv::Size imgSize)
 Converts data \(X\) into an image. More...
 

Additional Inherited Members

- Protected Types inherited from DirectGraphicalModels::fex::CSparseDictionary
enum  grad_type { GRAD_D, GRAD_W }
 
- Static Protected Member Functions inherited from DirectGraphicalModels::fex::CSparseDictionary
static void calculate_W (const Mat &X, const Mat &D, Mat &W, float lambda, float epsilon, unsigned int nIt=800, float lRate=SC_LRATE_W)
 Evaluates weighting coefficients matrix \(W\). More...
 
static void calculate_D (const Mat &X, Mat &D, const Mat &W, float gamma, unsigned int nIt=800, float lRate=SC_LRATE_D)
 Evaluates dictionary \(D\). More...
 
static Mat calculateGradient (grad_type gType, const Mat &X, const Mat &D, const Mat &W, float lambda, float epsilon, float gamma)
 Calculates the gradient matrices \(\frac{\partial J(D, W)}{\partial D}\) and \(\frac{\partial J(D, W)}{\partial W}\). More...
 
static float calculateCost (const Mat &X, const Mat &D, const Mat &W, float lambda, float epsilon, float gamma)
 Calculates the value of \(J(D, W)\) function. More...
 
- Protected Attributes inherited from DirectGraphicalModels::fex::IFeatureExtractor
const Mat m_img
 Container for the image, from which the features are to be extracted. More...
 

Detailed Description

Sparse Coding feature extraction class.

Author
Sergey G. Kosov, serge.nosp@m.y.ko.nosp@m.sov@p.nosp@m.roje.nosp@m.ct-10.nosp@m..de

Definition at line 17 of file SparseCoding.h.

Constructor & Destructor Documentation

◆ CSparseCoding()

DirectGraphicalModels::fex::CSparseCoding::CSparseCoding ( const Mat &  img)
inline

Constructor.

Parameters
imgInput image of type CV_8UC1.

Definition at line 24 of file SparseCoding.h.

◆ ~CSparseCoding()

virtual DirectGraphicalModels::fex::CSparseCoding::~CSparseCoding ( void  )
inlinevirtual

Definition at line 25 of file SparseCoding.h.

Member Function Documentation

◆ get() [1/2]

virtual Mat DirectGraphicalModels::fex::CSparseCoding::get ( void  ) const
inlinevirtual

Extracts and returns the required feature.

Returns
The feature image.

Implements DirectGraphicalModels::fex::ILocalFeatureExtractor.

Definition at line 27 of file SparseCoding.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get() [2/2]

Mat DirectGraphicalModels::fex::CSparseCoding::get ( const Mat &  img,
const Mat &  D,
SqNeighbourhood  nbhd = sqNeighbourhood(3) 
)
static

Extracts the sparse coding feature.

This fuction supports dictionaries with nWords less or equal to 512 words. For larger dictionaries use CSparseCoding::get_v() function directly.

Parameters
imgInput image of type CV_8UC1 or CV_8UC3.
DSparse dictionary \(D\): Mat(size nWords x blockSize^2; type CV_32FC1).

Dictionary should be learned from a training data with CSparseDictionary::train() function,
or it may be loaded directed from a dic file with CSparseDictionary::getDictionary("dictionary.dic").

nbhdNeighborhood around the pixel, where the samples are estimated. (Ref. SqNeighbourhood). It shoul be a square with a side equal to blockSize.
Returns
The sparse coding feature image of type CV_8UC{nWords}.

Definition at line 8 of file SparseCoding.cpp.

Here is the call graph for this function:

◆ get_v()

vec_mat_t DirectGraphicalModels::fex::CSparseCoding::get_v ( const Mat &  img,
const Mat &  D,
SqNeighbourhood  nbhd = sqNeighbourhood(3) 
)
static

Extracts the sparse coding feature.

This function is an alternative to get(), which can handle large amount of features (more then 512)

Parameters
imgInput image of type CV_8UC1 or CV_8UC3.
DSparse dictionary \(D\): Mat(size nWords x blockSize^2; type CV_32FC1).

Dictionary should be learned from a training data with CSparseDictionary::train() function,
or it may be loaded directed from a dic file with CSparseDictionary::getDictionary("dictionary.dic").

nbhdNeighborhood around the pixel, where the samples are estimated. (Ref. SqNeighbourhood). It shoul be a square with a side equal to blockSize.
Returns
The vector with nWords sparse coding feature images of type CV_8UC1 each.

Definition at line 19 of file SparseCoding.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

The documentation for this class was generated from the following files: