<p>I am trying to apply sinc interpolation on <a href="https://drive.google.com/file/d/0BwxvtmE7yeVKSUlnbWxUbC1VdGM/view?usp=sharing" rel="nofollow noreferrer">this data set</a>. 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.</p>

<p><a href="https://i.sstatic.net/rwfs3.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/rwfs3.png" alt="enter image description here"></a>
<a href="https://i.sstatic.net/uJ7Zv.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/uJ7Zv.png" alt="enter image description here"></a>
<a href="https://i.sstatic.net/SuYWb.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/SuYWb.png" alt="enter image description here"></a></p>

<p>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.</p>

<p>Here is the sinc interpolation method</p>

<pre><code>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 &lt; N; x++)
    {
        for (int y = 0; y &lt; M; y++)
        {
            LightVector sum = LightVector.ZERO;
            double sincSum = 0;
            for (int n = 0; n &lt; fs.Width; n++)//= (int)Ts
            {
                for (int m = 0; m &lt; 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 &gt; 255 || c.Y &gt; 255 || c.Z &gt; 255)
                c = c.Clamp(0, 255);
            fy.SetPixel(x, y, c);
        }
    }
    return fy;
}
</code></pre>

<p>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.</p>

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

<p><a href="https://i.sstatic.net/LiFLH.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/LiFLH.png" alt="enter image description here"></a></p>

<p><strong>UPDATE:</strong></p>

<p>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. </p>

<p><a href="https://i.sstatic.net/aZrhE.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/aZrhE.png" alt="enter image description here"></a></p>

CC BY-SA 3.0
2017-12-05T10:02:41.213Z
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
CC BY-SA 3.0
2017-12-05T10:36:34.413Z
It was normal loop first. It is changed just for speed. The results are identical.
ali
CC BY-SA 3.0
2017-12-05T23:40:20.683Z
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
CC BY-SA 3.0
2017-12-06T10:03:25.923Z
" 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
CC BY-SA 3.0
2017-12-07T10:03:19.497Z
The sinc method wasn't normalised. I modified the code and the image looks more like it but it is very blurry. Is this expected? I have updated the question with the new code and image.
ali
CC BY-SA 3.0
2017-12-07T10:03:45.343Z
The colour wasn't clamped between 0-255 too. Thanks.
ali
CC BY-SA 3.0
2017-12-07T16:55:26.927Z
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 https://www.cs.utexas.edu/~fussell/courses/cs384g-fall2013/lectures/mitchell/Mitchell.pdf ?
Simon F
<image-processing><interpolation>
Sinc interpolation and Ideal reconstruction example
ali
# Sinc interpolation and Ideal reconstruction example

(Asked by: username_0 on 2017-12-05)

I am trying to apply sinc interpolation on [this data set](https://drive.google.com/file/d/0BwxvtmE7yeVKSUlnbWxUbC1VdGM/view?usp=sharing). 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](https://i.sstatic.net/rwfs3.png)](https://i.sstatic.net/rwfs3.png)
[![enter image description here](https://i.sstatic.net/uJ7Zv.png)](https://i.sstatic.net/uJ7Zv.png)
[![enter image description here](https://i.sstatic.net/SuYWb.png)](https://i.sstatic.net/SuYWb.png)

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](https://i.sstatic.net/LiFLH.png)](https://i.sstatic.net/LiFLH.png)

**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.

[![enter image description here](https://i.sstatic.net/aZrhE.png)](https://i.sstatic.net/aZrhE.png)

**Tags:** image-processing, interpolation

> **Comments:**
> **username_1**: 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.  
> **username_0**: It was normal loop first. It is changed just for speed. The results are identical.  
> **username_2**: 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.  
> **username_3**: " 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?  
> **username_0**: The sinc method wasn't normalised. I modified the code and the image looks more like it but it is very blurry. Is this expected? I have updated the question with the new code and image.  
> **username_0**: The colour wasn't clamped between 0-255 too. Thanks.  
> **username_3**: 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 https://www.cs.utexas.edu/~fussell/courses/cs384g-fall2013/lectures/mitchell/Mitchell.pdf ?  

---

## 0 answers

