コード例 #1
0
    nb.nbshow()
    print('teste')
    get_ipython().magic('timeit ptrans(f,np.array(f.shape)//3)')
    get_ipython().magic('timeit ia.ptrans(f,np.array(f.shape)//3)')


# In[34]:

def dftshift(f):
    return ptrans(f, np.array(f.shape)//2)


# In[49]:

def idftshift(f):
    return ptrans(f, np.ceil(-np.array(np.shape(f))/2).astype(np.int))


# In[48]:

f = mpimg.imread('../data/cameraman.tif')
F = ia.dft(f)
Fs = ia.dftshift(F)
Fs1 = dftshift(F)
iFs1 = idftshift(Fs1)
ia.adshow(ia.dftview(F))
ia.adshow(ia.dftview(Fs))
ia.adshow(ia.dftview(Fs1))
ia.adshow(ia.dftview(iFs1))

コード例 #2
0
ファイル: dftview.py プロジェクト: pspalmirasara/ea979
    ea979path = os.path.abspath('../../')
    if ea979path not in sys.path:
        sys.path.append(ea979path)
    import ea979.src as ia

# ### Example 1

# In[2]:

if testing:
    import matplotlib.image as mpimg
    import numpy.fft as FFT
    f = mpimg.imread('../data/cameraman.tif')
    ia.adshow(f, "Original 2D image - Cameraman")
    F = FFT.fft2(f)
    Fv = ia.dftview(F)
    ia.adshow(Fv, "Cameraman DFT optical spectrum")

# ## Equation
#
#
# $$ \begin{matrix}
#     Gaux &=& \log(|F_{xc,yc}| + 1)\\xc     &=& \lfloor W/2 \rfloor \\yc     &=& \lfloor H/2 \rfloor\\ G &=& Gaux|_0^{255}
# \end{matrix} $$

# In[3]:

if testing:
    print('testing dftview')
    print(
        repr(
コード例 #3
0
    F = ia.dft(f)  # proposed dft
    F1 = np.fft.fftn(f)  # numpy dft

    print('ia.dft:', '\n', F.round(2), '\n')
    print('fft.fftn:', '\n', F1.round(2), '\n')
    print('Equal Results? (max error)', abs(F1 - F).max())

# ### Image example: 2d circle

# In[5]:

if testing:
    f = ia.circle([256, 256], 10, [129, 129])
    ia.adshow(f)
    F = ia.dft(f)
    Fv = ia.dftview(F)
    ia.adshow(Fv)

# ### Image example: 3d square

# In[6]:

if False:  #testing:

    f = np.zeros((25, 30, 40))
    f[10:15, 20:26, 21:27] = 1
    F = ia.dft(f)
    ia.adshow(ia.normalize(ia.mosaic(f, 5)), 'Original Image')
    ia.adshow(ia.mosaic(ia.dftview(F), 5), 'Fourier Transformation')

# ### Comparison with other implementations
コード例 #4
0
# In[4]:

if False:  #testing:
    import matplotlib.image as mpimg

    f = mpimg.imread('../data/cameraman.tif')
    F = ia.dft(f)
    print(F.shape)
    H = ia.circle(F.shape, 50, [F.shape[0] / 2, F.shape[1] / 2])
    H = ia.normalize(H, [0, 1])
    FH = F * ia.idftshift(H)
    print(ia.isdftsym(FH))
    g = ia.idft(FH)
    ia.adshow(f)
    ia.adshow(ia.dftview(F))
    ia.adshow(ia.normalize(H, [0, 255]))
    ia.adshow(ia.dftview(FH))
    ia.adshow(ia.normalize(abs(g)))

# ## Equation
#
# $$ \begin{matrix}
#     f(x) &=& \frac{1}{N}\sum_{u=0}^{N-1}F(u)\exp(j2\pi\frac{ux}{N}) \\ & & 0 \leq x < N, 0 \leq u < N \\ \mathbf{f}          &=& \frac{1}{\sqrt{N}}(A_N)^* \mathbf{F}
# \end{matrix} $$

# $$ \begin{matrix}
# f(x,y) &=& \frac{1}{NM}\sum_{u=0}^{N-1}\sum_{v=0}^{M-1}F(u,v)\exp(j2\pi(\frac{ux}{N} + \frac{vy}{M})) \\ & & (0,0) \leq (x,y) < (N,M), (0,0) \leq (u,v) < (N,M) \\
#     \mathbf{f} &=& \frac{1}{\sqrt{NM}} (A_N)^* \mathbf{F} (A_M)^*
# \end{matrix} $$
コード例 #5
0
    get_ipython().system(' jupyter nbconvert --to python bwlp.ipynb')
    import numpy as np
    import sys, os
    ea979path = os.path.abspath('../../')
    if ea979path not in sys.path:
        sys.path.append(ea979path)
    import ea979.src as ia

# ### Example 1

# In[2]:

if testing:

    H2_10 = ia.bwlp([100, 100], 2, 2)  # cutoff period: 2 pixels, order: 10
    ia.adshow(ia.dftview(H2_10))

# In[3]:

if testing:
    H4_1 = ia.bwlp([100, 100], 4, 1)  # cutoff period: 4, order: 1
    ia.adshow(ia.dftview(H4_1))

# In[4]:

if testing:
    H8_100 = ia.bwlp([100, 100], 8, 100)  # cutoff period: 8, order: 100
    ia.adshow(ia.dftview(H8_100))

# In[5]:
コード例 #6
0
ファイル: isccsym.py プロジェクト: pspalmirasara/ea979
                                                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))))

# ### Image Example: circular filter

# 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))

# ### Image Example 2: retangular filter

# 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))