FPGA histogram operation

Histogram concepts and classification

An image histogram is used as a graphical representation of the distribution of tones in a digital image. It plots the number of pixels for each hue value. By looking at the histogram of a particular image, the viewer will be able to judge the entire tonal distribution at a glance.

The horizontal axis of the chart represents the hue variation, while the vertical axis represents the total number of pixels of that specific hue.

The left side of the horizontal axis represents dark areas, the middle represents midtone values, and the right represents light areas. The vertical axis represents the area size (total number of pixels) captured in each area.

Therefore, a histogram of a very dark image will have most of its data points on the left and center of the plot.

In contrast, a histogram of a very bright image with few dark areas or shadows will have most of its data points to the right and center of the plot.

94149aefd95aaf9cf8a2517359a215cf.png 2d33aeb18341c708f72d7559d47d7c43.png

Commonly used in FPGA processing is the grayscale histogram, which describes the grayscale statistical information of an image and is mainly used in image segmentation, image enhancement, and image grayscale transformation.

FPGA is mainly divided into the following three types for histogram processing:

01e7205918403733500b8783bf96a8ee.png

The histogram concept that we often hear or hear mainly refers to histogram equalization, which is also the simplest method and is commonly found in some entry-level image processing books or articles. We will introduce histogram standardization and histogram stretching later, focusing on histogram equalization first. Public account: OpenFPGA

Histogram statistics and FPGA implementation

Mathematically speaking, the image histogram describes the statistical characteristics of each gray level of the image. It uses a function of the image gray value to count the number or probability of each gray level in an image. Its mathematical definition is as follows Shown: Public account: OpenFPGA

Histogram statistics are relatively simple. You can count the color images after converting them into grayscale images. The pseudo code is as follows: Public account: OpenFPGA

unsigned int pHistCnt[256];
  int i,j =0;
  memset(pHistCnt,0,256);
  for( i=0;i<m dwHeight; i++)
    for( j=0;j<m_dwWidth;j++)
      pHistCnt[m_pBitmap[i*mdwWidth+j]]++;//统计打开图像中各个灰度像素点个数

The above code just traverses the image and stores the data into the data.

f1492eebe41ca0dffe8d1896db2d86b4.png

The right side of the picture above is the histogram statistics of the image on the left.

When actually implemented with FPGA, a normalized histogram is generally used, that is, it does not care about the actual specific value of each gray value but the probability of occurrence. Specifically, it is assumed that the number of pixels in an image is N (N=image length*image width), and the total number of gray levels is L (the number of levels is related to the number of bits in the image. Assuming an 8-bit image, the total number is 2^8 =256), at this time, the total number of pixels of gray level l (small L) in the image is. Each gray level is divided by the total number of pixels to obtain the probability of occurrence of each gray level: Public account: OpenFPGA

The above formula has another name: histogram probability density function (also called normalized grayscale histogram), recorded as PDF

What can you do after finishing the histogram statistics? It is obvious that the brightness and contrast information of the image can be read from the histogram. If the statistics of the histogram are mainly distributed to the right, then the image is relatively bright; vice versa. When the statistical distribution of the histogram is relatively uniform, the contrast of the image is relatively large. If the statistical distribution of the histogram is relatively concentrated, the contrast of the image is small. Public account: OpenFPGA

The following pictures illustrate the above conclusions:

20d0b884068ee7d6c54511556c0f0ac7.png A darker image with lower contrast 122153f0992c1a70afc375e140b3b5a2.png A brighter image with lower contrast da15c589bbc7a8be02ba8bfab5619b77.png High contrast images

FPGA functional analysis

There are two ways to perform histogram operations on FPGA, one is true operation and the other is pseudo operation: true operation is to cache the image for subsequent processing (equalization, etc.), and then send the image out; pseudo operation is After the image is pipelined, the required information is cached, and then after the next image comes, the information obtained from the previous image is applied to the current image. Since commonly used operations are based on video frames to avoid excessive video delay, we generally use pseudo operations, that is, cache the current frame information and then apply the next frame of image.

For the above characteristics, we generally choose on-chip dual-port RAM as cache memory. For an 8-bit depth map, the amount of data in the statistical results is not large, so on-chip storage is selected. In addition, on the one hand, the statistical module needs to cooperate with other timings, so it needs to provide a bilateral read and write interface; on the other hand, address information is needed in the statistical process, so a memory in the form of RAM is selected.

Basically, the histogram statistical steps are as follows:

  • Read the current statistical value, add 1 and then rewrite it into RAM

  • Repeat the above steps until the statistics of the current image are completed

  • Read out the results before the next image arrives

  • Clear RAM contents after reading

Therefore, we need three circuits to complete histogram statistics: statistical circuit, readout circuit and clearing circuit.

3b6abfebc9bc0d6bb2dde0766ed1f604.png

We will introduce these three circuit designs in detail in the next article.

FPGA circuit design

FPGA code design

think

What should be done if the image histogram is segmented and concentrated?

Follow-up articles:

Histogram equalization and FPGA implementation

Histogram specification and FPGA implementation

Histogram stretching and FPGA implementation

Guess you like

Origin blog.csdn.net/Pieces_thinking/article/details/135028201