Image processing-similar image recognition (histogram application) and image processing Histogram

Source: Internet
Author: User

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
  1. Public void setGreenBinCount (int greenBinCount ){
  2. This. greenBins = greenBinCount;
  3. }
  4. Public void setBlueBinCount (int blueBinCount ){
  5. This. blueBins = blueBinCount;
  6. }
  7. Public float [] filter (BufferedImage src, BufferedImage dest ){
  8. Int width = src. getWidth ();
  9. Int height = src. getHeight ();
  10. Int [] inPixels = new int [width * height];
  11. Float [] histogramData = new float [redBins * greenBins * blueBins];
  12. GetRGB (src, 0, 0, width, height, inPixels );
  13. Int index = 0;
  14. Int redIdx = 0, greenIdx = 0, and blueIdx = 0;
  15. Int singleIndex = 0;
  16. Float total = 0;
  17. For (int row = 0; row
  18. Int ta = 0, tr = 0, tg = 0, tb = 0;
  19. For (int col = 0; col <width; col ++ ){
  20. Index = row * width + col;
  21. Ta = (inPixels [index]> 24) & 0xff;
  22. Tr = (inPixels [index]> 16) & 0xff;
  23. Tg = (inPixels [index]> 8) & 0xff;
  24. Tb = inPixels [index] & 0xff;
  25. RedIdx = (int) getBinIndex (redBins, tr, 255 );
  26. GreenIdx = (int) getBinIndex (greenBins, tg, 255 );
  27. BlueIdx = (int) getBinIndex (blueBins, tb, 255 );
  28. SingleIndex = redIdx + greenIdx * redBins + blueIdx * redBins * greenBins;
  29. HistogramData [singleIndex] + = 1;
  30. Total + = 1;
  31. }
  32. }
  33. // Start to normalize the histogram data
  34. For (int I = 0; I
  35. {
  36. HistogramData [I] = histogramData [I]/total;
  37. }
  38. Return histogramData;
  39. }

The code for calculating the pasteurization coefficient is as follows:

 

 

[Java]View plaincopy
  1. /**
  2. * Bhattacharyya Coefficient
  3. * Http://www.cse.yorku.ca /~ Kosta/CompVis_Notes/bhattacharyya.pdf
  4. *
  5. * @ Return
  6. */
  7. Public double modelMatch (){
  8. HistogramFilter hfilter = new HistogramFilter ();
  9. Float [] sourceData = hfilter. filter (sourceImage, null );
  10. Float [] candidateData = hfilter. filter (candidateImage, null );
  11. Double [] mixedData = new double [sourceData. length];
  12. For (int I = 0; I <sourceData. length; I ++ ){
  13. MixedData [I] = Math. sqrt (sourceData [I] * candidateData [I]);
  14. }
  15. // The values of Bhattacharyya Coefficient ranges from 0 to 1,
  16. Double similarity = 0;
  17. For (int I = 0; I <mixedData. length; I ++ ){
  18. Similarity + = mixedData [I];
  19. }
  20. // The degree of similarity
  21. Return similarity;
  22. }

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!
 

Related Article

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.