Image processing-similar image recognition (histogram application) and image processing Histogram
Algorithm Overview:
First, histogram data is collected for the source image and the image to be filtered, and then the respective image histograms are normalized.
Calculate the histogram data using the babacache coefficient algorithm to obtain the image similarity value. The value ranges from 0 to 1.
0 represents extremely different, and 1 represents extremely similar (identical ).
Detailed algorithm steps:
The histogram data is generated based on the pixel data of the source image and the candidate image. Step 2: Enable
Use the histogram result output in step 1 and the Bhattacharyya coefficient algorithm to calculate the similarity
Degree value.
Step 1: histogram Calculation
The histogram is divided into a grayscale histogram and an RGB histogram. It is very easy to calculate a grayscale image histogram, as long as you initialize
Histogram array H with a size of 256, and then completes the frequency distribution statistics based on the pixel value. If the pixel value is 124
H [124] + = 1, while for color RGB pixels, there are two ways to express the histogram, one is a single histogram, the other is
Three-dimensional histograms, which are simple and clear, correspond to three RGB colors respectively, and define three histograms HR,
HG, HB. Assume that the RGB value of P of a certain pixel is (4,231,129), then the histogram is calculated as HR [4] + = 1,
HG [231] + = 1, HB [129] + = 1. After each pixel is calculated, the RGB color histogram data is generated.
The sh of a single histogram of RGB pixels indicates a slightly complex point. The value range of each color is 0 ~ Between 255, suppose
Can be divided into a certain range of equal portions, when the 8 equal portions, each equal portions of the value range is 32, 16 equal portions, each equal value range
The circumference is 16. When the value is 4, the range of each equal value is 64. Assume that the RGB value is (14, 68,221 ),
Then, it corresponds to the histogram index values (index) respectively: (0, 4, 13), according to the formula for calculating the index value:Index = R + G * 16 + B * 16*16
Corresponding histogram index = 0 + 4*16 + 13*16*16, SH [3392] + = 1
In this way, all RGB pixel values are traversed to complete histogram data calculation.
Step 2: Calculate the barrier coefficient. The formula is as follows:
P and P' represent the histogram data of the source and candidate images respectively. After the product of each data point with the same I value is squared, the data points are added.
The obtained result is the image similarity value (coefficient factor value), ranging from 0 to 1.
Program effect:
Similarity exceeds 99%, extremely similar
Similarity: 72%, generally similar
The source code for program histogram calculation is as follows:
[Java]View plaincopy
- Public void setGreenBinCount (int greenBinCount ){
- This. greenBins = greenBinCount;
- }
- Public void setBlueBinCount (int blueBinCount ){
- This. blueBins = blueBinCount;
- }
- Public float [] filter (BufferedImage src, BufferedImage dest ){
- Int width = src. getWidth ();
- Int height = src. getHeight ();
- Int [] inPixels = new int [width * height];
- Float [] histogramData = new float [redBins * greenBins * blueBins];
- GetRGB (src, 0, 0, width, height, inPixels );
- Int index = 0;
- Int redIdx = 0, greenIdx = 0, and blueIdx = 0;
- Int singleIndex = 0;
- Float total = 0;
- For (int row = 0; row
- Int ta = 0, tr = 0, tg = 0, tb = 0;
- For (int col = 0; col <width; col ++ ){
- Index = row * width + col;
- Ta = (inPixels [index]> 24) & 0xff;
- Tr = (inPixels [index]> 16) & 0xff;
- Tg = (inPixels [index]> 8) & 0xff;
- Tb = inPixels [index] & 0xff;
- RedIdx = (int) getBinIndex (redBins, tr, 255 );
- GreenIdx = (int) getBinIndex (greenBins, tg, 255 );
- BlueIdx = (int) getBinIndex (blueBins, tb, 255 );
- SingleIndex = redIdx + greenIdx * redBins + blueIdx * redBins * greenBins;
- HistogramData [singleIndex] + = 1;
- Total + = 1;
- }
- }
- // Start to normalize the histogram data
- For (int I = 0; I
- {
- HistogramData [I] = histogramData [I]/total;
- }
- Return histogramData;
- }
The code for calculating the pasteurization coefficient is as follows:
[Java]View plaincopy
- /**
- * Bhattacharyya Coefficient
- * Http://www.cse.yorku.ca /~ Kosta/CompVis_Notes/bhattacharyya.pdf
- *
- * @ Return
- */
- Public double modelMatch (){
- HistogramFilter hfilter = new HistogramFilter ();
- Float [] sourceData = hfilter. filter (sourceImage, null );
- Float [] candidateData = hfilter. filter (candidateImage, null );
- Double [] mixedData = new double [sourceData. length];
- For (int I = 0; I <sourceData. length; I ++ ){
- MixedData [I] = Math. sqrt (sourceData [I] * candidateData [I]);
- }
- // The values of Bhattacharyya Coefficient ranges from 0 to 1,
- Double similarity = 0;
- For (int I = 0; I <mixedData. length; I ++ ){
- Similarity + = mixedData [I];
- }
- // The degree of similarity
- Return similarity;
- }
In matlab, what is the difference between histogram processing and regional histogram processing? Who has more advantages in Face Recognition?
Generally, we use regional histograms for processing.
Histogram processing is generally used for image enhancement to modify the image as a whole.
The area histogram focuses on modifying the image in a certain area, so the recognition capability is stronger.
What is the difference between histogram balancing and histogram normalization in matlab Image Processing?
1. The "central idea" of histogram equalization is to change the gray-scale histogram of the original image from a certain gray-scale interval in the comparison set to a uniform distribution within all gray-scale ranges. Histogram equalization refers to non-linear stretching of the image, and re-allocating the image pixel value, so that the number of pixels within a certain gray range is roughly the same. Histogram equalization is to change the histogram distribution of a given image to "even" distribution histogram distribution. 2. Normalization is a non-dimensional processing method that converts the absolute values of physical system values into relative values. An Effective Method to simplify calculation and reduce the value. Histogram normalization is similar!