“This is the 11th day of my participation in the Gwen Challenge in November. See details: The Last Gwen Challenge in 2021”

preface

Hello! Friend!!!

Thank you very much for reading haihong’s article, if there are any mistakes in the article, please point out ~

 

Self-introduction ଘ(੭, ᵕ)੭

Nickname: Haihong

Tag: programmer monkey | C++ contestant | student

Introduction: because of C language to get acquainted with programming, then transferred to the computer major, had the honor to get some national awards, provincial awards… Has been confirmed. Currently learning C++/Linux/Python

Learning experience: solid foundation + more notes + more code + more thinking + learn English well!

Image histogram normalization

Image histogram concept:

Image histogram is a statistical table reflecting the distribution of image pixels. In fact, the horizontal coordinate represents the types of image pixels, which can be gray scale or color. The vertical axis represents the total number of pixels in the image for each color value or the percentage of the total number of pixels. An image is made up of pixels because the histogram that reflects the distribution of pixels is often an important feature of the image.

Image gray histogram: A digital image has gray levels [0~255], and the histogram is defined as follows:

Where, is the KTH gray level (e.g. 255), and is the number of the gray level. The normalized histogram is defined as follows:

That is, the number of the KTH gray level is the sum of all gray levels, which is the probability.

Get the image histogram:

T = imread (' a1. JPG) subplot (1, 2, 1), imshow (t), title (' artwork ') subplot (1,2,2), imhist (t), title (' image histogram)Copy the code

Effect:

Imhist: This function is used to get histograms of image data. In the image enhancement technology, the image gray level histogram is of great significance, which is the basis of some image processing technology such as histogram modification technology and histogram equalization. To obtain help information about this function, type doc imhist or help imhist in the MATLAB command window.

Call format:

Imhist (I,n) imhist(X,map) [Counts, X] = imhist(I,n) Imhist (X,map) computes and displays the histogram of the indexed color image X,map being the palette. You can also display histograms with STEM (x,counts). Counts and x return the histogram data vector and the corresponding color vector, respectively.

Imhist (I,n)

T =imread('a1.jpg') subplot(2,3,1),imshow(t),title(' original plot ') subplot(2,3,2),imhist(t),title(' original plot ') Subplot (2,3,4),imhist(t,64),title(' grey scale: 128') subplot(2,3,3),imhist(t, 64),title(' grey scale: 128') Subplot (2,3,6),imhist(t,16),title(' grey scale: 16') subplot(2,3,5),imhist(t, 16),title(' grey scale: 16')Copy the code

Results the figureConclusion imhist (I, n) :

The definition of n is the grayscale series, which can be understood as dividing 0~255 into several parts. For example, the default value is 256, which is divided into 256 parts, and one part is 1, so the grayscale value is counted every 1. And n is 128, then 0-255 is divided into 128 parts, one of which is 2, and the gray value is counted every 2. Therefore, from the comparison image, n of 128 looks more sparse than n of 256.

[counts,x] = imhist(I) Counts the number of pixels at each pixel level and the number of times each pixel appears on the histogram.

So what’s the use of getting these two values? Here we can use these two values to draw a statistical graph using stem functions

The code:

F=imread('a1.jpg'); I=rgb2gray(F); Subplot (1,3,2),imhist(I),title(' imhist ') [count,x]=imhist(I) % Subplot (1,3,3),stem(x,count),title(' statistics based on image histogram ') % plot a bar chart using the values you just obtainedCopy the code

Effect:Here we can see that the images drawn by STEM and imhist are actually the same, but the images drawn by STEM are counted.

If we need to normalize the image histogram here, we will essentially change the ordinate to the probability of the current count to the total count. This is also very simple. We need to divide the STEM counts by the total number of pixels. Code:

F=imread('a1.jpg'); I=rgb2gray(F); [m, n] = size (I) subplot,4,1 (1), imshow (I), title (' artwork ') subplot (1,4,2), imhist (I), title (' image of the original image histogram)/count, x = imhist (I) Subplot (1,4,3),stem(x,count),title(' statistical plot based on image histogram ') count=count/m/n % Subplot (1,4,4),stem(x,count),title(' image histogram normalization ')Copy the code

Effect: