Your t=0.5 is not right, the value of t depends on the source size, dest size, and the current dest pixel, so most definitely you shouldn't hard code it to 0.5.
I'll post some code that works a little later if you can't figure it out, don't have time now.
bicubic interpolation on image enlargements
0.5f would actually be the same as bilinear interpolation
i could find anything about the correct blend factors :(
i have search on google for hours and couldn t find any decent article that doesn t only give your the formula
the only think i found was the b spline approach which works but delivers too smooth results
thx in advance
i could find anything about the correct blend factors :(
i have search on google for hours and couldn t find any decent article that doesn t only give your the formula
the only think i found was the b spline approach which works but delivers too smooth results
thx in advance
Alright, here goes
[Edited by - outRider on August 8, 2005 11:43:19 AM]
// x,y coords for pixels in old and new imagesfloat ox,oy;int nx,ny;// temppixel t[4];dx = oldwidth / newwidth;dy = oldheight / newheight;for (ny = 0; ny < newheight; ++ny){ oy = ny * dy; for (nx = 0; nx < newwidth; ++nx) { ox = nx * dx; // ox.frac, oy.frac represent fractional portions of ox,oy // i.e. for ox=4.15, ox.frac=0.15 // oimg, nimg are image buffers t[0] = interpolate(oimg[ox - 1,oy - 1], oimg[ox,oy - 1], oimg[ox + 1,oy - 1], oimg[ox + 2,oy - 1], ox.frac); t[1] = interpolate(oimg[ox - 1,oy], oimg[ox,oy], oimg[ox + 1,oy], oimg[ox + 2,oy], ox.frac); t[2] = interpolate(oimg[ox - 1,oy + 1], oimg[ox,oy + 1], oimg[ox + 1,oy + 1], oimg[ox + 2,oy + 1], ox.frac); t[3] = interpolate(oimg[ox - 1,oy + 2], oimg[ox,oy + 2], oimg[ox + 1,oy + 2], oimg[ox + 2,oy + 2], ox.frac); nimg[nx,ny] = interpolate(t[0],t[1],t[2],[3], oy.frac); [Edit]// Sorry, should have been interpolate() not cubic(), in case anyone else is looking at this. }}pixel interpolate(pixel a,b,c,d, t){ return pixel( cubic(a.r, b.r, c.r, d.r, t), cubic(a.g, b.g, c.g, d.g, t), cubic(a.b, b.b, c.b, d.b, t), );}cubic(v0,v1,v2,v3, t){ int p = (v3 - v2) - (v0 - v1); int q = (v0 - v1) - p; int r = v2 - v0; int s = v1; float tSqrd = t * t; return (p * (tSqrd * t)) + (q * tSqrd) + (r * t) + s;}
[Edited by - outRider on August 8, 2005 11:43:19 AM]
thx it works now
I searched on google for some information on cubic interpolation and especially the weight factors and there s absolutely no useful information maybe one should write a little tutorial about it
this is when I swap the interpolation factors, e.g.: xfrac for y axis
it uses SI (stepping interpolation) size*2 per step
after the cubic filter I applied 4 smooths to get this result
here are the results
1. my cubic filter
2. photoshop's cubic filter
without swapping it get results a little bit sharper then photoshop's
I searched on google for some information on cubic interpolation and especially the weight factors and there s absolutely no useful information maybe one should write a little tutorial about it
this is when I swap the interpolation factors, e.g.: xfrac for y axis
it uses SI (stepping interpolation) size*2 per step
after the cubic filter I applied 4 smooths to get this result
here are the results
1. my cubic filter
2. photoshop's cubic filter
without swapping it get results a little bit sharper then photoshop's
Using xfrac on the y-axis and vice versa will give you incorrect results, your result looks a little stretched to me, but if that's what you prefer it won't matter as much for something like a greyscale heightmap, but for enlarging images I think it won't look good at all.
And if you use something like what I posted you don't need to size by stepping, you can directly go from 32,32 to 256,256. It should be much faster.
And if you use something like what I posted you don't need to size by stepping, you can directly go from 32,32 to 256,256. It should be much faster.
yeah right it looks a little bit streched, the next thing ill do is blend it with several octaves as descriped in the simple clouds tutorial this should result in a decent heightmap for terrains and with exponential filter i can use it for clouds
The quoted code for "cubic" cannot be correct. cubic(255,255,255,85,0.811) = 276
no way can a correct interpolated result be greater than any of the inputs.
no way can a correct interpolated result be greater than any of the inputs.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement