Image Processing - Image Sampling & Quantization

Concepts

  • Image Processing

    • Improvement of pictorial information for human interpretation

    • Processing of image data for storage, transmission, and representation for autonomous machine perception

    • Digital IP refers to processing of digital images by means of a computer

  • Computer Vision

    • A branch of artificial intelligence
    • Analyse and understand images
    • Comparable to the human vision system, including
      • Learning
      • Being able to make inferences
      • Taking actions based on visual inputs
  • IP vs CV

    There is a continuum from IP at one end to CV at the other. The area Image Analysis is in between IP and CV.

    image-20241007030550578

Image Processing

Consider a monochromatic image, denote images by 2D functions of the form f(x, y).

Image Sampling & Quantization

An image may be continuous with respect to the x and y spatial coordinates and also in amplitude. To convert an image into digital form, the function has to be sampled in both coordinates and amplitudes

  • Digitizing the coordinate values is called sampling
  • Digitizing the amplitude values is called quantization

Image Sampling

  • Example
image-20241203224550736
1
2
3
4
5
6
7
8
9
from skimage.transform import rescale
image_rescaled = rescale(image, 0.25, anti_aliasing=False)
image_rescaled2 = rescale(image_rescaled, 0.25, anti_aliasing=False)
image_rescaled3 = rescale(image_rescaled2, 0.25, anti_aliasing=False)
f, axs = plt.subplots(2, 2, figsize=(6, 8))
axs[0,0].imshow(image, cmap='gray')
axs[0,1].imshow(image_rescaled, cmap='gray')
axs[1,0].imshow(image_rescaled2, cmap='gray')
axs[1,1].imshow(image_rescaled3, cmap='gray')

The purpose of this code is to demonstrate the effects of repeatedly downscaling an image without applying any anti-aliasing filters. As the image is rescaled multiple times, the quality and resolution of the image will degrade, and the visual artifacts may become more pronounced.

image-20241203224639505

Image Quantization

  • False Contouring

False contouring can occur in digital images when the number of displayable colors is limited. It happens when the continuous tonal gradients in the original image are not accurately reproduced due to the limited number of discrete color levels available in the output device or image format.

False contouring is a direct consequence of the image quantization process. When the number of color levels is reduced too drastically, the resulting discrete steps between color levels become visible as false contours in the image.

image-20241203232732722
1
2
3
4
5
6
7
8
9
# The purpose of this code is to demonstrate the effect 
# of bit depth reduction on an image.
# By performing a bitwise right shift operation on the image,
# the code creates a series of images with different bit depths,
# effectively reducing the number of grayscale levels.
fig, axes = plt.subplots(2, 4)
for i, ax in enumerate(axes.flat):
ax.imshow(image >> i, cmap='gray')
ax.axis('off')
image-20241203232818382
  • Saturation and Noise

When an image is quantized, the continuous tonal range is mapped to a smaller set of discrete color levels. This can result in the amplification or accentuation of noise patterns, as the subtle variations in pixel values may be lost or masked by the discrete color levels.
In areas of the image with low contrast or subtle details, the quantization process can make noise more visible and pronounced, as the small variations in pixel values are more likely to be affected by the reduction in color levels.

image-20241204010527996
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# The purpose of this code is to highlight the saturated pixels 
# in an image, which are the pixels that have reached the
# maximum value of 255 (in an 8-bit grayscale image).
# This is often useful for identifying areas of the image that are
# overexposed or have lost detail due to the pixels being saturated.

import matplotlib.pyplot as plt
from skimage.color import gray2rgb

# Find the saturated pixels
saturated_mask = (image >= 255)

# Convert the highlight image to rgb
highlighted_image = gray2rgb(image)

# Highlight the saturated pixels in red
highlighted_image[saturated_mask] = [255, 0, 0]

plt.imshow(highlighted_image)
image-20241204010542818
  • Bit Plane Slicing

    Bit plane slicing is a technique used to analyze the contribution of individual bit planes (the binary digits that make up the pixel values) in a digital image.

    image-20241204010957744

    Bit plane slicing can be used to understand the impact of quantization on the image, as the removal of lower-order bit planes during quantization directly affects the visual information contained in the image.

image-20241204010838685
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import numpy as np

# The purpose of this code is to extract the
# most significant bit plane of an image.
# By extracting the most significant bit plane,
# this code can provide a simplified representation of the image,
# highlighting the high-level features and structures
# that are determined by the most significant bits.
def get_k_bitPlane(image, k):
return np.where(image&(1<<k), 1, 0)
most_significant_bitplane = get_k_bitPlane(image, 0)
plt.imshow(most_significant_bitplane, cmap='gray', vmin=0, vmax=1)

# The purpose of this modified code is to extract
# and display multiple bit planes of an image.
# By selectively displaying or processing different bit planes,
# you can gain insights into the image data and
# potentially improve the performance of various image processing algorithms.

# Using bit plane 6 and 7
def get_k_bitsPlane(image, kbits):
new_image = np.zeros_like(image)
for k in kbits:
new_image = new_image << 1
new_image += np.where(image & (1 << k), 1, 0).astype(new_image.dtype)
return new_image
bits = [7, 6]
plt.imshow(get_k_bitsPlane(image, bits), cmap='gray', vmin=0, vmax=2 ** len(bits) - 1)
image-20241204011100729