def test_affine_Matrix3D(self): im = pv.Image(pv.BABOON) test_im = pv.Image(im.asMatrix3D()) affine = pv.AffineFromRect(pv.CenteredRect(256,256,128,128),(64,64)) # Transform the images im = affine(im) test_im = affine(test_im) # Correlate the resulting images vec1 = pv.unit(im.asMatrix3D().flatten()) vec2 = pv.unit(test_im.asMatrix3D().flatten()) score = np.dot(vec1,vec2) self.assertGreater(score, 0.998)
def computeVector(self, img): '''Creates a vector from a face''' #face = img.asPIL().crop(rect.box()).resize(self.face_size,ANTIALIAS) vec = img.asMatrix2D().flatten() if self.norm == PCA_MEAN_STD_NORM: vec = pv.meanStd(vec) if self.norm == PCA_MEAN_UNIT_NORM: vec = pv.meanUnit(vec) if self.norm == PCA_UNIT_NORM: vec = pv.unit(vec) return vec
def computeVector(self,img): '''Creates a vector from a face''' #face = img.asPIL().crop(rect.box()).resize(self.face_size,ANTIALIAS) vec = img.asMatrix2D().flatten() if self.norm == PCA_MEAN_STD_NORM: vec = pv.meanStd(vec) if self.norm == PCA_MEAN_UNIT_NORM: vec = pv.meanUnit(vec) if self.norm == PCA_UNIT_NORM: vec = pv.unit(vec) return vec
def test_3_unit(self): '''unit Normalization: ||norm|| = 1.0 and dot(norm,im)/||im|| = 1.0.''' ilog = None if 'ilog' in list(globals().keys()): ilog = globals()['ilog'] norm = pv.unit(self.tile) if ilog != None: ilog.log(norm,label="unit_Normalization") mat = norm.asMatrix2D() length = np.sqrt((mat**2).sum()) self.assertAlmostEqual(length,1.0,places=3) mat = norm.asMatrix2D() mat = mat.flatten() im = self.tile.asMatrix2D().flatten() proj = np.dot(mat,im) length = np.sqrt((im**2).sum()) self.assertAlmostEqual(proj/length,1.0,places=3)
def test_3_unit(self): '''unit Normalization: ||norm|| = 1.0 and dot(norm,im)/||im|| = 1.0.''' ilog = None if 'ilog' in list(globals().keys()): ilog = globals()['ilog'] norm = pv.unit(self.tile) if ilog != None: ilog.log(norm, label="unit_Normalization") mat = norm.asMatrix2D() length = np.sqrt((mat**2).sum()) self.assertAlmostEqual(length, 1.0, places=3) mat = norm.asMatrix2D() mat = mat.flatten() im = self.tile.asMatrix2D().flatten() proj = np.dot(mat, im) length = np.sqrt((im**2).sum()) self.assertAlmostEqual(proj / length, 1.0, places=3)
def clipRange(self): self.value = pv.unit(self.value)