Exemple #1
0
 def test_smaller_even_output(self):
     from dfm.reframe import reframe
     a = numpy.array([[1, 1, 1], [1, 2, 1], [1, 1, 1]])
     expected = numpy.array([
         [0, 0, 0, 0],
         [0, 1, 1, 1],
         [0, 1, 2, 1],
         [0, 1, 1, 1],
     ])
     out = reframe(a, width=4, height=4, x=2, y=2)
     print('')
     pprint(out)
     assert_array_equal(out, expected)
Exemple #2
0
 def test_offcenter_larger(self):
     from dfm.reframe import reframe
     a = numpy.array([
         [1, 1, 1, 1, 1],
         [1, 2, 2, 2, 1],
         [1, 2, 3, 2, 1],
         [1, 2, 2, 2, 1],
         [1, 1, 1, 1, 1],
     ])
     expected = numpy.array([[2, 3, 2], [2, 2, 2], [1, 1, 1]])
     out = reframe(a, width=3, height=3, x=1, y=0)
     print('')
     pprint(out)
     assert_array_equal(out, expected)
Exemple #3
0
 def test_offcenter_smaller_cropped(self):
     from dfm.reframe import reframe
     a = numpy.array([[1, 1, 1], [1, 2, 1], [1, 1, 1]])
     expected = numpy.array([
         [0, 0, 0, 1, 1],
         [0, 0, 0, 1, 2],
         [0, 0, 0, 1, 1],
         [0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0],
     ])
     out = reframe(a, width=5, height=5, x=4, y=1)
     print('')
     pprint(out)
     assert_array_equal(out, expected)
Exemple #4
0
    else:
        raise ValueError('No convergence when finding local maxima')

features = pandas.DataFrame(features)
gabor_vects = numpy.full([features.shape[0], size**2], numpy.nan)
for feature in tqdm.tqdm(features.itertuples(), desc='construct features'):
    f = feature.Index
    kside = 1 + 2 * int(ceil(kernel_extent * feature.sigma))
    kernel_params = dict(ksize=(kside, kside),
                         sigma=feature.sigma,
                         theta=feature.theta,
                         lambd=feature.lambd,
                         gamma=gamma,
                         ktype=cv2.CV_32F)
    kernel = cv2.getGaborKernel(psi=0, **kernel_params)
    gabor = reframe(kernel, width=size, height=size, x=feature.x, y=feature.y)
    gabor_vects[f, :] = gabor.flatten()

print('determine explained variance by feature..')
covs = gabor_vects @ image.flatten()
areas = numpy.sum(numpy.abs(gabor_vects), axis=1)
expl_var = covs / areas
expl_var_ranks = numpy.flip(numpy.argsort(expl_var))
features['expl_var_rank'] = expl_var_ranks

## selection
selection = numpy.full_like(expl_var_ranks, False, dtype=bool)
img_vect = image.ravel()
selection[expl_var_ranks[0]] = True  ## select first gabor
recon_vect = gabor_vects[selection, :].sum(axis=0)
recon_r = numpy.corrcoef(recon_vect, img_vect)[0, 1]