def test_ainterface(self): """Simple test of the basic feature interface""" features = [ imfeat.ObjectBank(), imfeat.GIST(), imfeat.HOGLatent(2), imfeat.Autocorrelogram(), imfeat.GradientHistogram(), imfeat.Histogram('gray'), imfeat.RHOG(gray=False), imfeat.RHOG(gray=True), imfeat.Moments('rgb', 2), imfeat.Histogram('rgb'), imfeat.SpatialHistogram(mode='rgb', num_rows=2, num_cols=2), imfeat.TinyImage() ] feat_sz = {} for image_fn in glob.glob('test_images/*'): if image_fn in ['test_images/test3.gif']: continue for feat_num, feature in enumerate(features): prev_f = None for load_func in [ cv.LoadImage, cv.LoadImageM, cv2.imread, Image.open ]: f = feature( imfeat.resize_image(load_func(image_fn), 100, 100)) self.assertEqual(feat_sz.setdefault(feat_num, f.size), f.size) if prev_f is None: prev_f = f if load_func != Image.open: # Skip PIL as the jpeg loading produces different data np.testing.assert_equal(prev_f, f)
def __init__(self, min_diff=.5, **kw): super(DecisionTree, self).__init__([('opencv', 'gray', 8)], min_diff=min_diff, **kw) self._surf = impoint.SURF() self._feat = imfeat.Histogram('gray', num_bins=4, norm=False) self.rfc = None
def test_gray_hist(self): feature = imfeat.Histogram('gray') for feat_out, image in self._run_all_images(feature): print(feat_out) print(len(feat_out)) self._feat_hist_zero(feature) self._feat_hist_norm(feature)
def test_hist(self): img = cv.LoadImage('test_images/lena.jpg') feat = imfeat.Histogram('rgb', num_bins=8) feat2 = imfeat.PyramidHistogram(mode='rgb', num_bins=8, levels=1) np.testing.assert_equal(feat(img), feat2(img)) out = imfeat.PyramidHistogram(mode='lab', num_bins=[4, 11, 11], levels=4)(img) print(out) print(out.shape)
def test_hist_planar(self): img = cv.LoadImage('test_images/lena.jpg') for i in range(512): for j in range(512): img[i, j] = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) for mode in modes: print(mode) feat = imfeat.Histogram(mode, style='planar') b = feat(img) print(b)
def _hist_joint(): return imfeat.Histogram('rgb', style='joint')
def _lab_hist_joint_8bins(): return imfeat.Histogram('lab', style='joint', num_bins=8)
def test_meta(self): self._histogram(imfeat.MetaFeature(imfeat.Histogram('lab')))
def test_histogram_joint_lab(self): self._histogram(imfeat.Histogram('lab'))
def test_histogram_joint_spatial(self): img = Image.open('test_images/lena.ppm') np.testing.assert_equal( imfeat.Histogram(mode='rgb')(img), imfeat.SpatialHistogram(mode='rgb')(img))
def test_histogram_joint(self): self._histogram(imfeat.Histogram('rgb'))
def __init__(self, min_diff=10, **kw): super(Histogram, self).__init__(min_diff=min_diff, **kw) self._feat = imfeat.Histogram('gray')
def __init__(self, num_bins=8, *args, **kw): super(GradientHistogram, self).__init__({'type': 'numpy', 'dtype': 'float32', 'mode': 'gray'}) self._hist_feat = imfeat.Histogram('gray', num_bins=num_bins)