예제 #1
0
def translation(image, sigma, axis=0):
    '''
    8x8のブロックごとに離散コサイン変換された画像(以下DCT画像)を平行移動する.

    Parameters
    ----------
    image:幅と高さが8の倍数であるDCT画像を表す2次元配列. 8の倍数でない場合の動作は未定義.
    
    sigma:移動距離. 負数も可(ただし, 少し遅い)

    axis:移動方向の軸. defaultは`axis=0`

    Returns
    -------
    `image`を平行移動したDCT画像を表す2次元配列を返す. `image`の値は変わらない.

    Examples
    --------
    >>> import numpy as np
    >>> a = np.arange(64).reshape((8,8))
    >>> a
    array([[ 0,  1,  2,  3,  4,  5,  6,  7],
           [ 8,  9, 10, 11, 12, 13, 14, 15],
           [16, 17, 18, 19, 20, 21, 22, 23],
           [24, 25, 26, 27, 28, 29, 30, 31],
           [32, 33, 34, 35, 36, 37, 38, 39],
           [40, 41, 42, 43, 44, 45, 46, 47],
           [48, 49, 50, 51, 52, 53, 54, 55],
           [56, 57, 58, 59, 60, 61, 62, 63]])
    >>> dct_image_transform.translation.translation(a,4,axis=1)
    array([[  0,   1,  -2,   0,   3,   0,  -7,   8],
           [  6,   0, -11,   3,  10,  -5, -16,  22],
           [ 12,  -1, -19,   7,  17, -10, -25,  36],
           [ 19,  -3, -28,  11,  25, -16, -34,  50],
           [ 25,  -4, -36,  16,  32, -22, -43,  64],
           [ 32,  -6, -45,  20,  39, -27, -52,  79],
           [ 38,  -7, -53,  24,  47, -33, -61,  93],
           [ 45,  -9, -62,  28,  54, -38, -71, 107]])
    '''

    if sigma < 0:
        sigma = -sigma
        if axis == 0:
            return np.transpose(
                reflection(_translation(
                    reflection(np.transpose(image), axis=1), sigma),
                           axis=1))
        elif axis == 1:
            return reflection(_translation(reflection(image, axis=1), sigma),
                              axis=1)
    else:
        if axis == 0:
            return np.transpose(_translation(np.transpose(image), sigma))
        elif axis == 1:
            return _translation(image, sigma)
예제 #2
0
def rotate180(image):
    '''
    8x8のブロックごとに離散コサイン変換された画像(以下DCT画像)を180度回転する.

    Parameters
    ----------
    image:幅と高さが8の倍数であるDCT画像を表す2次元配列. 8の倍数でない場合の動作は未定義.
    
    Returns
    -------
    `image`を180度回転したDCT画像を表す2次元配列を返す. `image`の値は変わらない.

    Examples
    --------
    >>> import numpy as np
    >>> a = np.arange(64).reshape((8,8))
    >>> a
    array([[ 0,  1,  2,  3,  4,  5,  6,  7],
           [ 8,  9, 10, 11, 12, 13, 14, 15],
           [16, 17, 18, 19, 20, 21, 22, 23],
           [24, 25, 26, 27, 28, 29, 30, 31],
           [32, 33, 34, 35, 36, 37, 38, 39],
           [40, 41, 42, 43, 44, 45, 46, 47],
           [48, 49, 50, 51, 52, 53, 54, 55],
           [56, 57, 58, 59, 60, 61, 62, 63]])
    >>> dct_image_transform.rotate.rotate180(a)
    array([[ 5.76134986e-15, -1.00000000e+00,  2.00000000e+00,
            -3.00000000e+00,  4.00000000e+00, -5.00000000e+00,
             6.00000000e+00, -7.00000000e+00],
           [-8.00000000e+00,  9.00000000e+00, -1.00000000e+01,
             1.10000000e+01, -1.20000000e+01,  1.30000000e+01,
            -1.40000000e+01,  1.50000000e+01],
           [ 1.60000000e+01, -1.70000000e+01,  1.80000000e+01,
            -1.90000000e+01,  2.00000000e+01, -2.10000000e+01,
             2.20000000e+01, -2.30000000e+01],
           [-2.40000000e+01,  2.50000000e+01, -2.60000000e+01,
             2.70000000e+01, -2.80000000e+01,  2.90000000e+01,
            -3.00000000e+01,  3.10000000e+01],
           [ 3.20000000e+01, -3.30000000e+01,  3.40000000e+01,
            -3.50000000e+01,  3.60000000e+01, -3.70000000e+01,
             3.80000000e+01, -3.90000000e+01],
           [-4.00000000e+01,  4.10000000e+01, -4.20000000e+01,
             4.30000000e+01, -4.40000000e+01,  4.50000000e+01,
            -4.60000000e+01,  4.70000000e+01],
           [ 4.80000000e+01, -4.90000000e+01,  5.00000000e+01,
            -5.10000000e+01,  5.20000000e+01, -5.30000000e+01,
             5.40000000e+01, -5.50000000e+01],
           [-5.60000000e+01,  5.70000000e+01, -5.80000000e+01,
             5.90000000e+01, -6.00000000e+01,  6.10000000e+01,
            -6.20000000e+01,  6.30000000e+01]])
    '''
    return reflection(reflection(image,axis=0),axis=1)
예제 #3
0
 def test_reflecion0_1(self):
     image = np.array(io.imread('images/sample512x512.jpg'), dtype=np.float)
     tf_image = idct2(reflection(dct2(image), axis=0))
     image = np.flipud(image)
     self.assertTrue(np.max(np.abs(image - tf_image)) < 1e-10)
예제 #4
0
 def test_reflecion1_3(self):
     image = np.array(io.imread('images/sample2048x2048.jpg'),
                      dtype=np.float)
     tf_image = idct2(reflection(dct2(image), axis=1))
     image = np.fliplr(image)
     self.assertTrue(np.max(np.abs(image - tf_image)) < 1e-10)