Beispiel #1
0
 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)
Beispiel #2
0
 def test_gradient_hist(self):
     feature = imfeat.GradientHistogram()
     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)
Beispiel #3
0
 def test_save_lena(self):
     feat = imfeat.GradientHistogram()
     out = feat.make_feature_mask(
         imfeat.convert_image(cv2.imread('test_images/lena.jpg'),
                              feat.MODES))
     try:
         os.makedirs('out')
     except OSError:
         pass
     print('m[%s]M[%s]' % (np.min(out), np.max(out)))
     cv2.imwrite('out/lena_gradient.jpg', np.array(out * 255,
                                                   dtype=np.uint8))
Beispiel #4
0
 def __init__(self, max_integral_trees=None, tp=None, tp2=None, num_classes=21):
     super(TextonBase, self).__init__({'type': 'numpy', 'dtype': 'uint8', 'mode': 'bgr'})
     self._max_integral_trees = max_integral_trees
     self._tp = tp
     self._tp2 = tp2
     import imseg
     if not (tp and tp2):
         from imfeat._texton.msrc_model import data
         tp = pickle.loads(data[1][1])
         tp2 = pickle.loads(data[0][1])
     self.tp = imseg.TextonPredict(tp)  # NOTE(brandyn): TP = 1 and TP2 = 0 as that is how the names were sorted
     if max_integral_trees is not None:
         self.tp2 = imseg.IntegralPredict(tp2[:max_integral_trees])
     else:
         self.tp2 = imseg.IntegralPredict(tp2)
     self.num_classes = num_classes
     self.grad = imfeat.GradientHistogram()
Beispiel #5
0
        os.makedirs('%s/view' % out_root)
    except OSError:
        pass
    cv2.imwrite('%s/view/key.png' % out_root, color_key)



def convert_color(image):
    image = imfeat.convert_image(image, [('opencv', 'lab', cv.IPL_DEPTH_8U)])
    image = np.asarray(cv.GetMat(image)).copy()
    return image


HOG = imfeat.HOGLatent(4)
LBP = imfeat.LBP()
GRAD = imfeat.GradientHistogram()




def convert_labels_to_integrals(label_mask, num_vals):
    masks = []
    print(label_mask.shape)
    for x in range(num_vals):
        m = np.asfarray(label_mask == x)
        m = cv2.integral(m)
        masks.append(m)
    return np.ascontiguousarray(np.swapaxes(np.swapaxes(np.array(masks), 0, 2), 0, 1))


def save_feature_hists(func_data, extra_dump_vars, bins=20):
def _meta_hog_gradient():
    return imfeat.MetaFeature(imfeat.HOGLatent(), imfeat.GradientHistogram())
def _gradient_hist():
    return imfeat.GradientHistogram()