Exemplo n.º 1
0
 def test_uniform_properties(self):
     im = np.ones((4, 4), dtype=np.uint8)
     result = graycomatrix(im, [1, 2, 8], [0, np.pi / 2], 4, normed=True,
                           symmetric=True)
     for prop in ['contrast', 'dissimilarity', 'homogeneity',
                  'energy', 'correlation', 'ASM']:
         graycoprops(result, prop)
Exemplo n.º 2
0
 def test_energy(self):
     result = graycomatrix(self.image, [1], [0, 4],
                           4,
                           normed=True,
                           symmetric=True)
     energy = graycoprops(result, 'energy')[0, 0]
     np.testing.assert_almost_equal(energy, 0.38188131)
Exemplo n.º 3
0
 def test_homogeneity(self):
     result = graycomatrix(self.image, [1], [0, 6],
                           4,
                           normed=True,
                           symmetric=True)
     homogeneity = graycoprops(result, 'homogeneity')[0, 0]
     np.testing.assert_almost_equal(homogeneity, 0.80833333)
Exemplo n.º 4
0
 def test_correlation(self):
     result = graycomatrix(self.image, [1, 2], [0],
                           4,
                           normed=True,
                           symmetric=True)
     energy = graycoprops(result, 'correlation')
     np.testing.assert_almost_equal(energy[0, 0], 0.71953255)
     np.testing.assert_almost_equal(energy[1, 0], 0.41176470)
Exemplo n.º 5
0
 def test_dissimilarity_2(self):
     result = graycomatrix(self.image, [1, 3], [np.pi / 2],
                           4,
                           normed=True,
                           symmetric=True)
     result = np.round(result, 3)
     dissimilarity = graycoprops(result, 'dissimilarity')[0, 0]
     np.testing.assert_almost_equal(dissimilarity, 0.665, decimal=3)
Exemplo n.º 6
0
 def test_contrast(self):
     result = graycomatrix(self.image, [1, 2], [0],
                           4,
                           normed=True,
                           symmetric=True)
     result = np.round(result, 3)
     contrast = graycoprops(result, 'contrast')
     np.testing.assert_almost_equal(contrast[0, 0], 0.585, decimal=3)
Exemplo n.º 7
0
    def test_greycomatrix_and_greycoprops_deprecations(self):
        expected = graycomatrix(self.image, [1], [0, np.pi / 2], 4,
                                normed=True, symmetric=True)
        with expected_warnings(["Function ``greycomatrix``"]):
            result = greycomatrix(self.image, [1], [0, np.pi / 2], 4,
                                  normed=True, symmetric=True)
        np.testing.assert_array_equal(expected, result)

        result = np.round(result, 3)
        dissimilarity_expected = graycoprops(result, 'dissimilarity')
        with expected_warnings(["Function ``greycoprops``"]):
            dissimilarity_result = greycoprops(result, 'dissimilarity')
        np.testing.assert_array_equal(
            dissimilarity_expected, dissimilarity_result
        )
Exemplo n.º 8
0
                               loc[1]:loc[1] + PATCH_SIZE])

# select some patches from sky areas of the image
sky_locations = [(38, 34), (139, 28), (37, 437), (145, 379)]
sky_patches = []
for loc in sky_locations:
    sky_patches.append(image[loc[0]:loc[0] + PATCH_SIZE,
                             loc[1]:loc[1] + PATCH_SIZE])

# compute some GLCM properties each patch
xs = []
ys = []
for patch in (grass_patches + sky_patches):
    glcm = graycomatrix(patch, distances=[5], angles=[0], levels=256,
                        symmetric=True, normed=True)
    xs.append(graycoprops(glcm, 'dissimilarity')[0, 0])
    ys.append(graycoprops(glcm, 'correlation')[0, 0])

# create the figure
fig = plt.figure(figsize=(8, 8))

# display original image with locations of patches
ax = fig.add_subplot(3, 2, 1)
ax.imshow(image, cmap=plt.cm.gray,
          vmin=0, vmax=255)
for (y, x) in grass_locations:
    ax.plot(x + PATCH_SIZE / 2, y + PATCH_SIZE / 2, 'gs')
for (y, x) in sky_locations:
    ax.plot(x + PATCH_SIZE / 2, y + PATCH_SIZE / 2, 'bs')
ax.set_xlabel('Original Image')
ax.set_xticks([])
Exemplo n.º 9
0
 def test_invalid_property(self):
     result = graycomatrix(self.image, [1], [0], 4)
     with pytest.raises(ValueError):
         graycoprops(result, 'ABC')
Exemplo n.º 10
0
 def test_non_normalized_glcm(self):
     img = (np.random.random((100, 100)) * 8).astype(np.uint8)
     p = graycomatrix(img, [1, 2, 4, 5], [0, 0.25, 1, 1.5], levels=8)
     np.testing.assert_(np.max(graycoprops(p, 'correlation')) < 1.0)