# Sinc interpolation and Ideal reconstruction example

I am trying to apply sinc interpolation on this data set. The patches in the left image is a snapshot of AutoCAD 3d faces. Lux values are calculated for centre of each patch that are in 0.3m x 0.3m dimension.

The middle is a bitmap image of the above data set. Applying below sinc interpolation method results in the right side image. I was expecting to get smooth gradient in the colours but am not sure if the sinc function is applied correctly.

Here is the sinc interpolation method

public ImageFilm ConvolveWithSinc(ImageFilm fs, float Ts)
{
float Ws = 1 / Ts;
int N = fs.Width;
int M = fs.Height;
ImageFilm fy = new ImageFilm(N, M);
Vector zero = Vector.ZERO;
for (int x = 0; x < N; x++)
{
for (int y = 0; y < M; y++)
{
LightVector sum = LightVector.ZERO;
double sincSum = 0;
for (int n = 0; n < fs.Width; n++)//= (int)Ts
{
for (int m = 0; m < fs.Height; m++)//= (int)Ts
{
double sinc = (Helper.Sinc(Ws * (x - n)) *
Helper.Sinc(Ws * (y - m)));

sincSum += sinc;

LightVector v = fs.GetPixel(n, m);
if (v == zero) continue;

sum += v * sinc;
}
}
LightVector c = sum / sincSum;
if (c.X > 255 || c.Y > 255 || c.Z > 255)
c = c.Clamp(0, 255);
fy.SetPixel(x, y, c);
}
}
return fy;
}


I understand that the sampling frequency on the above middle image might be below the Nyquist frequency but I wanted to know if this is the case or I am doing something wrong.

I have tried the above method on a simpler function sin(16*x*x) and the interpolated image looks similar to the original:

UPDATE:

Thanks for the comments. I have modified the code to divide the pixel value by the sum of the two sinc functions. Is this the correct way of normilizing it? The image looks better but it is very blurry.

• As a first debugging step, you should replace the Parallel.for with a normal loop, to make sure a concurrency problem isn't the source of your error. – Dan Hulme Dec 5 '17 at 10:02
• It was normal loop first. It is changed just for speed. The results are identical. – ali Dec 5 '17 at 10:36
• I wonder if your colors are clipping? They may be going above 1.0 or below 0.0. Might be worth checking out as part of debugging. It could be that things are smooth in at least part of the image, but that they are out of range. – Alan Wolfe Dec 5 '17 at 23:40
• " It is changed just for speed." If you want speed, why don't you do it as a separable filter, e.g. do Y operations first into an intermediate buffer and then do the X? Also, since you aren't doing a true integral, are you normalising your sinc filter taps? i.e. does Sum(Helper.Sinc(Ws * (x - n))) over all n == 1? – Simon F Dec 6 '17 at 10:03
• Yes the normalisation looks about right..though you probably don't need to repeatedly compute the sum of the weights as, in your test, they shouldn't be changing from pixel to pixel. Having said all this, I'm not sure sinc is the right choice for graphics. Can I suggest you try looking at Mitchell & Netravali's cs.utexas.edu/~fussell/courses/cs384g-fall2013/lectures/… ? – Simon F Dec 7 '17 at 16:55