About histogram

1. Grayscale histogram

Definition of gray-level histogram: Gray-level histogram is a function of gray-level, it represents the number of pixels with a certain gray-level in the image, and reflects the frequency of a certain gray-level in the image.
Examples of histograms:

from PIL import  Image
import matplotlib.pyplot as plt
im = Image.open("./data/lenagray.png")
hist = im.histogram()
plt.figure()
plt.bar([i for i in range(len(hist))],hist)
plt.show()

Insert picture description here
Frequency calculation method:
  vi = ni / n. \ Vi = ni/n. v i=n i / n .
The properties of the histogram: 1) The histogram only reflects the distribution information of the pixels, not including the position information of the pixels; 2) Different images may have the same histogram;
Insert picture description here
3) An image is divided into multiple regions, and more The sum of the histograms of these regions is the histogram of the original image.
Insert picture description here
The function of the histogram: 1) Determine whether the image quantization is appropriate (balanced distribution); 2) Determine the threshold for image binarization (the Threshold point between the two peaks, usually distinguishable background and objects); 3) Calculate the objects in the histogram 4) Calculate the amount of image information H (Entropy, entropy).
Insert picture description here

1.1 Color histogram

The color histogram can be based on different color spaces and coordinate systems. The most commonly used color space is the RGB color space, because most digital images are expressed in this color space. However, the RGB space structure does not conform to people's subjective judgments of color similarity. Therefore, some people have proposed color histograms based on HSV space, Luv space and Lab space because they are closer to people's subjective perception of color. The HSV space is the most commonly used color space for histograms. Its three components represent color (Hue), saturation (Saturation) and value (Value).
Global color histogram: It reflects the composition distribution of colors in the image, that is, which colors appear and the probability of each color.
Cumulative color histogram: When the features in the image cannot be taken over all possible values, some zero values ​​will appear in the statistical histogram. The appearance of these zero values ​​will affect the calculation of the similarity measure, so that the similarity measure cannot correctly reflect the color difference between the images. To solve this problem, the concept of using "accumulated color histogram" is proposed. In the accumulated histogram, adjacent colors are related in frequency.
Quantization histogram: Taking into account the characteristics of different color spaces, each channel is of different importance to the human eye, and different color channels can be given different quantization levels.

1.2 Histogram equalization

Histogram equalization is a method in the field of image processing that uses image histograms to adjust contrast.
Contrast is the ratio of black to white, that is, the gradual change from black to white. The larger the ratio, the more gradual levels from black to white, and thus the richer the color expression. Contrast has a very critical effect on visual effects. Generally speaking, the larger the contrast, the clearer and more eye-catching the image, and the brighter and brighter the color; while the lower the contrast, the whole picture will be gray.
Histogram equalization is usually used to increase the global contrast of many images, especially when the contrast of the useful data of the image is quite close. In this way, the brightness can be better distributed on the histogram. This can be used to enhance the local contrast without affecting the overall contrast. Histogram equalization achieves this function by effectively expanding the commonly used brightness.

Guess you like

Origin blog.csdn.net/beauthy/article/details/105178066