[iaresize] [Up] [iadct] Geometric Manipulations

iaptrans
Periodic translation.

Synopsis

g = iaptrans( f, t )

Implemented in Python.

Input

f Image. Gray-scale (uint8 or uint16) or binary image (logical).
t Image. Accepts any image data type.

[rows cols] to translate.

Output

g Image. Gray-scale (uint8 or uint16) or binary image (logical).

Description

Translate the image periodically by t=[r0 c0]. This translation can be seen as a window view displacement on an infinite tile wall where each tile is a copy of the original image. The periodical translation is related to the periodic convolution and discrete Fourier transform. Be careful when implementing this function using the mod, some mod implementations in C does not follow the correct definition when the number is negative.

Examples

>>> import Numeric

              
>>> f = Numeric.array([[1,2,3,4,5],[6,7,8,9,10],[11,12,13,14,15]])

              
>>> print f
[[ 1  2  3  4  5]
 [ 6  7  8  9 10]
 [11 12 13 14 15]]
>>> print iaptrans(f, [-1,2]).astype(Numeric.UnsignedInt8)
[[ 9 10  6  7  8]
 [14 15 11 12 13]
 [ 4  5  1  2  3]]

>>> import Numeric

              
>>> f = iaread('cameraman.pgm')

              
>>> iashow(f)
(256, 256) Min= 0 Max= 251 Mean=137.066 Std=87.20
>>> iashow(iaptrans(f, Numeric.array(f.shape)/2))
(256, 256) Min= 0 Max= 251 Mean=137.066 Std=87.20
f iaptrans(f, Numeric.array(f.shape)/2)

Equation

Source Code

def iaptrans(f, t):
    from Numeric import asarray, Int, zeros
    f, t = asarray(f), asarray(t).astype(Int)
    h = zeros(2*abs(t) + 1)
    r0 = abs(t[0])
    c0 = abs(t[1])
    h[t[0]+r0, t[1]+c0] = 1
    g = iapconv(f, h).astype(f.typecode())
    return g
    

See also

iapconv 2D Periodic convolution.
[iaresize] [Up] [iadct] http://www.python.org