I recently learnt bilinear interpolation, according to the description in Wiki, I feel that bilinear interpolation can only be used in integer-factored enlarging, for example, given 4x4 resolution image, by bilinear interpolation, it can only enlarged to 8x8, 12x12, 16x16... and so on, but it can't be enlarged to 9x9, 13x13... just because the number like 9 or 13 cannot be divided by 4, is that right? if not right, how can it be enlarged to n times, where n is not integer, by bilinear interpolation?
NO that is not right. You can resize from any positive resolution to any other. So let assume source image is xs0,ys0
and destination is xs1,ys1
resolution.
process all pixels of target image
so 2 nested for loops through x1,y1
covering xs1,ys1
for each pixel compute floating position in source image
x0 = x1*(xs0-1)/(xs1-1)
y0 = y1*(ys0-1)/(ys1-1)
bi-linearly interpolate from 4 neighbors
integer part of x0,y0
points to start point and fractional parts are your interpolation parameters tx,ty
... so interpolate pixel between source (x0,y0),(x0+1,y0),(x0,y0+1),(x0+1,y0+1)
and store the result in destination image at (x1,y1)
. Handle the edge pixels (x0==xs0-1 , y0==ys0-1
) differently to avoid access violations.