MPEG CDVA Experimentation Model (CXM)  1.0
Compact Descriptors for Visual Analisys
CoordinateCoding.h
Go to the documentation of this file.
1 /*
2 The copyright in this software is being made available under this MPEG Reference Software Copyright License. This software may be subject to other third party and contributor rights, including patent rights, and no such rights are granted under this license.
3 
4 Copyright (c) 2016-2017, Joanneum Research, Mitsubishi Electric Research Labs, Peking University, Telecom Italia, University of Surrey, Visual Atoms
5 
6 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
7 * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
8 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9 * Neither the names of Joanneum Research, Mitsubishi Electric Research Labs, Peking University, Telecom Italia, University of Surrey, Visual Atoms nor the names of their contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
11 */
12 
13 #pragma once
14 
15 #include "BitOutputStream.h"
16 #include "BitInputStream.h"
17 #include "FeatureList.h"
18 #include "Parameters.h"
19 #include "RefFeature.h"
20 #include "DescriptorTimeMap.h"
21 
22 using namespace mpeg7cdvs;
23 
24 namespace mpeg7cdva
25 {
26 
33 {
34 public:
35  static const int SUM_HIST_COUNT_SIZE = 64;
36  static const int CONTEXT_RANGE = 5;
37  static const int MAXIMUM_SUM_CONTEXT = (2*CONTEXT_RANGE*CONTEXT_RANGE + CONTEXT_RANGE) ;
38 
44  long vCount[SUM_HIST_COUNT_SIZE];
45  long vInitialMap[2];
46  long vMap[MAXIMUM_SUM_CONTEXT+1][2];
47  } ;
48 
49 private:
50 
51  static const int CONTEXT_TABLE[12][6];
52  static const int HIST_COUNT_TABLE[12][3];
53 
54  CoordinateCoding(const CoordinateCoding& p); // copy constructor - set private to avoid its usage.
55  CoordinateCoding &operator=(const CoordinateCoding&); // assignment operator - set private to avoid its usage.
56  static int compareArray(int * a, int * b, int size); // compare two int arrays
57  static int compareArray(int * a, int * b, int iWidth, int iHeight, bool bTranspose); // compare two int arrays
58  static int compareArray(bool * a, bool * b, int size); // compare two bool arrays
59 
60  // Input parameters
61  int m_debugLevel; // If (debugLevel > 0) some debugging info will be printed
62  int m_blockWidth; // Size of the grid used to build the histogram map
63  int m_queryLength; // To identify operating point
64 
65  // Histogram count data structure
66  int* m_hCount; // Pointer to the histogram count
67  int m_hCountSize; // Histogram count size
68 
69  // Histogram map data structure
70  int* m_hMap; // Pointer to histogram map
71  int m_hMapSizeX; // X Dimension of histogram map
72  int m_hMapSizeY; // Y Dimension of histogram map
73  bool m_bIsTransposed; // Indicating whether the circular scanned matrix needs to be transposed
74 
75  // For context entropy coding
76  bool m_bTrainingMode;
77  CircularSumContext m_csc;
78 
79  bool m_readSize;
80 
81  // Utility functions
82  void TransposeMatrix( int* &pMatrix, int &iRows, int &iCols);
83 
84  bool readOK;
85 
86 public:
87 
92  CoordinateCoding(const Parameters & param);
93 
94  virtual ~CoordinateCoding(); // destructor
95 
100  void toBinary(BitOutputStream & writer, bool writeSize = true);
101 
106  void fromBinary(BitInputStream & reader);
107 
114  void fromBinary(BitInputStream & reader, unsigned int hMapSizeX, unsigned int hMapSizeY);
115 
121  int compare(const CoordinateCoding & other);
122 
129  void exportVars(unsigned int & histogramCountSize, unsigned int & histogramMapSizeX, unsigned int & histogramMapSizeY) const;
130 
131 
137  void generateHistogramMap(FeatureList & featurelist, int numPoints);
138 
145  void generateHistogramMap(std::vector<RefFeature> & refFeaturelist, FeatureList & featurelist, int offset, int frameIdx, DescriptorTimeMap& dtm, int numPoints, int xSize, int ySize);
146 
147 
152  void generateFeatureList(FeatureList & descriptors);
153 
154 
155  // Functions for context training
156  void StartTrainingMode();
157  void EndTrainingMode();
158  int AddImageSample(FeatureList& featurelist);
159 
160  // Functions for context I/O
161  int writeSeparateContext(char *filename);
162  static int readSeparateContext( char *filename, CircularSumContext &cCsc);
163  int readSeparateContext( char *filename);
164 
166 
167  void setVerbose() { m_debugLevel = 2; }
168 
173  void difference(CoordinateCoding& other);
174 
175  void generateHistogramMap2(FeatureList & featurelist, int numPoints);
176 
177  void setIsOK(bool ok) { readOK = ok; }
178 
179 };
180 
181 } // end of namespace
Definition: DescriptorTimeMap.h:24
Basic structure for Cssc.
Definition: CoordinateCoding.h:43
Namespace used to encapsulate all MPEG-7 CDVA declarations.
Definition: Buffer.h:14
Definition: CoordinateCoding.h:32
void setIsOK(bool ok)
Definition: CoordinateCoding.h:177
void setVerbose()
Definition: CoordinateCoding.h:167