Image Processing and Coding

Submitted by sylvia.wong@up… on Fri, 07/07/2023 - 19:17

In the field of computer vision and digital media, image processing and coding play a vital role in analysing, manipulating, and representing images. This branch of study focuses on developing algorithms and techniques to enhance, transform, compress, and decode digital images. In this topic, we will delve into the fundamental concepts of image processing and coding, enabling you to understand and apply these techniques to various practical scenarios.

By the end of this topic, you will have a solid foundation in image processing and coding. You will be able to apply various techniques to analyse, manipulate, and interpret digital images. Whether you are interested in computer vision, photography, or multimedia applications, this course will equip you with the knowledge and skills to work with images effectively.

Sub Topics

Image processing is a field that involves the manipulation and analysis of digital images to extract valuable information or enhance their visual quality. To understand the basics of image processing, let's explore how digital images are captured, stored, and manipulated, along with the principles and methodologies used in the process.

A diagram depicting how digital images are captured, stored, and manipulated, along with the principles and methodologies used in the process

Image capture

Digital images are captured using devices such as cameras, scanners, or sensors. These devices convert the optical information of the scene into digital signals that represent the image. In a camera, for example, light passes through the lens and is focused onto an image sensor (such as a CCD or CMOS sensor) that converts the light into electrical signals. The signals are then processed and stored as digital images.

Image representation

Digital images are represented as two-dimensional arrays of discrete elements called pixels. Each pixel corresponds to a tiny portion of the image and contains information about the colour or intensity value at that location. The arrangement of pixels forms a grid, and the resolution of an image is determined by the number of pixels in each dimension.

Image storage

Digital images are typically stored in file formats such as JPEG, PNG, TIFF, or BMP. These formats define how the image data is encoded and organized within the file. Different file formats have varying levels of compression, glossiness, and support for features like transparency or metadata. The storage format affects the file size, quality, and compatibility with different software applications.

Image manipulation

Image manipulation involves performing various operations on digital images to achieve desired outcomes. These operations can be categorized into two main types:

  • Point operations modify individual pixels based on their values, such as adjusting brightness or contrast.
  • Neighbourhood operations consider groups of pixels and apply operations such as filtering, smoothing, or edge detection to enhance or extract specific features from the image.

Image processing techniques

Image processing techniques encompass a wide range of algorithms and methodologies. Some common techniques include:

  • Filtering: This technique involves applying filters to an image to remove noise, enhance details, or extract specific frequencies.
  • Segmentation: Segmentation techniques divide an image into meaningful regions or objects based on similarities in colour, texture, or other features.
  • Feature extraction: Feature extraction methods aim to identify and extract relevant features or patterns from an image that are useful for subsequent analysis or recognition tasks.
  • Image restoration: Restoration techniques are employed to restore images that have been degraded due to factors like noise, blurring, or compression artefacts.
  • Image compression: Compression techniques reduce the storage size of an image while preserving essential visual information. Lossless and lossy compression algorithms are used depending on the application requirements.

Applications of image processing

Image processing has numerous applications across various fields. In medical imaging, it is used for tasks like image enhancement, segmentation of anatomical structures, and tumour detection. In satellite imagery and remote sensing, image processing techniques help extract land cover information, detect changes, or monitor environmental conditions. In computer vision, image processing plays a crucial role in tasks such as object detection, recognition, and tracking.

Pixels

In the context of digital images, pixels are the fundamental building blocks that make up an image. The term "pixel" is derived from "picture element" and refers to the smallest unit of an image. Each pixel represents a single point in the image and contains information about its colour or intensity value.

An image, in simple terms, is a collection of pixels arranged in a grid-like structure. The resolution of an image is determined by the number of pixels in each dimension. For example, an image with a resolution of 1920x1080 consists of 1,920 pixels in the horizontal (width) dimension and 1,080 pixels in the vertical (height) dimension.

The representation of images in terms of pixels involves assigning a specific colour or intensity value to each pixel. In grayscale images, each pixel is represented by a single value that indicates its intensity level. The intensity can range from 0 (black) to 255 (white) in an 8-bit grayscale image.

Color images, on the other hand, consist of multiple channels, typically Red, Green, and Blue (RGB). In an RGB image, each pixel is represented by a combination of three values (red, green, and blue) that determine its colour. The intensity values for each channel can range from 0 to 255, allowing for a wide range of colours to be represented.

For example, the colour RGB(47, 10, 200) is bright blue.

Colour spaces

Color spaces provide different ways to represent and interpret colours in an image. The RGB colour space, mentioned earlier, is the most common and widely used colour space. However, there are other colour spaces such as CMYK (cyan, magenta, yellow, black), HSV (hue, saturation, value), and LAB, which offer alternative ways to describe colours based on different perceptual aspects.

Color Gamuts

https://pagesthemagazine.com/color-me-confident/

Watch the following video on RGB and CMYK colour modes.

Learning Activity

Visit the following site and pick a colour from the palette. The RGB and CMYK codes will be displayed.
https://rgbcolorcode.com/

The importance of pixel-level operations in image processing

A photo editor in action

Pixel-level operations are fundamental in image processing as they allow for precise control and manipulation of individual pixels in an image. These operations involve modifying the pixel values to achieve desired effects such as adjusting brightness, contrast, or colour balance. By applying pixel-level operations, images can be enhanced, corrected, or transformed to improve their visual quality or extract specific features.

Pixel-level operations are the basis for various image processing techniques, such as point operations, filtering, and morphological operations. They provide the ability to manipulate image characteristics at a granular level and can be used for tasks like noise reduction, edge detection, image enhancement, and feature extraction.

  • Grayscale images: Grayscale images are the simplest type of images and consist of shades of grey ranging from black to white. Each pixel in a grayscale image is represented by a single intensity value. These images are commonly used in applications where colour information is not necessary or when working with single-channel image processing algorithms. Grayscale images are widely used in tasks such as image enhancement, edge detection, and feature extraction.
  • Colour images: Colour images provide richer visual information compared to grayscale images and are extensively used in applications such as computer vision, digital photography, and image analysis. They allow for tasks like colour correction, object recognition, and image segmentation.
  • Binary images: Binary images are images that consist of only two possible pixel values, usually black and white. These images are created by thresholding a grayscale or colour image, where pixel values below a certain threshold are assigned one value (e.g., black), and pixel values above the threshold are assigned the other value (e.g., white). Binary images are commonly used in tasks like image segmentation, shape analysis, and object detection.
  • Multi-spectral images: Multispectral images contain multiple channels or bands that capture electromagnetic radiation across different wavelengths. These images are often acquired using specialized sensors or satellite systems. Each band represents a specific portion of the electromagnetic spectrum, allowing for the capture of additional information beyond what can be seen by the human eye. Multispectral images find applications in fields such as remote sensing, agriculture, environmental monitoring, and geological surveys. 

Characteristics and properties of different image types

The characteristics and properties of different image types are essential considerations for performing image processing tasks effectively. Here are some key aspects to consider:

  • Dimensionality: Grayscale and binary images have a single channel, while colour images have multiple channels. Understanding the dimensionality of an image is crucial for selecting appropriate algorithms and techniques.
  • Colour information: Color images provide additional information compared to grayscale images, enabling more sophisticated image analysis and processing tasks. Consideration of colour spaces, such as RGB, HSV or LAB, is necessary for accurately manipulating colour information.
  • Pixel values: The range and interpretation of pixel values vary among different image types. Grayscale images have intensity values ranging from 0 to 255, while binary images have only two possible values (0 and 1). Understanding the pixel value range and its meaning is essential for applying appropriate operations and thresholds.
  • Channel interdependence: In colour images, the channels are interdependent, meaning that changes in one channel can affect the perception of colours in other channels. Proper handling of colour channel relationships is necessary for maintaining colour consistency and accuracy during image processing.
  • Spectral information: Multispectral images capture data across different wavelengths, providing valuable spectral information. Utilizing the unique properties of each band allows for advanced analysis and interpretation of the image data, such as identifying specific land cover types or detecting vegetation health.

Understanding the characteristics and properties of different image types is crucial for selecting the appropriate image processing techniques, algorithms, and tools. It ensures that image processing tasks are performed effectively and that the unique aspects of each image type are properly addressed during analysis and manipulation.

Digital image processing involves a series of steps to transform and analyse images for various applications. Here are the essential steps typically involved in digital image processing:

A diagram depicting steps in digital processing
  1. Image acquisition: Image acquisition is the process of capturing or obtaining images using digital cameras, scanners, or other imaging devices. It involves converting physical images or scenes into digital representations. The quality and characteristics of the acquired images have a significant impact on the subsequent processing steps.
  2. Preprocessing: Preprocessing involves preparing the acquired images for further analysis by applying various techniques. This step includes several sub-steps, such as:
    1. Noise reduction: Images may contain noise caused by various factors, such as sensor limitations or environmental conditions. Noise reduction techniques, such as filtering algorithms, are applied to remove or reduce unwanted noise while preserving important image details.
    2. Image enhancement: Image enhancement techniques aim to improve the visual quality of images by adjusting brightness, contrast, or sharpness. Enhancements can highlight important features, improve visibility, and make images more visually appealing.
  3. Segmentation: Segmentation is the process of dividing an image into meaningful regions or segments based on specific characteristics. It involves identifying and separating regions with similar properties, such as colour, texture, or intensity. Image segmentation is crucial for tasks such as object detection, tracking, and image understanding.
  4. Feature extraction: Feature extraction involves identifying and extracting relevant visual features or patterns from segmented regions. These features represent specific characteristics of the image, such as edges, textures, shapes, or colour histograms. Feature extraction is important for tasks such as object recognition, classification, and image comparison.
  5. Image analysis: Image analysis is the process of interpreting and extracting meaningful information from images. It involves applying various algorithms and techniques to analyse the extracted features and derive insights from the image data. Image analysis tasks can include object detection, pattern recognition, image classification, and image understanding.

Using Jupyter Notebook, an interactive coding environment within Anaconda Navigator, offers several advantages when working on digital image processing tasks. Here's why and how Jupyter Notebook is commonly used for image manipulation:

  • Interactive and visual environment: Jupyter Notebook provides an interactive and visual environment for coding, making it easier to experiment with image processing algorithms and visualize the results. It allows for the seamless integration of code, text, and visualizations in a single document, which is ideal for documenting and sharing image processing workflows.
  • Integrated libraries: Jupyter Notebook supports various Python libraries commonly used in image processing, such as Matplotlib, scikit-image (skiimage.io), scikit-learn (sklearn), and NumPy. These libraries provide extensive functionality for reading, displaying, manipulating, and analysing images. Jupyter Notebook's integration with these libraries simplifies the process of importing and utilizing their functions for image processing tasks.
  • Image I/O capabilities: Jupyter Notebook allows you to read and write images in different formats, such as JPEG, PNG, or TIFF. The integration with libraries like Matplotlib and scikit-image provides convenient functions for loading images into memory, accessing pixel data, and performing image-related operations.
  • Visualizing images: With Jupyter Notebook, you can easily display images directly within the notebook using Matplotlib's image plotting capabilities. This feature enables you to visualize the original images, as well as the intermediate results of image processing operations, such as noise reduction, segmentation, or feature extraction. Visualizing images helps in understanding and evaluating the effectiveness of different image processing techniques.
  • Code documentation and collaboration: Jupyter Notebook allows you to combine code cells with Markdown text cells, making it a powerful tool for documenting image processing workflows. You can add explanations, comments, and annotations to describe each step of the image processing pipeline. This documentation aspect makes Jupyter Notebook useful for sharing, collaboration, and reproducibility of image processing tasks.: Jupyter Notebook supports various Python libraries commonly used in image processing, such as Matplotlib, scikit-image (skiimage.io), scikit-learn (sklearn), and NumPy. These libraries provide extensive functionality for reading, displaying, manipulating, and analysing images. Jupyter Notebook's integration with these libraries simplifies the process of importing and utilizing their functions for image processing tasks.

To use Jupyter Notebook for image processing, you can follow these steps:

  1. Install Anaconda Navigator: Download and install Anaconda Navigator, which includes Jupyter Notebook, from the Anaconda website (https://www.anaconda.com/products/individual).
  2. Launch Jupyter Notebook: Open Anaconda Navigator, locate Jupyter Notebook, and click on the launch button. This will open a web browser window with the Jupyter Notebook interface.
  3. Create a new Notebook: In the Jupyter Notebook interface, click on "New" and select "Python 3" to create a new Python notebook.
  4. Import relevant libraries: In the first code cell of the notebook, import the necessary libraries for image processing, such as Matplotlib, scikit-image, scikit-learn, and NumPy.
  5. Read and display images: Use the appropriate functions from the libraries to read images from the file system and display them using Matplotlib's image plotting functions. You can also perform basic image manipulations, such as resizing, cropping, or converting colour spaces, using the available functions.
  6. Implement image processing techniques: Write code cells to implement specific image processing techniques, such as noise reduction, segmentation, feature extraction, or any other desired operations. Visualize the intermediate results and evaluate their effectiveness.
  7. Document and run the code: Add markdown cells to document the steps, explain the purpose of each code cell, and provide any necessary comments. Execute the code cells to run the image processing operations and observe the output.

Libraries and frameworks are important in image processing tasks as they provide a wide range of functionalities, algorithms, and tools for manipulating, analysing, and visualizing images. By leveraging libraries, researchers and practitioners can develop sophisticated image-processing pipelines and perform a wide range of tasks efficiently and effectively. Let's take a look at some of the most common:

 

Library Description Image Processing
Matplotlib Matplotlib is a popular data visualization library in Python. It provides a wide range of functions and tools for creating high-quality plots, charts, and visualizations. In image processing, Matplotlib is commonly used for visualizing images, displaying histograms, plotting graphs, and showcasing the results of various image processing operations. It offers flexible and customizable options for adjusting colours, scales, labels, and annotations, making it a powerful tool for visualizing image data and analysis.
scikit-image scikit-image provides a comprehensive collection of functions and algorithms for image manipulation, filtering, segmentation, feature extraction, and more. The skimage.io module within scikit-image offers utilities for reading and saving images in various formats. It supports popular image file formats such as JPEG, PNG, TIFF, and BMP, allowing easy access to image data for processing within Python. scikit-image, often abbreviated as skimage, is a library specifically designed for image-processing tasks in Python.
scikit-learn scikit-learn, or sklearn, is a widely used machine learning library in Python. scikit-learn provides a unified interface for training and evaluating machine learning models, making it convenient to incorporate machine learning techniques into image analysis pipelines. It also includes utility functions for data preprocessing, model selection, and performance evaluation. While it is not solely focused on image processing, it offers a range of machine-learning algorithms that can be applied to images for tasks such as classification, clustering, and dimensionality reduction.
NumPy NumPy is a fundamental library for numerical computing in Python. It provides powerful tools for handling large, multi-dimensional arrays and performing efficient numerical operations on them. It offers a wide range of functions for array manipulation, mathematical operations, linear algebra, and statistical analysis. In image processing, NumPy is crucial for representing and manipulating image data as arrays.NumPy's efficient array processing capabilities enable faster and more efficient image processing operations, making it an essential library in the field.

 

 

 

 

Watch the following video on image processing basics including the use of Python for image manipulation.

Learning Activity

If you haven't already, install and explore Jupyter Notebook then using this and information from this course consider the following questions:

  1. What is the difference between a black-and-white image and a binary image?
  2. What are the main steps in digital image processing?
Module Linking
Main Topic Image
A photographers desk and apps they use for editing
Is Study Guide?
Off
Is Assessment Consultation?
Off