LBP.py 926 B

123456789101112131415161718192021222324
  1. from pylab import imread, figure, show, imshow
  2. # Divide the examined window to cells (e.g. 16x16 pixels for each cell).
  3. # For each pixel in a cell, compare the pixel to each of its 8 neighbors
  4. # (on its left-top, left-middle, left-bottom, right-top, etc.). Follow the
  5. # pixels along a circle, i.e. clockwise or counter-clockwise.
  6. # Where the center pixel's value is greater than the neighbor, write "1".
  7. # Otherwise, write "0". This gives an 8-digit binary number (which is usually
  8. # converted to decimal for convenience).
  9. # Compute the histogram, over the cell, of the frequency of each "number"
  10. # occurring (i.e., each combination of which pixels are smaller and which are
  11. # greater than the center).
  12. # Optionally normalize the histogram. Concatenate normalized histograms of all
  13. # cells. This gives the feature vector for the window.
  14. image = imread("../images/test.png")
  15. figure()
  16. imshow(image)
  17. show()