92 if (width != this->width || height != this->height)
116 const Vec2d newCoordinates = { float(j), float(i) };
119 Vec2d originalCoordinates;
122 const float u = originalCoordinates.
x;
123 const float v = originalCoordinates.
y;
128 if (u_int >= 0 && u_int < width - 1 && v_int >= 0 && v_int < height - 1)
134 const int u1 = int(floor(u));
135 const int v1 = int(floor(v));
136 const float x = u -
u1;
137 const float y = v -
v1;
139 const float f00 = (1 -
x) * (1 - y);
140 const float f10 = x * (1 -
y);
141 const float f01 = (1 -
x) * y;
142 const float f11 = x *
y;
144 const float sum = f00 + f10 + f01 + f11;
175 printf(
"error: map has not been computed yet. call CImageMapper::ComputeMap\n");
179 if (pInputImage->
type != pOutputImage->
type)
181 printf(
"error: input and output image must be of same type for CImageMapper::PerformMapping\n");
187 printf(
"error: input image does not match calibration file for CImageMapper::PerformMapping\n");
193 printf(
"error: output image does not match calibration file for CImageMapper::PerformMapping\n");
200 pSaveOutputImage = pOutputImage;
205 unsigned char *output = pOutputImage->
pixels;
211 const unsigned char g = input[0];
216 for (
int i = 0; i < nPixels; i++)
220 output[i] = (
unsigned char) ((input[input_offset] * m.
f00 + input[input_offset +
width] * m.
f01 + input[input_offset + 1] * m.
f10 + input[input_offset +
width + 1] * m.
f11 + 2097152) >> 22);
225 for (
int i = 0; i < nPixels; i++)
233 const unsigned char r = input[0];
234 const unsigned char g = input[1];
235 const unsigned char b = input[2];
236 input[0] = input[1] = input[2] = 0;
240 for (
int i = 0, output_offset = 0; i < nPixels; i++, output_offset += 3)
243 const int width3 = 3 *
width;
247 output[output_offset] = (
unsigned char) ((input[input_offset] * m.
f00 + input[input_offset + width3] * m.
f01 + input[input_offset + 3] * m.
f10 + input[input_offset + width3 + 3] * m.
f11 + 2097152) >> 22);
248 output[output_offset + 1] = (
unsigned char) ((input[input_offset + 1] * m.
f00 + input[input_offset + width3 + 1] * m.
f01 + input[input_offset + 4] * m.
f10 + input[input_offset + width3 + 4] * m.
f11 + 2097152) >> 22);
249 output[output_offset + 2] = (
unsigned char) ((input[input_offset + 2] * m.
f00 + input[input_offset + width3 + 2] * m.
f01 + input[input_offset + 5] * m.
f10 + input[input_offset + width3 + 5] * m.
f11 + 2097152) >> 22);
254 for (
int i = 0, output_offset = 0; i < nPixels; i++, output_offset += 3)
257 output[output_offset] = input[input_offset];
258 output[output_offset + 1] = input[input_offset + 1];
259 output[output_offset + 2] = input[input_offset + 2];
268 if (pSaveOutputImage)
void ComputeMap(int width, int height)
This method initializes the instance for mapping of images of a specific size.
CImageMapper(bool bInterpolate=true)
The only constructor of this class.
MapCoordinates * m_pCoordinateMap
int width
The width of the image in pixels.
Data structure for the representation of 8-bit grayscale images and 24-bit RGB (or HSV) color images ...
unsigned char * pixels
The pointer to the the pixels.
virtual ~CImageMapper()
The destructor.
virtual void ComputeOriginalCoordinates(const Vec2d &newCoordinates, Vec2d &originalCoordinates)=0
bool CopyImage(const CByteImage *pInputImage, CByteImage *pOutputImage, const MyRegion *pROI=0, bool bUseSameSize=false)
Copies one CByteImage to another.
int height
The height of the image in pixels.
void PerformMapping(const CByteImage *pInputImage, CByteImage *pOutputImage)
This method performs the mapping.
GLenum GLsizei GLsizei height
GLenum GLenum GLenum input
ImageType type
The type of the image.
GLdouble GLdouble GLdouble r
Data structure for the representation of a 2D vector.