15 class __declspec(dllexport) WPImage
19 WPImage (
int width,
int height);
20 WPImage (
int width,
int height,
float* image);
21 WPImage (
int width,
int height,
const float* image);
24 int GetWidth ()
const {
return _width; }
25 int GetHeight ()
const {
return _height; }
27 void GetCharData (
unsigned char* data)
const;
28 void GetShortData (
unsigned short int* data)
const;
30 float GetThresholdCoeff ()
const {
return _thresholdCoeff; }
31 void GetCropIndices (
int &low,
int &high)
const { low = _cropHeightLow; high = _cropHeightHigh; }
33 void SetWidth (
int value) { _width = value; }
34 void SetHeight (
int value) { _height = value; }
35 void SetWidthAndHeight (
int width,
int height) { _width = width; _height = height; }
36 void SetThresholdCoeff (
float value) { _thresholdCoeff = value; }
37 void SetCropIndices (
int low,
int high) { _cropHeightLow = low; _cropHeightHigh = high; }
39 bool TransposeArray (
const float* src,
float* dst,
int inWidth,
int inHeight)
const;
40 bool TransposeArray (
const unsigned short* src,
unsigned short* dst,
int inWidth,
42 bool TransposeArray (
const unsigned char* src,
unsigned char* dst,
int inWidth,
45 static bool ConvertFloatToUnsignedChar (
const float* inData,
unsigned char* outData,
47 static bool ConvertFloatToUnsignedShort (
const float* inData,
unsigned short* outData,
51 static bool TransposeAnyArray (T* src, T* dst,
int inWidth,
int inHeight);
53 static bool TransposeAnyArray (
const T* src, T* dst,
int inWidth,
int inHeight);
56 static bool FlipHorizontal (T* data,
int width,
int height);
58 static bool FlipVertical (T* data,
int width,
int height);
60 static bool Rotate (
const T* dataIn, T* dataOut,
int width,
int height,
61 unsigned int cw90Multiplier);
66 bool SmoothImage (
const std::vector<float>& inData,
int width,
int height,
67 int neighbors, std::vector<float>& outData)
const;
68 bool ThresholdImage (
const std::vector<float>& inData, std::vector<float>& averagedData,
69 float threshold, std::vector<float>& outData)
const;
70 bool TakeLogOfImage (
const std::vector<float>& inData, std::vector<float>& outData)
const;
71 bool CropImageHeight (
const std::vector<float>& inData, std::vector<float>& outData,
72 int topCutoff,
int botCutoff)
const;
74 float GetMinValue ()
const;
75 float GetMaxValue ()
const;
76 float GetMinValue (
const std::vector<float>& image)
const;
77 float GetMaxValue (
const std::vector<float>& image)
const;
79 float GetMeanOfMaxes (
const std::vector<float>& image,
int imageHeight,
80 std::vector<float>& rows)
const;
81 float GetMeanOfContainer (
const std::vector<float>& container)
const;
83 bool ReadFile (
string name, vector<float>& outdata);
84 bool WriteFile (
string name, std::vector<signed char>& outData);
86 virtual bool ThresholdAndScale (
const std::vector<float>& inData,
87 std::vector<float>& outData)
const;
88 virtual bool NormalizeFor8Bit (
const std::vector<float>& intensityData,
89 std::vector<unsigned char>& outData)
const;
91 static float GetMinValue (
const float* data,
int size);
92 static float GetMaxValue (
const float* data,
int size);
94 static bool NormalizeFor8Bit (
const float* inData,
unsigned char* outData,
int size);
95 static bool NormalizeFor16Bit (
const float* inData,
unsigned short int* outData,
int size);
100 int _cropHeightLow, _cropHeightHigh;
101 int _topCutoffHeight;
102 int _botCutoffHeight;
104 float _thresholdCoeff;
105 const float* _floatData;
112 template <
typename T>
113 bool WPImage::FlipHorizontal(T* data,
int width,
int height)
115 if (data ==
nullptr || width <= 0 || height <= 0)
return false;
122 for (
int y = 0; y < height; y++)
124 int rowStart = y * width;
125 for (
int x = 0; x < width / 2; x++)
127 temp = data[rowStart + x];
128 data[rowStart + x] = data[rowStart + width - 1 - x];
129 data[rowStart + width - 1 - x] = temp;
141 template <
typename T>
142 bool WPImage::FlipVertical(T* data,
int width,
int height)
144 if (data ==
nullptr || width <= 0 || height <= 0)
return false;
151 for (
int y = 0; y < height / 2; y++)
153 int rowStartTop = y * width;
154 int rowStartBot = (height - 1 - y) * width;
155 for (
int x = 0; x < width; x++)
157 temp = data[rowStartTop + x];
158 data[rowStartTop + x] = data[rowStartBot + x];
159 data[rowStartBot + x] = temp;
169 template <
typename T>
170 bool WPImage::Rotate(
const T* dataIn, T* dataOut,
int width,
int height,
unsigned int cw90Multiplier)
172 if (dataIn ==
nullptr || dataOut ==
nullptr || width <= 0 || height <= 0)
return false;
180 if (cw90Multiplier == 1)
182 for (
int x = 0; x < width; x++)
184 for (
int y = height - 1; y >= 0; y--)
186 dataOut[i++] = dataIn[y * width + x];
191 else if (cw90Multiplier == 3)
193 for (
int x = 0; x < width; x++)
195 for (
int y = 0; y < height; y++)
197 dataOut[i++] = dataIn[width - 1 - x + y * width];
202 else if (cw90Multiplier == 2)
204 for (
int y = 0; y < height; y++)
206 for (
int x = 0; x < width; x++)
208 dataOut[i++] = dataIn[(height - 1 - y) * width + width - 1 - x];
215 for (
int x = 0; x < width * height; x++)
217 dataOut[x] = dataIn[x];
229 template <
typename T>
230 bool WPImage::TransposeAnyArray(T* src, T* dst,
int inWidth,
int inHeight)
232 if (src ==
nullptr || dst ==
nullptr || inWidth <= 0 || inHeight <= 0)
return false;
238 for (
int i = 0; i < inWidth; i++)
240 startLoc = i * inHeight;
241 for (
int j = 0; j < inHeight ; j++)
243 dst[j * inWidth + i] = src[startLoc + j];
254 template <
typename T>
255 bool WPImage::TransposeAnyArray(
const T* src, T* dst,
int inWidth,
int inHeight)
257 if (src ==
nullptr || dst ==
nullptr || inWidth <= 0 || inHeight <= 0)
return false;
263 for (
int i = 0; i < inWidth; i++)
265 startLoc = i * inHeight;
266 for (
int j = 0; j < inHeight; j++)
268 dst[j * inWidth + i] = src[startLoc + j];