Digital Image Processing with
Interpolation
1) Goal of the project
Implement image resizing (upsampling or downsampling) using numerical
interpolation methods:
Bilinear interpolation
Bicubic interpolation
Compare your resized images with MATLAB’s built-in imresize function.
Explore the effect of interpolation on image quality (sharpness, smoothness,
aliasing).
2) Why interpolation is needed in image
resizing
When resizing an image, especially enlarging, new pixel locations don’t coincide
with original pixels. To assign color/gray values to these new positions, you need
numerical interpolation.
Nearest-neighbor: simplest, just take the closest pixel (fast but blocky).
Bilinear: uses 2D linear interpolation with 4 neighboring pixels.
Bicubic: uses cubic polynomials, considers 16 neighboring pixels, smoother
output.
3) Mathematical formulation
A) Bilinear interpolation
Suppose you want to find the intensity at a non-integer pixel location (x,y)(x, y). Let
the surrounding four pixels be:
(x1,y1),(x1+1,y1),(x1,y1+1),(x1+1,y1+1)(x_1,y_1), (x_1+1,y_1),
(x_1,y_1+1), (x_1+1,y_1+1)
If I(i,j)I(i,j) is the pixel intensity:
f(x,y)≈(1−a)(1−b)I(x1,y1)+a(1−b)I(x1+1,y1)+(1−a)bI(x1,y1+1)+abI(x1+
1,y1+1)f(x,y) \approx (1-a)(1-b) I(x_1,y_1) + a(1-b) I(x_1+1,y_1) +
(1-a)b I(x_1,y_1+1) + a b I(x_1+1,y_1+1)
where
a=x−x1,b=y−y1a = x - x_1, \quad b = y - y_1
B) Bicubic interpolation
Uses cubic polynomial along each axis.
Considers 16 neighbors: 4×4 grid around target pixel.
Cubic kernel (Catmull-Rom or Keys cubic) is applied separately along x and y
axes:
f(x)=∑i=−12wi(u)⋅ I(xi)f(x) = \sum_{i=-1}^{2} w_i(u) \cdot I(x_i)
where uu is fractional distance from pixel, wi(u)w_i(u) is cubic weight.
Smoother than bilinear, reduces blockiness and stair-step artifacts.
4) Resizing algorithm
Step 1: Compute target size
Given original image of size H×WH \times W
Desired new size H′×W′H' \times W'
Compute scaling factors:
Sx=W/W′,Sy=H/H′S_x = W / W', \quad S_y = H / H'
Step 2: Map new pixel locations to old image coordinates
For each pixel (i′,j′)(i',j') in the resized image:
x=(j′−0.5)⋅ Sx+0.5,y=(i′−0.5)⋅ Sy+0.5x = (j'-0.5) \cdot S_x + 0.5,
\quad y = (i'-0.5) \cdot S_y + 0.5
(x,y) are floating-point coordinates in original image.
Step 3: Apply interpolation
For bilinear:
Identify the four surrounding pixels
Compute weights based on fractional distances
Assign interpolated intensity
For bicubic:
Identify 4×4 surrounding pixels
Apply cubic kernel along x and y axes
Assign interpolated intensity
Step 4: Repeat for all pixels in the resized image
For RGB images: apply separately for each color channel (R, G, B)
5) MATLAB Implementation Outline
A) Bilinear Interpolation
function I_resized = bilinear_resize(I, new_H, new_W)
[H, W, C] = size(I);
I_resized = zeros(new_H, new_W, C);
Sx = W / new_W;
Sy = H / new_H;
for c = 1:C
for i = 1:new_H
for j = 1:new_W
x = (j-0.5)*Sx + 0.5;
y = (i-0.5)*Sy + 0.5;
x1 = floor(x); x2 = min(x1+1, W);
y1 = floor(y); y2 = min(y1+1, H);
a = x - x1; b = y - y1;
I11 = I(y1,x1,c); I21 = I(y1,x2,c);
I12 = I(y2,x1,c); I22 = I(y2,x2,c);
I_resized(i,j,c) = (1-a)*(1-b)*I11 + a*(1-b)*I21 + (1-
a)*b*I12 + a*b*I22;
end
end
end
I_resized = uint8(I_resized);
end
B) Bicubic Interpolation
Implement cubic kernel function:
function w = cubic_weight(u)
a = -0.5; % Catmull-Rom
u = abs(u);
w = zeros(size(u));
mask1 = (u<=1);
mask2 = (u>1 & u<2);
w(mask1) = (a+2)*u(mask1).^3 - (a+3)*u(mask1).^2 + 1;
w(mask2) = a*u(mask2).^3 - 5*a*u(mask2).^2 + 8*a*u(mask2) - 4*a;
end
Apply along x and y axes for 4×4 neighborhood (more loops than bilinear).
C) Comparison with MATLAB built-in
I_builtin = imresize(I, [new_H, new_W], 'bilinear');
imshowpair(I_resized, I_builtin, 'montage');
title('Custom Bilinear vs MATLAB imresize');
Compute error metrics:
MSE = mean((I_resized(:) - I_builtin(:)).^2)
PSNR = 10*log10(255^2 / MSE)
6) Outputs / Visualization
Resized images (upsampled/downsampled)
Side-by-side comparison with MATLAB imresize
Error maps (optional: show difference image)
Performance metrics:
MSE, PSNR
Runtime for bilinear vs bicubic vs MATLAB built-in
7) Extensions / Challenges
Implement nearest-neighbor, bilinear, bicubic, Lanczos and compare.
Implement antialiasing for downsampling.
Resize grayscale and RGB images.
Resize real photo vs synthetic test patterns to observe
smoothness/blockiness.
Implement as a function + GUI for interactive image resizing.
8) Learning Outcomes
Understand 2D interpolation in numerical analysis
Apply bilinear and bicubic formulas in practice
Observe trade-offs between accuracy and computational cost