Home | Trees | Indices | Help |
---|
|
1 # PyVision License 2 # 3 # Copyright (c) 2011 David S. Bolme 4 # All rights reserved. 5 # 6 # Redistribution and use in source and binary forms, with or without 7 # modification, are permitted provided that the following conditions 8 # are met: 9 # 10 # 1. Redistributions of source code must retain the above copyright 11 # notice, this list of conditions and the following disclaimer. 12 # 13 # 2. Redistributions in binary form must reproduce the above copyright 14 # notice, this list of conditions and the following disclaimer in the 15 # documentation and/or other materials provided with the distribution. 16 # 17 # 3. Neither name of copyright holders nor the names of its contributors 18 # may be used to endorse or promote products derived from this software 19 # without specific prior written permission. 20 # 21 # 22 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR 26 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 27 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 28 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 30 # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 31 # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 ''' 34 Created on Jan 15, 2011 35 36 @author: bolme 37 ''' 38 39 import pyvision as pv 40 import numpy as np 41 #import time 42 43 LBP_CLASSIC = [ 44 [-1.0,-1.0], 45 [ 0.0,-1.0], 46 [ 1.0,-1.0], 47 [ 1.0, 0.0], 48 [ 1.0, 1.0], 49 [ 0.0, 1.0], 50 [-1.0, 1.0], 51 [-1.0, 0.0], 52 ] 53 54 LBP_RAD1 = np.array([[0.0, 1.0], [0.70710678118654746, 0.70710678118654757], [1.0, 6.123233995736766e-17], [0.70710678118654757, -0.70710678118654746], [1.2246467991473532e-16, -1.0], [-0.70710678118654746, -0.70710678118654768], [-1.0, -1.8369701987210297e-16], [-0.70710678118654768, 0.70710678118654746]]) 55 LBP_RAD2 = 2.0*LBP_RAD1 56 LBP_RAD3 = 3.0*LBP_RAD1 57 LBP_RAD4 = 4.0*LBP_RAD1 58 LBP_RAD8 = 8.0*LBP_RAD1 59 60 6163 ''' 64 Conduct an LBP transformation on the image. 65 ''' 66 im = pv.Image(im.asOpenCVBW()) #TODO: Use opencv for speed 67 68 mat = im.asMatrix2D() 69 lbp = np.zeros(mat.shape,dtype=np.uint8) 70 71 w,h = mat.shape 72 73 bit = 1 74 for dx,dy in pattern: 75 affine = pv.AffineTranslate(-dx,-dy,(w,h)) 76 mat2 = affine.transformImage(im).asMatrix2D() 77 78 lbp += bit*(mat < mat2) 79 80 bit = bit * 2 81 82 return lbp83
Home | Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Tue Apr 21 14:32:00 2015 | http://epydoc.sourceforge.net |