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.
Parallel.for
with a normal loop, to make sure a concurrency problem isn't the source of your error. – Dan Hulme Dec 05 '17 at 10:02Also, 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 06 '17 at 10:03Having 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 Dec 07 '17 at 16:55