A summary of image histogram correlation

Source: Internet
Author: User
Tags truncated

This paper mainly discusses histogram equalization , histogram stipulation (matching), Local histogram , constrained contrast adaptive histogram equalization (CLAHE), and image enhancement based on histogram statistics.


1. Histogram equalization

The basic idea is to make the same number of pixels per gray level as possible


Figure 1-1: Histogram equalization effect (truncated from Digital image processing)

As can be seen from the graph above, histogram equalization is used to improve image contrast by making the image gray scale span wider gray scale range.

Another advantage of histogram equalization is that no additional parameters are required and the entire process is automatic

The disadvantage of histogram equalization is that some gray levels may not be mapped after stretching, resulting in a grainy sense of image perception

algorithm steps:

1) Calculate image grayscale histogram and normalized (divided by total number of pixels)

2) Calculate the cumulative histogram of normalized histogram fhist[L-1]

3) to the original figure Gray S, the transformed grayscale d = fhist[s] * (L-1)

Code:

void Equalizehist (byte* pbuffer, byte* out, int height, int width)
{
	//assumed to be 8-bit image
	int hist[256] = {0};

	for (int i = 0, i < height; i++)
	{for
		(int j = 0; J < width; j + +)
		{
			byte* pnow = pbuffer + i * widt H + J;
			Hist[int (*pnow)]++;
		}
	}

	Float fhist[256] = {0};
	float len = height*width;
	for (int i = 0; i < i++)
		fhist[i] = hist[i]/len;

	for (int i = 1; i < i++)
		fhist[i] = fhist[i-1] + fhist[i];

	for (int i = 0, i < height; i++)
	{for
		(int j = 0; J < width; j + +)
		{
			byte* pnow = pbuffer + i * width + j;
			out[i*width+j]= Int (Fhist[int (*pnow)] * 255 + 0.5);}}}


2. Histogram regulation (matching)

Histogram equalization is the transformation of the histogram into a uniform distribution of the shape, histogram matching is transformed into a specified shape, so histogram equalization can be regarded as a special case of the histogram specification

The basic idea of the algorithm is to use histogram equalization as a bridge, while the original histogram and the target histogram are balanced, so theoretically, two balanced histogram is the same (of course, the actual situation must be different). It may be assumed that the original graph of the balanced histogram is shist[L-1], the target graph of the equalization of the histogram is dhist[L-1]. For the first level of the original histogram, look for the level of the map that is closest to shist[I in dlhist as I maps grayscale

In the histogram comparison this piece of algorithm implements the single mapping rule sml and Group mapping rules GML two methods:


Figure 2-1. SML and GML mapping rules (SML and GML mappings, truncated from histogram)

Code:

void Matchhist (Mat Src, Mat DST, mat& out) {/* calculates the respective cumulative histogram */int srchist[256] = {0};

	int dsthist[256] = {0};
		for (int i = 0; i < src.rows; i++) {byte* ptr = src.ptr<byte> (i);
	for (int j = 0; J < Src.cols; J + +) Srchist[int (ptr[j])]++;
		} for (int i = 0; i < dst.rows; i++) {byte* ptr = dst.ptr<byte> (i);
	for (int j = 0; J < Dst.cols; J + +) Dsthist[int (ptr[j])]++;
	} float fsrchist[256] = {0};
	Float fdsthist[256] = {0};
		for (int i = 0; i < i++) {Fsrchist[i] = Srchist[i]/float (src.rows*src.cols);
	Fdsthist[i] = dsthist[i]/float (dst.rows*dst.cols);
		} for (int i = 1; i < i++) {Fsrchist[i] = Fsrchist[i-1] + fsrchist[i];
	Fdsthist[i] = Fdsthist[i-1] + fdsthist[i];
	}/* Gray value difference at all levels */float distance[256][256] = {0}; for (int i = 0; i < n; i++) {for (int j = 0; J < N; j + +) Distance[i][j] = Fabs (Fsrchist[j]-fdsthist[i])
	;
	} #if 1/*SML map */int mapping[256] = {0}; for (int i = 0; I < 256;
		i++) {int mindst = 0;
		float minValue = distance[0][i];
				for (int j = 1; J <; J + +) {if (MinValue > Distance[j][i]) {minValue = Distance[j][i];
			MINDST = j;
	}} Mapping[i] = MINDST;
	} #else/*GML Map */int laststart = 0, lastend = 0, start = 0, end = 0;
		for (int i = 0; i < i++) {float minValue = distance[i][0];
				for (int j = 0; J <; J + +) {if (MinValue > Distance[i][j]) {end = J;
			MinValue = Distance[i][j];
			}} if (start! = Laststart | | end! = lastend) {for (int j = start; J <= End; j + +) mapping[j] = i;
			Laststart = start;
			Lastend = end;
		Start = Lastend + 1;
		}} #endif for (int i = 0; i < src.rows; i++) {byte* ptr = src.ptr<byte> (i);
		byte* ptr1 = out.ptr<byte> (i);
	for (int j = 0; J < Src.cols; J + +) Ptr1[j] = Mapping[int (Ptr[j]); }
}

3. Local histogram

Sometimes it is necessary to highlight the small and medium-range details of the image, but the histogram equalization and the basic gray-scale transformation method mentioned in the paper are all based on the global gray scale distribution.


There are approximately 3 ways to implement local histogram processing:

1) Divide the original image into non-overlapping sub-blocks and do histogram processing within each sub-block (e.g. histogram equalization)

Simple operation, but the output image will have a block effect


2) Similar to template convolution, to the point to be processed center, take its neighborhood as a sub-block, in the sub-block histogram processing, processing results only map to that point

Block effects can be eliminated, but histogram processing is required for each point, which is inefficient


3) The first two methods of the combined version, no longer move by pixel, step size is less than the width of the child block to ensure that two adjacent sub-blocks overlap, each sub-block histogram mapping results are assigned to all points within the child block, so that each point will have multiple assignments, the final value is the mean value of these assignments


Figure 3-1 compares the global histogram equalization with the local Histogram equalization (Method 2, the sub-block size is 11*11)


Figure 3-1: Original diagram (left), Global histogram equalization (middle), local histogram equalization (right)


4. Adaptive histogram equalization with limited contrast (CLAHE)

Clahe on the basis of local histogram equalization (also called Adaptive Histogram equalization Ahe), the histogram of each sub-block is limited, which controls the noise caused by ahe, and can be used to do fog.

Here's a more detailed description of Clahe.


The following algorithm steps refer to the OpenCV Clahe module (opencv\sources\modules\imgproc\src\clahe.cpp)

Step1. Expands the image boundary so that it can be cut into just a few sub-blocks

Assume that each chunk area is tilesizetotal

Sub-block factor Lutscale = 255.0/tilesizetotal

Processing of preset limit: limit = MAX (1, limit * tilesizetotal/256)

Step2. For each sub-block, calculate the histogram

Step3. For each gray level of the histogram of each sub-block, the preset limit value is used to limit the number of pixels that the entire histogram exceeds the limit.

Step4. Calculates the LUT cumulative histogram for each sub-block Tilelut

Tilelut[i] = sum[i] * Lutscale

Sum[i] is a cumulative histogram, Lutscale ensure tilelut value in [0, 255]

Step5. Traverse the original image each point, consider the sub-block of the point and the right, bottom, and bottom 4 sub-blocks of the Tilelut, with the original gray value of the index to get 4 values, and then do the bilinear interpolation is worth the point of the gray value of the transformation

bilinear interpolation avoids the calculation of the histogram centered on each pixel.


Figure 4-1 compares the effects of global histogram equalization, Ahe, and Clahe, and you can see that the Clahe control of noise is the best


figure 4-1. A. original image; B. Global histogram equalization; C. AHE (30 sub-blocks); d. CLAHE (limit:0.272, 30 sub-blocks)


5. Image enhancement based on histogram statistics

The normalized histogram is P (r) so that the mean value of the pixel is, so that the N-order moment of R about mean M is obtained, and if n=2 is taken, the gray variance is obtained.

In the actual calculation, the usual sampling mean and sampling variance are used to eliminate the histogram calculation:

Case:

Assuming that the dark area of the image needs to be enhanced now, the gray mean and variance of its neighborhood window are computed for each point, and the difference is compared with the global gray mean and variance, if the local mean is less than the sum of the specified threshold and global mean, then the point is considered to be in the dark area, and then the relationship between local variance and global If the local variance falls within a range (), then the point is less contrast, so it can be multiplied by a value to highlight the feature, and the low threshold is set to avoid increasing the actual constant area


6. Reference

[1] "Digital image processing" Gonzalez

[2] A local histogram equalization algorithm for maintaining image brightness, such as river waves

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.