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.

enter image description here enter image description here enter image description here

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:

enter image description here


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.

enter image description here

  • 1
    $\begingroup$ 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. $\endgroup$
    – Dan Hulme
    Dec 5, 2017 at 10:02
  • $\begingroup$ It was normal loop first. It is changed just for speed. The results are identical. $\endgroup$
    – ali
    Dec 5, 2017 at 10:36
  • 2
    $\begingroup$ 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. $\endgroup$
    – Alan Wolfe
    Dec 5, 2017 at 23:40
  • 2
    $\begingroup$ " 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? $\endgroup$
    – Simon F
    Dec 6, 2017 at 10:03
  • 1
    $\begingroup$ 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/… ? $\endgroup$
    – Simon F
    Dec 7, 2017 at 16:55


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.