In [1]:
    
import numpy as np
def isccsym2(F):
    if len(F.shape) == 1: F = F[np.newaxis,np.newaxis,:] 
    if len(F.shape) == 2: F = F[np.newaxis,:,:] 
    n,m,p = F.shape
    x,y,z = np.indices((n,m,p))
    Xnovo = np.mod(-1*x,n) 
    Ynovo = np.mod(-1*y,m)
    Znovo = np.mod(-1*z,p)  
    aux = np.conjugate(F[Xnovo,Ynovo,Znovo])
    return (abs(F-aux)<10E-4).all()
    
In [2]:
    
def isccsym(F):
    import ia898.src as ia
    
    if len(F.shape) == 1: F = F[np.newaxis,np.newaxis,:] 
    if len(F.shape) == 2: F = F[np.newaxis,:,:] 
    n,m,p = F.shape
    
    return(abs(F-np.conjugate(ia.ptrans(F[::-1,::-1,::-1],(1,1,1))))<10E-4).all()
    
In [11]:
    
testing = (__name__ == "__main__")
if testing:
    ! jupyter nbconvert --to python isccsym.ipynb
    import numpy as np
    import sys,os
    ia898path = os.path.abspath('../../')
    if ia898path not in sys.path:
        sys.path.append(ia898path)
    import ia898.src as ia
    
    import matplotlib.image as mpimg
    
    
In [2]:
    
if testing:
    F = np.arange(5)
    print('Is 1d odd dimension vetor symmetric?',ia.isccsym(F),'\n')
    F =  np.arange(6)
    print('Is 1d even dimension vetor symmetric?',ia.isccsym(F),'\n')
    F = np.array( [1j,1j,0,1j,1j] )
    print('Is 1d even dimension vetor symmetric?',ia.isccsym(F),'\n')
    
    
In [3]:
    
if testing:
    F = np.array( [ [0,1,1], 
                    [2,4,3],
                    [2,3,4]] )
    print('Is function F symmetric?',ia.isccsym(F),'\n')
    
    
In [4]:
    
if testing:
    F = np.array([ [ 0j,1j,-1j], 
                   [ 2j,4j,-3j],
                   [-2j,3j,-4j]] )
    print('Is function F symmetric?',ia.isccsym(F),'\n')
    
    F = np.array( [ [ 2j,1j,-1j], 
                    [ 2j,4j,-3j],
                    [-2j,3j,-4j]] )
    print('Is function F symmetric?',ia.isccsym(F),'\n')
    
    
In [5]:
    
if testing:        
    print('Is this function symmetric?')
    print(ia.isccsym(np.fft.fft2(np.random.rand(100,100)))) # dimension variation
    print(ia.isccsym(np.fft.fft2(np.random.rand(101,100))))
    print(ia.isccsym(np.fft.fft2(np.random.rand(101,101))))
    
    
In [14]:
    
if testing:
    img = mpimg.imread('../data/cameraman.tif')
    F = ia.dft(img)
    imgc = 1 * ia.circle(img.shape, 50, [img.shape[0]/2, img.shape[1]/2])  
    imgct = ia.ptrans(imgc, np.array(imgc.shape)//2)
    ia.adshow(ia.normalize(imgct),'circular filter')
    res = F * imgct
    ia.adshow(ia.dftview(res))
    print('Is this filter symmetric?', ia.isccsym(res))
    
    
    
    
In [17]:
    
if False: # testing:
    mquadra = ia.rectangle(img.shape, [50,50], [img.shape[0]/2, img.shape[1]/2])
    ia.adshow(mquadra,'RETANGULO')
    mquadra = ia.ptrans(mquadra, array(mquadra.shape)/2)
    ia.adshow(ia.normalize(mquadra),'retangular filter')
    mfiltrada = F * mquadra                                        
    
    print('Is this filter symmetric?', ia.isccsym(mfiltrada))
    
In [ ]: