(src, dst=None)
return dst
Rearrange the quadrants of Fourier image so that the origin is at
        the image center. Swaps quadrant 1 with 3, and 2 with 4.

        src and dst arrays must be equal size & type
Rearrange the quadrants of Fourier image so that the origin is at
        the image center. Swaps quadrant 1 with 3, and 2 with 4.
Rearrange the quadrants of Fourier image so that the origin is at the image center . Swaps quadrant 1 with 3 and 2 with 4 .
def shift_dft(src, dst=None):
    '''
        Rearrange the quadrants of Fourier image so that the origin is at
        the image center. Swaps quadrant 1 with 3, and 2 with 4.

        src and dst arrays must be equal size & type
    '''

    if dst is None:
        dst = np.empty(src.shape, src.dtype)
    elif src.shape != dst.shape:
        raise ValueError("src and dst must have equal sizes")
    elif src.dtype != dst.dtype:
        raise TypeError("src and dst must have equal types")

    if src is dst:
        ret = np.empty(src.shape, src.dtype)
    else:
        ret = dst

    h, w = src.shape[:2]

    cx1 = cx2 = w/2
    cy1 = cy2 = h/2

    # if the size is odd, then adjust the bottom/right quadrants
    if w % 2 != 0:
        cx2 += 1
    if h % 2 != 0:
        cy2 += 1

    # swap quadrants

    # swap q1 and q3
    ret[h-cy1:, w-cx1:] = src[0:cy1 , 0:cx1 ]   # q1 -> q3
    ret[0:cy2 , 0:cx2 ] = src[h-cy2:, w-cx2:]   # q3 -> q1

    # swap q2 and q4
    ret[0:cy2 , w-cx2:] = src[h-cy2:, 0:cx2 ]   # q2 -> q4
    ret[h-cy1:, 0:cx1 ] = src[0:cy1 , w-cx1:]   # q4 -> q2

    if src is dst:
        dst[:,:] = ret

    return dst
def shift_dft ( src , dst = None ) : if dst is None : dst = np . empty ( src . shape , src . dtype ) elif src . shape != dst . shape : raise ValueError ( "src and dst must have equal sizes" ) elif src . dtype != dst . dtype : raise TypeError ( "src and dst must have equal types" ) if src is dst : ret = np . empty ( src . shape , src . dtype ) else : ret = dst h , w = src . shape [ : 2 ] cx1 = cx2 = w / 2 cy1 = cy2 = h / 2 # if the size is odd, then adjust the bottom/right quadrants if w % 2 != 0 : cx2 += 1 if h % 2 != 0 : cy2 += 1 # swap quadrants # swap q1 and q3 ret [ h - cy1 : , w - cx1 : ] = src [ 0 : cy1 , 0 : cx1 ] # q1 -> q3 ret [ 0 : cy2 , 0 : cx2 ] = src [ h - cy2 : , w - cx2 : ] # q3 -> q1 # swap q2 and q4 ret [ 0 : cy2 , w - cx2 : ] = src [ h - cy2 : , 0 : cx2 ] # q2 -> q4 ret [ h - cy1 : , 0 : cx1 ] = src [ 0 : cy1 , w - cx1 : ] # q4 -> q2 if src is dst : dst [ : , : ] = ret return dst