   Image Interpolation
  Hi , I want to interpolate an image , It is in YUV format, I want to interpolate only the Y component,and I have the data for y component in byte memory array.Can anyone give me c++ code to implement bilinear interpolation .Koreno   
  What do you mean by "interpolate an image"?You can only interpolate BETWEEN two (or more) things.So, do you have two images and you want to interpolate the y-component between the two?Or is it something different?   ;http://www.gamedev.net/reference/articles/article810.asp;  The correct term is supersampling, upsampling, oversampling, or even interpolating the image, done by interpolating the pixel (component) values. It can be distinguished between _spatial_ interpolation (e.g. inside the image, what is wanted here) and _temporal_ interpolation (between images of a sequence). However, one could also say temporal interpolation is interpolation in z direction, so this is just a question of definition and nothing special to worry about in this case.Bilinear interpolation is to be done with the 4 original values in the upper-left, upper-right, lower-left, and lower-right "corner" w.r.t. the location of the (to be) interpolated pixel.Assuming x and y denote the location of the interpolated pixel, given as floating point co-ordinates w.r.t. the original image size, so thatx in [ -0.5 , width_of_original_in_pixels-0.5 )and similarlyy in [ -0.5 , height_of_original_in_pixels-0.5 )then you could use something like the following:floatImage::pixelAt(float x,float y) const {// integral parts from co-ordinatesconst int32_t intX = int32_t(x);const int32_t intY = int32_t(y);// presetting result from integral parts as index into mapconst int32_t index = intY * _width + intX;float result = float(_map[index]);// fractional parts from co-ordinatesx -= intX;y -= intY;// index offsets to the right and bottomconst int32_t sideOffset = intX+1 < _width ? 1 : 0;const int32_t downOffset = intY+1 < _height ? _width : 0;// neighboured component valuesfloat side = float(_map[index+sideOffset]);float down = float(_map[index+downOffset]);float diagonal = float(_map[index+downOffset+sideOffset]);// actual bi-linear interpolationresult += (side-result)*x;down += (diagonal-down)*x;result += (down-result)*y;// donereturn result;}Herein _map denotes your original luminance map as a linear array (i.e. all lines consecutively arranged), _width and _height denote the size of the map.Notice that the border problem is handled here by repeating the border pixel!If you want to access the original image by the pixel addresses of the interpolated image, you have the need of co-ordinate conversion. That could be done like herefloatImage::pixelAt(int32_t x,int32_t y,uint32_t sampling) const {const float factor = 0.5f/sampling;return pixelAt(float(x+x)*factor,float(y+y)*factor);}where sampling denotes the sampling factor (e.g. 4 if the supersampled image should show 4 by 4 pixels for each pixel in the original image).Invoke this routine withx in [ 0 , width_of_interpolated_image - 1 ] w/ width_of_interpolated_image = sampling * width_of_original_imageandy in [ 0 , height_of_interpolated_image -1 ]  w/ height_of_interpolated_image = sampling * height_of_original_image[Edited by - haegarr on January 19, 2006 6:48:57 AM]