Spatial Resolution (down sampling and up sampling) in image processing (original) (raw)

Last Updated : 8 Jan, 2026

A digital image is a two-dimensional array of size M × N, where M is the number of rows and N is the number of columns. Each element in this array is called a pixel, represented by coordinates (x,y) and intensity value f(x,y).

Spatial Resolution

The term spatial resolution corresponds to the total number of pixels in the given image. If the number of pixels is more, then the resolution of the image is more.

Down-sampling

In the down-sampling technique, the number of pixels in the given image is reduced depending on the sampling frequency. Due to this, the resolution and size of the image decrease.

Up-sampling

The number of pixels in the down-sampled image can be increased by using up-sampling interpolation techniques. The up-sampling technique increases the resolution as well as the size of the image.

Some commonly used up-sampling techniques are

Upsampling is performed using Nearest Neighbor interpolation by replicating rows and columns, which may introduce artifacts at higher sampling rates. Bilinear or Cubic interpolation gives better quality. Both downsampling and upsampling are shown in grayscale to avoid color distortions.

The below program depicts the down sampled and up sampled representation of a given image:

Python `

import cv2 import matplotlib.pyplot as plt import numpy as np

img1 = cv2.imread('gfg (1).png', 0) m, n = img1.shape print('Image Shape:', m, n)

print('Original Image:') plt.imshow(img1, cmap="gray") plt.title("Original Image") plt.show()

f = 4 img2 = np.zeros((m//f, n//f), dtype=int) for i in range(0, m, f): for j in range(0, n, f): try: img2[i//f][j//f] = img1[i][j] except IndexError: pass

print('Down Sampled Image:') plt.imshow(img2, cmap="gray") plt.title("Down Sampled Image") plt.show()

img3 = np.zeros((m, n), dtype=int)

for i in range(0, m-1, f): for j in range(0, n-1, f): img3[i, j] = img2[i//f][j//f]

for i in range(1, m-(f-1), f): for j in range(0, n-(f-1)): img3[i:i+(f-1), j] = img3[i-1, j]

for i in range(0, m-1): for j in range(1, n-1, f): img3[i, j:j+(f-1)] = img3[i, j-1]

print('Up Sampled Image:') plt.imshow(img3, cmap="gray") plt.title("Up Sampled Image") plt.show()

`

**Input:

**Output:

o_image

Original Image

d_image

Down Sampled Image

u_image

Up Sampled Image

**Explanation:

Downsampling

Upsampling (Nearest Neighbor)