コード例 #1
0
ファイル: dctmatrix.py プロジェクト: pspalmirasara/ea979
    
    print("\nVisualiza propriedade A*A'= I:\n", B)


# ### Example 2

# In[2]:

if testing:
    get_ipython().magic('matplotlib inline')
    import matplotlib.pyplot as plt
    import matplotlib.image as mpimg
    import sys,os
    ea979path = os.path.abspath('../../')
    if ea979path not in sys.path:
        sys.path.append(ea979path)
    import ea979.src as ia
    A = ia.dctmatrix(128)
    ia.adshow(ia.normalize(A,[0,255]),'DCT 128x128')


# In[ ]:




# In[ ]:



コード例 #2
0
ファイル: isolines.py プロジェクト: pspalmirasara/ea979

# ## Examples

# In[1]:

testing = (__name__ == "__main__")
if testing:
    get_ipython().system(' jupyter nbconvert --to python isolines.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:
    f = ia.normalize(ia.bwlp([150, 150], 4, 1), [0, 255])
    f = f.astype('uint8')
    g = ia.isolines(f, 10, 3)
    g = g.astype('uint8')

    ia.adshow(f)
    ia.adshow(g)

# In[ ]:
コード例 #3
0
    import ea979.src as ia

# ### Example 1

# In[2]:

if testing:
    F = ia.rectangle([7, 9], [3, 2], [3, 4])
    print(F)

# - **Example 2**

# In[3]:

if testing:
    F = ia.rectangle([200, 300], [90, 120], [70, 120])
    ia.adshow(ia.normalize(F))

# ## Equation
#
# \begin{equation}
#   g(x,y)=\begin{cases}
#     1, & \text{if } x_\text{min} \leq x < x_\text{max} \text{ and } y_\text{min} \leq y < y_\text{max}.\\
#     0, & \text{otherwise}.
#   \end{cases}
# \end{equation}

# ## Contributions
#
# Lucas de Vasconcellos Teixeira, 1st semester 2017
コード例 #4
0
ファイル: cos.py プロジェクト: pspalmirasara/ea979
    get_ipython().system(' jupyter nbconvert --to python cos.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:

    f = ia.cos([128, 256], 100, np.pi / 3, 0)
    ia.adshow(ia.normalize(f, [0, 255]))

# ## Equation
#
# $$ \begin{matrix}
#     f(r,c) & = & cos( 2\pi (\frac{1}{T_r}r + \frac{1}{T_c}c) + \phi) \\
#     f(r,c) & = & cos( 2\pi (\frac{v}{H}r + \frac{u}{W}c) + \phi) \\
#     T_r    & = & \frac{T}{sin(\theta)} \\
#     T_c    & = & \frac{T}{cos(\theta)} \\
#     u   & = & \frac{W}{T_c} \\
#     v   & = & \frac{H}{T_r}
# \end{matrix} $$
#
# - $\theta$ is the direction of the cosine wave.
# - $T$ is the wave period, in number of pixels.
# - $T_r$ and $T_c$ are the period or wave length in the vertical and horizontal directions, respectively, in number of pixels.
コード例 #5
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))

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

# ### 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
コード例 #7
0
ファイル: ellipse.py プロジェクト: pspalmirasara/ea979
if testing:
    g = ia.ellipse([16, 16], [2, 4], [8, 8], np.pi * 0.25)
    print('g:\n', g.astype(int))

# ## Measuring time:

# In[4]:

if testing:
    from time import time
    t = time()
    g = ia.ellipse([300, 300], [90, 140], [150, 150], np.pi * 0.25)
    tend = time()
    print('Computational time (10k, 10k) is {0:.2f} seconds.'.format(tend - t))
    ia.adshow(g, "Ellipse")

# In[6]:

if testing:
    print('Computational time (10k, 10k) is:')
    get_ipython().magic(
        'timeit ia.ellipse([300,300], [90,140], [150,150], np.pi * 0.25)')

# ## Equation
#
# $$
#     \begin{matrix}
#         \frac{((x-center_x)\cos(\theta) - (y-center_y)\sin(\theta))^2}{r_x^2}
#             +
#         \frac{((x-center_x)\sin(\theta) - (y-center_y)\cos(\theta))^2}{r_y^2} <= 1
コード例 #8
0
ファイル: ramp.py プロジェクト: pspalmirasara/ea979
if testing:
    F = ia.ramp([5,7], 3, [4,10])
    print(F)
    F = ia.ramp((1,5,7),(0,3,0), [0,0,4,10,0,0])
    print(F)
    F = ia.ramp([1,5,7],[3,0,0], [4,10,0,0,0,0])
    print(F)


# - **Image example**

# In[4]:

if testing:
    F = ia.ramp([1,200,300], [0,10,0], [0,0,0,255,0,128])
    ia.adshow(ia.normalize(F.reshape(200,300)))


# In[6]:

if testing:
    F = ia.ramp([200,300], 10, [0,255])
    ia.adshow(ia.normalize(F))


# In[7]:

if testing:
    F = ia.ramp([1,200,300], [10,0,0], [0,255,0,0,0,0])
    ia.adshow(ia.normalize(F.reshape(200,300)))
コード例 #9
0
    print(np.round(g.real))

# 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} $$
コード例 #10
0
ファイル: pconv.py プロジェクト: pspalmirasara/ea979
                  [[17, 18, 19], [20, 21, 22], [23, 24, 25]]])

    print("\n Image Kernel (H): ")
    print(h)

    result = ia.pconv(f, h)
    print("\n Image Output - (G): ")
    print(result)

# ## Example with Image 2D

# In[6]:

if testing:
    f = mpimg.imread('../data/cameraman.tif')
    ia.adshow(f, title='a) - Original Image')
    h = np.array([[-1, -1, -1], [0, 0, 0], [1, 1, 1]])
    g = ia.pconv(f, h)
    print("\nPrewitt´s Mask")
    print(h)

    gn = ia.normalize(g, [0, 255])
    ia.adshow(gn, title='b) Prewitt´s Mask filtering')

    ia.adshow(ia.normalize(abs(g)),
              title='c) absolute of Prewitt´s Mask filtering')

# ## Equation
#
# $$ f(i) = f(i + kN), h(i)=h(i+kN)$$
#
コード例 #11
0
ファイル: log.py プロジェクト: pspalmirasara/ea979
    print('image dimensions = ', s)
    print('center of function = ', mu)
    print('spread factor =', sigma)
    print('Laplacian of Gaussian image : \n', F.round(2))

# #### Generating a image 2D 128x128, centered at 64x64 and sigma 4:

# In[5]:

if testing:
    s, mu, sigma = [128, 128], [64, 64], 4
    F = ia.log(s, mu, sigma)
    print('image dimensions = ', s)
    print('center of function = ', mu)
    print('spread factor =', sigma)
    ia.adshow(ia.normalize(F), 'Laplacian of Gaussian')

# #### Generating a image 2D 256x256, centered at 128x128 and sigma 20

# In[6]:

if testing:
    s, mu, sigma = [256, 256], [128, 128], 20
    F = ia.log(s, mu, sigma)
    print('image dimensions = ', s)
    print('center of function = ', mu)
    print('spread factor =', sigma)
    ia.adshow(ia.normalize(F), 'Laplacian of Gaussian')

# ## Measuring time:
コード例 #12
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]:
コード例 #13
0
    print(a)

# ### Example 4

# In[5]:

if testing:
    get_ipython().magic('matplotlib inline')
    import matplotlib.pyplot as plt
    import matplotlib.image as mpimg

    f = mpimg.imread('../data/cameraman.tif')
    h = np.array([[1, 2, 1], [0, 0, 0], [-1, -2, -1]])
    g = ia.conv(f, h)
    gn = ia.normalize(g, [0, 255])
    ia.adshow(f, title='input')
    ia.adshow(gn, title='filtered')

# ## Limitations
#
# Both image and kernel are internally converted to double.

# ## Equation
#
# $$ \begin{matrix}
#     (f \ast h)(r,c) &=&  \sum_{i=0}^{H-1} \sum_{j=0}^{W-1} f_{e}(i,j) h_{e}(r-i, c-j) \\
#     f_{e}(r,c) &=& \left\{ \begin{array}{llcl} f(r,c), & 0 \leq r \leq H_{f}-1 & and & 0 \leq r \leq W_f-1  \\
#                                                          0, & H_f \leq r \leq H-1 & or & W_f \leq c \leq W-1 \end{array}\right.\\
#     h_{e}(r,c) &=& \left\{ \begin{array}{llcl} f(r,c), & 0 \leq r \leq H_{h}-1 & and & 0 \leq r \leq W_h-1  \\
#                                                          0, & H_h \leq r \leq H-1 & or & W_h \leq c \leq W-1 \end{array}\right.\\
#     H & \geq & H_f + H_h - 1 \\
コード例 #14
0
    get_ipython().system(' jupyter nbconvert --to python circle.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

# ## Showing a numerical example

# In[2]:

if testing:
    F = ia.circle([5, 7], 2, [2, 3])
    print(F.astype(np.uint8))

# ## Printing the generated image

# In[4]:

if testing:
    import matplotlib.pyplot as plt
    import matplotlib.image as mpimg
    get_ipython().magic('matplotlib inline')
    f = ia.circle([200, 300], 90, [100, 150])
    ia.adshow(f, 'circle')

# ## Contributions
#
# Luis Antonio Prado, 1st semester 2017
コード例 #15
0
ファイル: dct.py プロジェクト: pspalmirasara/ea979
# In[2]:

if testing:
    get_ipython().magic('matplotlib inline')
    import matplotlib.pyplot as plt
    import matplotlib.image as mpimg
    import sys, os
    ea979path = os.path.abspath('../../')
    if ea979path not in sys.path:
        sys.path.append(ea979path)
    import ea979.src as ia

    r, c = np.indices((256, 256))

    f = ((r - 129)**2 + (c - 129)**2 < 10**2) * 255
    ia.adshow(ia.normalize(f), 'Imagem original')

    F = ia.dct(f)

    ia.adshow(ia.normalize(np.log(abs(F) + 1)), 'DCT')

# ### Example 3
# Compare with dft

# In[3]:

if testing:
    f = mpimg.imread('../data/cameraman.tif')

    nb = ia.nbshow(3)
    nb.nbshow(f, 'Imagem original')
コード例 #16
0
ファイル: dftview.py プロジェクト: pspalmirasara/ea979
    import sys, os
    import matplotlib.image as mpimg
    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')
コード例 #17
0
    f = np.arange(24).reshape(2, 3, 4)  # original image with generic axis
    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')
コード例 #18
0
if testing:
    f = np.array([[1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0],
                  [0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0]])

    g = polar(f, (6, 6))

    print(g)

# ### Example 2

# In[5]:

if testing:
    f = mpimg.imread("../data/cameraman.tif")
    ia.adshow(f, "Figure a) - Original Image")
    g = polar(f, (250, 250))
    ia.adshow(g, "Figure b) - Image converted to polar coordinates, 0 to 2*pi")

    g = polar(f, (250, 250), np.pi)
    ia.adshow(g, "Figure c) - Image converted to polar coordinates, 0 to pi")

# ### Example 3 - non square image

# In[6]:

if testing:
    f = mpimg.imread('../data/astablet.tif')
    ia.adshow(f, 'original')
    g = polar(f, (256, 256))
    ia.adshow(g, 'polar')
コード例 #19
0
    ea979path = os.path.abspath('../../')
    if ea979path not in sys.path:
        sys.path.append(ea979path)
    import ea979.src as ia
    get_ipython().magic('matplotlib inline')
    import matplotlib.pyplot as plt
    import matplotlib.image as mpimg

# ### Example 1

# In[3]:

if testing:
    tables = ['gray', 'hsv', 'hot', 'cool', 'copper', 'pink', 'bone']
    r, f = np.indices((10, 256), 'uint8')
    ia.adshow(f, 'gray scale')

    for table in tables:
        cm = ia.colormap(table)
        g = ia.applylut(f, cm)
        g = g.astype('uint8')
        if len(g.shape) == 3:
            g = g.transpose(1, 2, 0)
        ia.adshow(g, table)

# ### Example 2
#
# Plotting the colormap table

# In[4]:
コード例 #20
0
if testing:
    np.set_printoptions(suppress=True, precision=4)
    A = ia.haarmatrix(4)
    print('Visualiza matriz haar 4x4:\n',A)
    B = np.dot(A,np.transpose(A))
    print("\nVisualiza propriedade A*A'= I:\n", B)


# ### Example 2

# In[3]:

if testing:
    
    A = ia.haarmatrix(128)
    ia.adshow(ia.normalize(A),'Haar matrix 128x128')


# ### Example 3

# In[4]:

if testing:
    f = mpimg.imread('../data/cameraman.tif')
    
    A = ia.haarmatrix(f.shape[0])
    B = ia.haarmatrix(f.shape[1])
    F = np.dot(np.dot(A, f), np.transpose(B))
    
    nb = ia.nbshow(2)
    nb.nbshow(f,'Imagem original')
コード例 #21
0
ファイル: phasecorr.py プロジェクト: pspalmirasara/ea979
    # 2D example
    f1 = mpimg.imread("../data/cameraman.tif")
    noise = np.random.rand(f1.shape[0], f1.shape[1])
    f2 = ia.normalize(ia.ptrans(f1, (-1, 50)) + 300 * noise)
    g1 = ia.phasecorr(f1, f2)
    i = np.argmax(g1)
    row, col = np.unravel_index(i, g1.shape)
    v = g1[row, col]
    print(np.array(f1.shape) - np.array((row, col)))

# In[ ]:

if testing:
    print('max at:(%d, %d)' % (row, col))

    ia.adshow(ia.normalize(f1), "input image")
    ia.adshow(ia.normalize(f2), "input image")
    ia.adshow(ia.normalize(g1),
              "Correlation peak at (%d,%d) with %d" % (row, col, v))

# ### Exemplo 3

# Show how to perform Template Matching using phase correlation.

# In[ ]:

if testing:
    # 2D example
    w1 = f1[27:69, 83:147]

    h3 = np.zeros_like(f1)