def test_cooccurence():
    np.random.seed(222)
    f = np.random.rand(32, 32)
    f = (f * 255).astype(np.int32)

    assert np.all(
        texture.cooccurence(f, 0, distance=1, symmetric=False) == brute_force(
            f, 0, 1))
    assert np.all(
        texture.cooccurence(f, 1, distance=1, symmetric=False) == brute_force(
            f, 1, 1))
    assert np.all(
        texture.cooccurence(f, 2, distance=1, symmetric=False) == brute_force(
            f, 1, 0))
    assert np.all(
        texture.cooccurence(f, 3, distance=1, symmetric=False) == brute_force(
            f, 1, -1))

    assert np.all(
        texture.cooccurence(f, 0, distance=1, symmetric=1) == brute_force_sym(
            f, 0, 1))
    assert np.all(
        texture.cooccurence(f, 1, distance=1, symmetric=1) == brute_force_sym(
            f, 1, 1))
    assert np.all(
        texture.cooccurence(f, 2, distance=1, symmetric=1) == brute_force_sym(
            f, 1, 0))
    assert np.all(
        texture.cooccurence(f, 3, distance=1, symmetric=1) == brute_force_sym(
            f, 1, -1))
Ejemplo n.º 2
0
    def computeTexture(self, p, imag, center, distances=1):
        '''
        Computes the texture around vector p
        '''
        from mahotas.features import texture

        origins = self._get_points_centering(center, p[1, :])
        puntos = numpy.array([p + cent for cent in origins])
        select = (puntos < numpy.array(imag.shape) - 1).all(axis=2).all(axis=0)
        p_real = puntos[:, select, :]

        colors = self._interp_gray_level(p_real, imag)

        ndarray = self._posterizeImage(colors)

        # Prevent errors with iterative list:
        if (type(distances) is not list) and (type(distances)
                                              is not numpy.ndarray):
            distances = [distances]

        glcm = []
        for dis in distances:
            glcm.append(
                texture.cooccurence(ndarray.astype(int) - 1,
                                    0,
                                    distance=dis,
                                    symmetric=False))
        features = texture.haralick_features(glcm)
        labels = texture.haralick_labels
        return features, labels
Ejemplo n.º 3
0
def test_cooccurence3():
    np.random.seed(222)
    f = np.random.rand(32, 32, 8)
    f = (f * 255).astype(np.int32)

    for di, (d0,d1,d2) in enumerate(texture._3d_deltas):
        assert np.all(texture.cooccurence(f, di, distance=1, symmetric=False) == brute_force3(f, d0, d1, d2))
Ejemplo n.º 4
0
def test_cooccurence3():
    np.random.seed(222)
    f = np.random.rand(32, 32, 8)
    f = (f * 255).astype(np.int32)

    for di, (d0,d1,d2) in enumerate(texture._3d_deltas):
        assert np.all(texture.cooccurence(f, di, symmetric=False) == brute_force3(f, d0, d1, d2))
Ejemplo n.º 5
0
 def computeTexture(self, p, imag, center, distances=1):
     '''
     Computes the texture around vector p
     '''
     from mahotas.features import texture
     
     origins = self._get_points_centering(center, p[1,:])
     puntos = numpy.array([p+cent for cent in origins])
     select = (puntos<numpy.array(imag.shape)-1).all(axis=2).all(axis=0)
     p_real = puntos[:,select,:]
     
     colors = self._interp_gray_level(p_real, imag)
     
     ndarray = self._posterizeImage(colors)
     
     # Prevent errors with iterative list:
     if (type(distances) is not list) and (type(distances) is not numpy.ndarray):
         distances = [distances]        
     
     glcm=[]
     for dis in distances:
         glcm.append(texture.cooccurence(ndarray.astype(int)-1, 0, distance=dis, symmetric=False))
     features = texture.haralick_features(glcm)
     labels = texture.haralick_labels
     return features, labels
def test_cooccurence_errors():
    f2 = np.zeros((6, 6), np.uint8)
    f3 = np.zeros((6, 6, 6), np.uint8)
    f4 = np.zeros((6, 6, 6, 6), np.uint8)

    with pytest.raises(ValueError):
        texture.cooccurence(f2, -2, distance=1)

    with pytest.raises(ValueError):
        texture.cooccurence(f3, -2, distance=1)

    with pytest.raises(ValueError):
        texture.cooccurence(f2, 10, distance=1)

    with pytest.raises(ValueError):
        texture.cooccurence(f3, 17, distance=1)

    with pytest.raises(ValueError):
        texture.cooccurence(f4, 1, distance=1)
Ejemplo n.º 7
0
def test_cooccurence():
    np.random.seed(222)
    f = np.random.rand(32, 32)
    f = (f * 255).astype(np.int32)

    assert np.all(texture.cooccurence(f, 0, distance=1, symmetric=False) == brute_force(f, 0, 1))
    assert np.all(texture.cooccurence(f, 1, distance=1, symmetric=False) == brute_force(f, 1, 1))
    assert np.all(texture.cooccurence(f, 2, distance=1, symmetric=False) == brute_force(f, 1, 0))
    assert np.all(texture.cooccurence(f, 3, distance=1, symmetric=False) == brute_force(f, 1, -1))

    assert np.all(texture.cooccurence(f, 0, distance=1, symmetric=1) == brute_force_sym(f, 0, 1))
    assert np.all(texture.cooccurence(f, 1, distance=1, symmetric=1) == brute_force_sym(f, 1, 1))
    assert np.all(texture.cooccurence(f, 2, distance=1, symmetric=1) == brute_force_sym(f, 1, 0))
    assert np.all(texture.cooccurence(f, 3, distance=1, symmetric=1) == brute_force_sym(f, 1, -1))
Ejemplo n.º 8
0
    def computeTexture(self, p, imag, origin, distances=1):
        '''
        Computes the texture around vector p
        
        :param p: The mapping or rojecting vector :math:`\mathbf{v}_{{\\theta},{\\varphi}}`
        :param imag: Three-dimensional intensity array corresponding to a 3D registered brain image. 
        :type imag: 3D numpy array
        :param origin: Specifies the position of the origin of mapping vectors. If not specified, defaults to the geometrical center of the image. 
        :type origin: 3D coordinates in numpy array
        :param distances: It helds the distances at which the GLCM is going to be computed. 
        :type distances: integer or list of integers
        '''
        from mahotas.features import texture

        # set the originso of each vector (the central one and surrounding 8)
        origins = self._get_points_centering(origin, p[1, :])
        puntos = numpy.array([p + cent for cent in origins])
        select = (puntos < numpy.array(imag.shape) - 1).all(axis=2).all(axis=0)
        p_real = puntos[:, select, :]

        colors = self._interp_gray_level(p_real, imag)

        ndarray = self._posterizeImage(colors)

        # Prevent errors with iterative list, adding support for
        # several distances in the computation of the GLCM
        if (type(distances) is not list) and (type(distances)
                                              is not numpy.ndarray):
            distances = [distances]

        glcm = []
        for dis in distances:
            glcm.append(
                texture.cooccurence(ndarray.astype(int) - 1,
                                    0,
                                    distance=dis,
                                    symmetric=False))
        features = texture.haralick_features(glcm)
        labels = texture.haralick_labels
        return features, labels
Ejemplo n.º 9
0
def test_single_point():
    A = np.zeros((5,5), np.uint8)
    A[2,2]=12
    assert not np.any(np.isnan(texture.cooccurence(A, 0, distance=1)))
Ejemplo n.º 10
0
 def c_1():
     texture.cooccurence(f3, -2, distance=1)
Ejemplo n.º 11
0
 def c_1():
     texture.cooccurence(f3, -2)
Ejemplo n.º 12
0
 def c_2_10():
     texture.cooccurence(f2, 10, distance=1)
Ejemplo n.º 13
0
 def c_2_10():
     texture.cooccurence(f2, 10, distance=1)
Ejemplo n.º 14
0
 def c_4_1():
     texture.cooccurence(f4, 1, distance=1)
Ejemplo n.º 15
0
 def c_4_1():
     texture.cooccurence(f4, 1, distance=1)
Ejemplo n.º 16
0
 def c_4_1():
     texture.cooccurence(f4, 1)
Ejemplo n.º 17
0
 def c_1():
     texture.cooccurence(f3, -2)
Ejemplo n.º 18
0
 def c_2_10():
     texture.cooccurence(f2, 10)
Ejemplo n.º 19
0
 def c_4_1():
     texture.cooccurence(f4, 1)
Ejemplo n.º 20
0
 def c_3_17():
     texture.cooccurence(f3, 17)
Ejemplo n.º 21
0
 def c_2_10():
     texture.cooccurence(f2, 10)
Ejemplo n.º 22
0
def test_float_cooccurence():
    A = np.zeros((5,5), np.float32)
    A[2,2]=12
    texture.cooccurence(A, 0, distance=1)
def test_single_point():
    A = np.zeros((5, 5), np.uint8)
    A[2, 2] = 12
    assert not np.any(np.isnan(texture.cooccurence(A, 0, distance=1)))
Ejemplo n.º 24
0
 def c_1():
     texture.cooccurence(f3, -2, distance=1)
def test_float_cooccurence():
    A = np.zeros((5, 5), np.float32)
    A[2, 2] = 12
    with pytest.raises(TypeError):
        texture.cooccurence(A, 0, distance=1)
Ejemplo n.º 26
0
 def c_3_17():
     texture.cooccurence(f3, 17, distance=1)
Ejemplo n.º 27
0
 def c_3_17():
     texture.cooccurence(f3, 17, distance=1)
Ejemplo n.º 28
0
 def c_3_17():
     texture.cooccurence(f3, 17)
Ejemplo n.º 29
0
def test_float_cooccurence():
    A = np.zeros((5,5), np.float32)
    A[2,2]=12
    texture.cooccurence(A,0)