KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
colorconv.h
Go to the documentation of this file.
1 // colorconv2.h -- Doron Tal
3 
4 #ifndef _COLORCONV2_H
5 #define _COLORCONV2_H
6 
8 //Added by Prasad
9 //To allow for float precision for image pixels
10 //NOTE***********Make sure the following is undefined when using any
11 //of the following functions:
12 //BGR2Gray, BGR2L, BGR2LAB
13 //because they assume char precision for image pixels***************
14 #define ENABLE_FLOAT_PRECISION
15 
17 // #include "ncuts.h"
18 
19 // Get grayscale from RGB, returns grayscale Value. Both the commented out
20 // '#define' below and the non-commented out macros give the same value, but
21 // the uncommented macro should be faster on most architectures.
22 // #define RGB2GRAY(R, G, B) ((BYTE)(0.15625f*(2.2f*R+3.2f*G+B)))
23 
24 #define RGB2GRAY(R, G, B) \
25  ((unsigned char)((5120L*(long)B+(((long)G)<<14)+11264L*(long)R)>>15))
26 
27 // default gamma value by which we assume the image has been corrected
28 // make sure this is float
29 #define DEFAULT_GAMMA 2.2f
30 
31 // point considered white in RGB space, Kodak uses (200,200,200), which
32 // would translate to putting 200.0f here. NOTE: this must be a float
33 // number.
34 #define RGB_WHITE_PT 255.0f
35 
36 // the nonlinear CIE-XYZ to LAB function
37 #define LAB_F(x) ((x > 0.008856f) ? (float)pow(x, 1.0/3.0) : \
38  7.787f*x+16.0f/116.0f)
39 
40 // the xyz transformation matrix
41 
42 // X (0), as a linear function of R, G & B (0,1 & 2)
43 #define XYZ_00 0.4124f
44 #define XYZ_01 0.3576f
45 #define XYZ_02 0.1805f
46 // Y (1), as a linear function of R, G & B (0,1 & 2)
47 #define XYZ_10 0.2126f
48 #define XYZ_11 0.7152f
49 #define XYZ_12 0.0722f
50 // Z (2), as a linear function of R, G & B (0,1 & 2)
51 #define XYZ_20 0.0193f
52 #define XYZ_21 0.1192f
53 #define XYZ_22 0.9505f
54 
56 
57 namespace DTLib {
58 
60  // can be done in-place
61  void BGR2Gray(unsigned char* pInBuf, unsigned char* pOutBuf,
62  const int& Width, const int& Height);
63 
65 
66  /*void BGR2LAB(unsigned char* pInBuf, float* pOutBuf,
67  const int& Width, const int& Height,
68  const float& Gamma = DEFAULT_GAMMA);*/
69 
70  void BGR2LAB(float* pInBuf, float* pOutBuf,
71  const int& Width, const int& Height,
72  const float& Gamma = DEFAULT_GAMMA);
73 
74  void BGR2L(unsigned char* pInBuf, float* pOutBuf,
75  const int& Width, const int& Height,
76  const float& Gamma = DEFAULT_GAMMA);
77 
78 //Added by Prasad
79 //Color conversion from RGB to Srg
81 //Added by Prasad
82 //To allow for float precision for image pixels
83 
84 #ifdef ENABLE_FLOAT_PRECISION
85  void BGR2Srg(float* pInBuf, float* pOutBuf,
86  const int& Width, const int& Height);
87 #else
88  void BGR2Srg(unsigned char* pInBuf, float* pOutBuf,
89  const int& Width, const int& Height);
90 #endif
91  // Change the channel ordering from pixel to planar, i.e.
94  // if the original image is, for example, one big buffer of
95  // BGR, BGR,... fill up three buffers B, G and R
96  template <class T>
97  inline void Interleaved2Planar(T* pIn, T* pOut1, T* pOut2, T* pOut3,
98  const int& Width, const int& Height) {
99  T *pI = pIn, *pO1 = pOut1, *pO2 = pOut2, *pO3 = pOut3;
100  for (int y = 0; y < Height; y++) {
101  for (int x = 0; x < Width; x++) {
102  *pO1++ = *pI++; *pO2++ = *pI++; *pO3++ = *pI++;
103  }
104  }
105  };
106 
107 } // namespace DTLib
108 
109 #endif /* #ifndef _COLORCONV2_H */
void BGR2Srg(float *pInBuf, float *pOutBuf, const int &Width, const int &Height)
Definition: colorconv.cpp:149
void BGR2LAB(float *pInBuf, float *pOutBuf, const int &Width, const int &Height, const float &Gamma=DEFAULT_GAMMA)
Definition: colorconv.cpp:46
x
Definition: APPgetLargeConnectedEdges.m:100
void BGR2Gray(unsigned char *pInBuf, unsigned char *pOutBuf, const int &Width, const int &Height)
Definition: colorconv.cpp:30
void Interleaved2Planar(T *pIn, T *pOut1, T *pOut2, T *pOut3, const int &Width, const int &Height)
Definition: colorconv.h:97
#define DEFAULT_GAMMA
Definition: colorconv.h:29
void BGR2L(unsigned char *pInBuf, float *pOutBuf, const int &Width, const int &Height, const float &Gamma=DEFAULT_GAMMA)
Definition: colorconv.cpp:101