What is histogram specification?

Key takeaways:

  1. Histogram specification (or histogram matching) is an image processing technique that adjusts the histogram of a source image to match the histogram of a reference image, aiming for a similar intensity distribution.

  2. The steps to implement a histogram are:

    1. Generate and normalize the histograms for both images.

    2. Compute the cumulative distribution functions (CDFs) for the intensity levels.

    3. Use the CDFs to derive equalization levels, which help map pixel values from the source image to the reference histogram.

  3. Understanding essential terms such as probability distribution function (PDF) and cumulative distribution function (CDF) is crucial, as these metrics form the foundation for performing histogram specification effectively.

  4. The process includes separating frequency counts and intensity values from both images, finding corresponding levels, and making adjustments to achieve the desired histogram.

  5. Histogram matching is widely used in various fields, including medical imaging, remote sensing, color correction, image enhancement, and machine learning, highlighting its versatility and importance in image analysis.

Histogram specification, also known as histogram matching, is a technique used in image processing to modify an image’s histogram to resemble another image’s histogram. The main goal is to give the source image a similar histogram shape as the reference image.

Histogram matching

To perform histogram matching, we need to know the number of intensity values and the size of both images.

Before performing histogram matching, it is essential to understand histogram equalization. We will briefly outline the necessary steps before delving into each in detail.

  1. Calculate the frequencyNumber of pixels against specific intensity value. of intensity values (i.e., the number of pixels for each intensity level) to generate histograms for both the source and reference images.

  2. Normalize both histograms by dividing their frequency counts by the total number of pixels in the image. This normalization results in the PDF of the intensity levels.

  3. Compute the cumulative distribution functions for the normalized intensity values from both histograms. The CDF is the cumulative sum of the PDF values and represents the probability of a pixel having a value less than or equal to a certain intensity.

  4. Multiply all CDF values by the maximum pixel intensity value (e.g., 255 for an 8-bit image) and round each resulting value to the nearest whole number. This value represents the equalization level for each pixel.

  5. Use the source image’s CDF to create new frequency values for mapping.

  6. Map the pixel values of the source image using the equalization levels obtained from the source image’s CDF and the reference image’s histogram. This step transforms the pixel values of the source image to achieve a histogram that closely resembles the reference image.

If anyone is unfamiliar with the technical terms in the steps above, don’t worry; we will revise these concepts first.

Histogram

The histogram below illustrates the distribution of intensity levels of the given image.

Histogram of an image
Histogram of an image

Note: Each box in the image represents one pixel.

This histogram represents the frequency of each intensity value in an image. Pixels with intensity value 0 occur 6 times in the image, pixels with value 2 occur 2 times, and so on.

Calculate PDF

To make calculations easier, let’s use a tabular format to represent the data:

  1. rk represents the pixel intensity values, ranging from 0 to L−1 for an image with L possible intensity levels.

  2. nk indicates the frequency of each corresponding pixel intensity value rk. It counts how many times each pixel intensity appears in the image.

  3. p(rk) denotes the probability of occurrence of each pixel intensity value rk. It can be calculated using the formula:

Where M is the number of rows and N is the number of columns.

Probability distribution of intensity values
Probability distribution of intensity values

The total number of pixels in the image is 25 (5*5), so we will divide each nk value by 25 to get the p(rk).

Calculate CDF

To calculate the CDF for each pixel value, we’ll sum the probability of the current pixel value (p(rk)) with the previous CDF value. Mathematically, this can be expressed as:

Where CDF(sk) is the cumulative distribution function value for the pixel value rk, and CDF(sk−1) is the CDF value for the previous pixel value.

Cumulative distribution of intensity values
Cumulative distribution of intensity values

The CDF at the last rk should always be equal to 1; if it is not, there must be a mistake in the calculation.

Calculate histogram equalization level

We need to get the CDF values within the range of possible intensity values. We multiply each CDF value with the highest intensity value, L-1, where L represents the number of possible intensity values. Then, we round the result to the nearest whole number.

Multiplying CDF by L-1
Multiplying CDF by L-1

In this example, the value of L is 8, which includes all the possible pixel intensities from 0 – 7. The value of L-1 will be 7.

Apply mapping

First, separate the equalization level and new nk (frequency counts) values from the source image table from the sk (cumulative distribution function) and equalization level values from the reference image table.

Check the new nk values corresponding to the histogram equalization levels in the source table that equal the histogram equalization levels in the reference table. If there is no exact match in the source image table, find a value greater than the current histogram equalization level in the reference image table but with the minimum difference. Thus, we will assign nk values from the source image table to the pixel intensities in the reference image table.

Note: The values in the tables below do not continue from those used to illustrate the concepts above.

Mapping
Mapping

Example

Let’s look at a detailed example of how to perform histogram matching.

Note: To find the total number of pixels in the image, multiply the dimensions, i.e., height * width.

Create histograms
Create histograms
1 of 7

Note: Specified images can have different dimensions than the original image.

Histogram matching is extensively used in image processing and computer vision. It finds applications in medical imaging, remote sensing, color correction, image enhancement, computer graphics, face recognition, art restoration, saturation/exposure adjustment, and optimizing data for machine learning.

Conclusion

Histogram specification is a fundamental technique in image processing that transforms one image’s histogram to closely resemble another’s. One can effectively perform histogram matching by systematically generating and analyzing histograms, normalizing data, and employing cumulative distribution functions. This technique has significant implications across various domains, enhancing image quality and enabling more accurate data representation in visual analytics. Understanding the underlying principles and processes of histogram matching is essential for professionals in fields that leverage image processing technologies.

Quiz

Test your understanding of the histogram matching process by attempting this quiz.

1

What is the initial step in performing histogram matching?

A)

Creating histograms for the source and reference images.

B)

Normalizing the histograms.

C)

Calculating the cumulative distribution function (CDF).

D)

Applying mapping directly.

Question 1 of 50 attempted

Frequently asked questions

Haven’t found what you were looking for? Contact Us


What are the advantages of histogram specification?

Histogram specification allows for better control over image contrast and brightness by matching the histogram of a source image to a desired reference histogram. This technique enhances visual appearance, ensures consistent intensity distribution, and is particularly useful for improving images from different sources.


What is the difference between histogram equalization and specification?

Histogram equalization aims to uniformly distribute pixel intensities across the entire range, enhancing contrast in the image. In contrast, histogram specification adjusts the histogram of a source image to match the histogram of a reference image, targeting a specific intensity distribution rather than a uniform one.


What does a histogram define?

A histogram is used to define the distribution of pixel intensity values in an image. It represents the frequency of occurrence of each intensity level, providing insights into the image’s contrast, brightness, and overall tonal range.


What is the purpose of histogram matching?

The purpose of histogram matching is to modify the pixel intensity distribution of a source image to match that of a reference image. This technique is often used to improve the visual consistency of images from different sources or to standardize image intensity for analysis.


What are two important characteristics of a histogram?

Two important characteristics of a histogram are as follows:

  • Shape: The shape of the histogram indicates the distribution of pixel intensities, which helps assess the image’s contrast and brightness.
  • Peak and valley: Peaks in the histogram represent frequently occurring intensity values, while valleys indicate less common intensities, providing insight into image details.

Can the histogram of two images be the same?

Yes, the histogram of two images can be the same if they contain the same distribution of pixel intensity values, even if the actual images look different. However, this does not imply that the images are identical, as they may have different content or details.


Where are histograms used in real life?

Histograms are used in various real-life applications, including:

  • Medical imaging: To analyze and enhance images for better diagnosis.
  • Photography: For adjusting exposure and contrast.
  • Remote sensing: To interpret satellite images and analyze land use.
  • Quality control: In manufacturing to ensure product consistency.
  • Machine learning: For feature extraction and data preprocessing in image classification tasks.

Copyright ©2024 Educative, Inc. All rights reserved