KSquare Utilities
Raster.cpp File Reference
#include "FirstIncludes.h"
#include <memory>
#include <math.h>
#include <limits.h>
#include <fstream>
#include <map>
#include <string.h>
#include <string>
#include <iostream>
#include <vector>
#include "MemoryDebug.h"
#include "kku_fftw.h"
#include "Raster.h"
#include "KKBaseTypes.h"
#include "Blob.h"
#include "BMPImage.h"
#include "Compressor.h"
#include "ConvexHull.h"
#include "EigenVector.h"
#include "GoalKeeper.h"
#include "Histogram.h"
#include "ImageIO.h"
#include "KKException.h"
#include "Matrix.h"
#include "MorphOpBinarize.h"
#include "MorphOpDilation.h"
#include "MorphOpErosion.h"
#include "MorphOpStretcher.h"
#include "OSservices.h"
#include "SimpleCompressor.h"
#include "MorphOpSobel.h"

Go to the source code of this file.

Functions

float DeltaAngle (float ang1, float ang2)
 Returns the difference between two angles in degrees. More...
 
template<typename T >
FindKthValue (T *values, kkint32 arraySize, kkint32 Kth)
 
bool k_ThinningCheckTransitions (uchar m_Matrix22[][3])
 
bool k_ThinningStep1cdTests (uchar m_Matrix22[][3])
 
bool k_ThinningStep2cdTests (uchar m_Matrix22[][3])
 
kkint32 Max6 (kkint32 x1, kkint32 x2, kkint32 x3, kkint32 x4, kkint32 x5, kkint32 x6)
 
kkint32 Max9 (kkint32 x1, kkint32 x2, kkint32 x3, kkint32 x4, kkint32 x5, kkint32 x6, kkint32 x7, kkint32 x8, kkint32 x9)
 
uchar MergeAlpfaBeta (float alpha, uchar alphaPixel, float beta, uchar betaPixel)
 
kkint32 Min (kkint32 x1, kkint32 x2)
 

Variables

kkint32 freqHist16BucketIdx [256]
 
kkint32 freqHistBucketIdx [256]
 
const MovDir movements [8]
 

Function Documentation

float DeltaAngle ( float  ang1,
float  ang2 
)

Returns the difference between two angles in degrees.

Given two angles, will determine the angular distance between them, going from the ang1 to ang2. A positive delta indicates that ang2 is in front of ang1, negative means it is behind ang1. The result can be from -180 to +180 degrees.

Definition at line 5328 of file Raster.cpp.

5331 {
5332  float deltaAng = ang2 - ang1;
5333 
5334  while (deltaAng > 180.0)
5335  deltaAng = deltaAng - (float)360.0;
5336 
5337  if (deltaAng < -180.0)
5338  deltaAng = deltaAng + (float)360;
5339 
5340  return deltaAng;
5341 } /* DeltaAngle */
template<typename T >
T FindKthValue ( T *  values,
kkint32  arraySize,
kkint32  Kth 
)

Definition at line 7175 of file Raster.cpp.

7179 {
7180  T pv;
7181  kkint32 left = 0;
7182  kkint32 right = arraySize - 1;
7183 
7184 
7185  kkint32 pivotIndex = right;
7186 
7187  kkint32 partitionIndex = -1;
7188 
7189  T temp;
7190 
7191  while (partitionIndex != Kth)
7192  {
7193  pv = values[pivotIndex];
7194 
7195  partitionIndex = left;
7196  for (kkint32 i = left; i < right; i++)
7197  {
7198  if (values[i] <= pv)
7199  {
7200  if (i != partitionIndex)
7201  {
7202  temp = values[i];
7203  values[i] = values[partitionIndex];
7204  values[partitionIndex] = temp;
7205  }
7206  partitionIndex = partitionIndex + 1;
7207  }
7208  }
7209 
7210  temp = values[partitionIndex];
7211  values[partitionIndex] = values[right];
7212  values[right] = temp;
7213 
7214  if (Kth < partitionIndex)
7215  right = partitionIndex - 1;
7216  else
7217  left = partitionIndex + 1;
7218 
7219  pivotIndex = right;
7220  }
7221 
7222  return values[Kth];
7223 } /* FindKthValue */
__int32 kkint32
Definition: KKBaseTypes.h:88
bool k_ThinningCheckTransitions ( uchar  m_Matrix22[][3])

Definition at line 8520 of file Raster.cpp.

Referenced by KKB::Raster::ThinContour().

8521 {
8522  kkint32 iTransitions=0;
8523 
8524  if ((m_Matrix22[0][0]==1) && (m_Matrix22[1][0]==0)){
8525  ++iTransitions;}
8526 
8527  if ((m_Matrix22[1][0]==1) && (m_Matrix22[2][0]==0)){
8528  ++iTransitions;}
8529 
8530  if ((m_Matrix22[2][0]==1) && (m_Matrix22[2][1]==0)){
8531  ++iTransitions;}
8532 
8533  if ((m_Matrix22[2][1]==1) && (m_Matrix22[2][2]==0)){
8534  ++iTransitions;}
8535 
8536  if ((m_Matrix22[2][2]==1) && (m_Matrix22[1][2]==0)){
8537  ++iTransitions;}
8538 
8539  if ((m_Matrix22[1][2]==1) && (m_Matrix22[0][2]==0)){
8540  ++iTransitions;}
8541 
8542  if ((m_Matrix22[0][2]==1) && (m_Matrix22[0][1]==0)){
8543  ++iTransitions;}
8544 
8545  if ((m_Matrix22[0][1]==1) && (m_Matrix22[0][0]==0)){
8546  ++iTransitions;}
8547 
8548  if (iTransitions==1)
8549  return true;
8550  else
8551  return false;
8552 } /* k_ThinningCheckTransitions */
__int32 kkint32
Definition: KKBaseTypes.h:88
bool k_ThinningStep1cdTests ( uchar  m_Matrix22[][3])

Definition at line 8507 of file Raster.cpp.

Referenced by KKB::Raster::ThinContour().

8508 {
8509  if ((m_Matrix22[1][0] + m_Matrix22[2][1] + m_Matrix22[1][2]) &&
8510  (m_Matrix22[2][1] + m_Matrix22[1][2] + m_Matrix22[0][1])
8511  )
8512  return true;
8513  else
8514  return false;
8515 }
bool k_ThinningStep2cdTests ( uchar  m_Matrix22[][3])

Definition at line 8493 of file Raster.cpp.

Referenced by KKB::Raster::ThinContour().

8494 {
8495  if ((m_Matrix22[1][0] + m_Matrix22[2][1] + m_Matrix22[0][1]) &&
8496  (m_Matrix22[1][0] + m_Matrix22[1][2] + m_Matrix22[0][1])
8497  )
8498  return true;
8499  else
8500  return false;
8501 }
kkint32 Max6 ( kkint32  x1,
kkint32  x2,
kkint32  x3,
kkint32  x4,
kkint32  x5,
kkint32  x6 
)
inline

Definition at line 240 of file Raster.cpp.

243 {
244  kkint32 r;
245 
246  if (x1 > x2)
247  r = x1;
248  else
249  r = x2;
250 
251  if (x3 > r) r = x3;
252  if (x4 > r) r = x4;
253  if (x5 > r) r = x5;
254  if (x6 > r) r = x6;
255 
256  return r;
257 } /* Max6 */
__int32 kkint32
Definition: KKBaseTypes.h:88
kkint32 Max9 ( kkint32  x1,
kkint32  x2,
kkint32  x3,
kkint32  x4,
kkint32  x5,
kkint32  x6,
kkint32  x7,
kkint32  x8,
kkint32  x9 
)
inline

Definition at line 262 of file Raster.cpp.

266 {
267  kkint32 r;
268 
269  if (x1 > x2)
270  r = x1;
271  else
272  r = x2;
273 
274  if (x3 > r) r = x3;
275  if (x4 > r) r = x4;
276  if (x5 > r) r = x5;
277  if (x6 > r) r = x6;
278  if (x7 > r) r = x7;
279  if (x8 > r) r = x8;
280  if (x9 > r) r = x9;
281 
282  return r;
283 } /* Max9 */
__int32 kkint32
Definition: KKBaseTypes.h:88
uchar MergeAlpfaBeta ( float  alpha,
uchar  alphaPixel,
float  beta,
uchar  betaPixel 
)

Definition at line 6419 of file Raster.cpp.

Referenced by KKB::Raster::DrawLine().

6424 {
6425  int newPixelValue = (int)(0.5f + alpha * (float)alphaPixel + beta * (float)betaPixel);
6426  if (newPixelValue > 255)
6427  newPixelValue = 255;
6428  return (uchar)newPixelValue;
6429 }
unsigned char uchar
Unsigned character.
Definition: KKBaseTypes.h:77
kkint32 Min ( kkint32  x1,
kkint32  x2 
)
inline

Definition at line 229 of file Raster.cpp.

230 {
231  if (x1 < x2)
232  return x1;
233  else
234  return x2;
235 }

Variable Documentation

kkint32 freqHist16BucketIdx[256]
Initial value:
=
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15
}

Definition at line 215 of file Raster.cpp.

Referenced by KKB::Raster::CalcAreaAndIntensityFeatures16().

kkint32 freqHistBucketIdx[256]
Initial value:
=
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7
}

Definition at line 204 of file Raster.cpp.

Referenced by KKB::Raster::CalcAreaAndIntensityFeatures(), KKB::Raster::CalcAreaAndIntensityHistogram(), and KKB::Raster::CalcAreaAndIntensityHistogramWhite().

const MovDir movements[8]
Initial value:
= {{-1, 0},
{-1, 1},
{ 0, 1},
{ 1, 1},
{ 1, 0},
{ 1, -1},
{ 0, -1},
{-1, -1}
}

Definition at line 5346 of file Raster.cpp.

Referenced by KKB::Raster::FollowContour().