def imresize(f, size):
    '''
    Resize an image
    Parameters
    ----------
        f: input image
        size: integer, float or tuple
            - integer: percentage of current size
            - float: fraction of current size
            - tuple: new dimensions
    Returns
    -------
        output image resized 
    '''
    H,W = f.shape
    if(type(size) is float): 
        G = np.zeros(((int)(H*size),(int)(W*size)),'complex128')
    elif(type(size) is int): 
        G = np.zeros(((int)(H*size/100),(int)(W*size/100)),'complex128')
    elif(type(size) is tuple):
        G = np.zeros(size,'complex128')
    
    F = np.fft.fft2(f)
    H,W = G.shape
     
    np.set_printoptions(precision=2)
    
    if(H%2==0):
        Hp = H//2
        Hn = H//2 - 1
    else:
        Hp = H//2 + 1
        Hn = H//2
        
    if(W%2==0):
        Wp = W//2
        Wn = W//2 - 1
    else:
        Wp = W//2 + 1
        Wn = W//2
    
    G[:Hp,:Wp] = F[:Hp,:Wp]
    G[-Hn:,:Wp]  = F[-Hn:,:Wp]
    G[:Hp,-Wn:]  = F[:Hp,-Wn:]    
    G[-Hn:,-Wn:] = F[-Hn:,-Wn:]
    
    return ia.normalize(np.fft.ifft2(G).real)
ia898path = os.path.abspath('/home/lotufo')
if ia898path not in sys.path:
    sys.path.append(ia898path)
import ia898.src as ia

# ## Considerem esta imagem para fazer a demonstração
#
# Uma linha branca foi adicionada à imagem para poder ver melhor o efeito
# da redução.

# In[13]:

nb = ia.nbshow(2)
f = mpimg.imread('../../lotufo/ia898/data/gull.pgm')
r, c = np.indices(f.shape)
y = ia.normalize(r == c * 2 - 150)
f = np.maximum(f, y)
y = ia.normalize(r == c * 2 - 151)
f = np.maximum(f, y)
y = ia.normalize(r == c * 2 - 152)
f = np.maximum(f, y)
nb.nbshow(f)
nb.nbshow()

# ## Esta é a redução sem interpolação

# In[14]:

g = f[::4, ::4]
nb.nbshow(f, '%s' % (f.shape, ))
nb.nbshow(g, '%s' % (g.shape, ))
Ejemplo n.º 3
0
# -75 e 75 e os valores para as colunas, inteiros no intervalo [-100,100]:
#
# $$    f(r,c) = r \ c $$
# $$    \text{para} \ r  \in  [-75,75] $$
# $$                  c  \in  [-100,100]$$
#
#
# No exemplo a seguir é utilizado a função `arange` para gerar os vetores de coordenadas. Para melhorar
# a visualização foi utilizada a função `ia636:iaisolines iaisolines` que permite visualizar os
# pixels de mesmo valores (isolinhas) da imagem gerada com uma cor destacada.

# In[4]:

r, c = np.meshgrid(np.arange(-75, 75), np.arange(-100, 100), indexing='ij')
f = r * c
fn = ia.normalize(f)
ia.adshow(fn, 'Ponto de sela')
#ia.adshow(ia.iaisolines(fn,9), 'Ponto de sela com isolinhas')

# ## Outras images criadas com matrizes de índices
#
# Implemente alguma das seguintes funções da toolbox `ia636:MainPage` que também foram feitas desta forma:
#
# - [ia636:iacos](http://adessowiki.fee.unicamp.br/adesso-1/wiki/ia636/iacos/view/) - Cossenóide
# - [ia636:iacircle](http://adessowiki.fee.unicamp.br/adesso-1/wiki/ia636/iacircle/view/) - Círculo
# - [ia636:iarectangle](http://adessowiki.fee.unicamp.br/adesso-1/wiki/ia636/iarectangle/view/) - Retângulo
# - [ia636:ialog](http://adessowiki.fee.unicamp.br/adesso-1/wiki/ia636/ialog/view/) - Laplaciano da gaussiana

# ## Atividades
#
# - Faça a seguir um programa qualquer de geração de imagem a partir de uma equação:
Ejemplo n.º 4
0
np.set_printoptions(precision=2)
nb = ia.nbshow(1)
nb.nbshow(f, 'Imagem original')
nb.nbshow()

# ## skimage.transform.rescale

# In[4]:

# skimage.transform.rescale

skimage_rescale1 = skimage.transform.rescale(f, scale1)
skimage_rescale2 = skimage.transform.rescale(f, scale2)

nb = ia.nbshow(3)
nb.nbshow(ia.normalize(skimage_rescale2), 'skimage_rescale x%s' % (scale2))
nb.nbshow(f, 'Imagem original')
nb.nbshow(ia.normalize(skimage_rescale1), 'skimage_rescale x%s' % (scale1))
nb.nbshow()

print("\nskimage x0.5:\n", skimage_rescale2[:8, :8])
print("f:\n", f[:8, :8])
print("\nskimage x2:\n", skimage_rescale1[:8, :8])

# ## skimage.transform.resize

# In[5]:

# skimage.transform.resize
skimage_resize1 = skimage.transform.resize(f, (H * scale1, W * scale1))
skimage_resize2 = skimage.transform.resize(f, ((int)(H * scale2),
if testing:
    f = np.arange(24).reshape(4, 6)
    F = ia.dft(f)
    g = ia.idft(F)
    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} $$
#F = F[H//2-U:H//2+U,W//2-V:W//2+V]
#F1 = F1[H//2-U:H//2+U,W//2-V:W//2+V]

nb = ia.nbshow(2)
nb.nbshow(F,'F')
nb.nbshow(F1,'F1')
nb.nbshow()

Fp = ia.polar(F,F.shape)
F1p = ia.polar(F1,F1.shape)

Fp = Fp[0:-20,:]
F1p = F1p[0:-20,:]

nb = ia.nbshow(2)
nb.nbshow(ia.normalize(Fp),'polar Fp')
nb.nbshow(ia.normalize(F1p),'polar F1p')
nb.nbshow()


# ### Correlação de fase entre as polares dos espectros para identificar o ângulo de rotação

# In[13]:

Pc = ia.phasecorr(Fp,F1p)
peak = np.unravel_index(np.argmax(Pc), Pc.shape)
ang = (float(peak[1])/Pc.shape[1])*360
print('angle:',ang)


# ## Corrigir a rotação
    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')
Ejemplo n.º 8
0
pl4 = plt.scatter(Y4[:, 0], Y4[:, 1], marker='<', color=colors[4])
pl5 = plt.scatter(Y5[:, 0], Y5[:, 1], marker='>', color=colors[5])
pl6 = plt.scatter(Y6[:, 0], Y6[:, 1], marker='h', color=colors[6])
pl7 = plt.scatter(Y7[:, 0], Y7[:, 1], marker='*', color=colors[7])
pl8 = plt.scatter(Y8[:, 0], Y8[:, 1], marker='^', color=colors[8])
pl9 = plt.scatter(Y9[:, 0], Y9[:, 1], marker='D', color=colors[9])

plt.legend((pl0, pl1, pl2, pl3, pl4, pl5, pl6, pl7, pl8, pl9),
           ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9'),
           loc='best',
           ncol=3,
           fontsize=8)

plt.show()

# ## Reconstrução parcial

# In[36]:

Ypr = np.zeros_like(Xr)
Ypr[:, :2] = Y
Xpr = Ypr.dot(V.T) + mu
Xpr = ia.normalize(Xpr)

nb = ia.nbshow(10)
for i in range(80):
    f = Xpr[i, :].reshape(16, 10)
    label = dt[i, 0]
    nb.nbshow(f, label)
nb.nbshow()
if testing:
    get_ipython().system(' jupyter nbconvert --to python hadamard.ipynb')
    import numpy as np
    import sys, os
    import matplotlib.image as mpimg
    ia898path = os.path.abspath('../../')
    if ia898path not in sys.path:
        sys.path.append(ia898path)
    import ia898.src as ia

# In[3]:

if testing:
    f = mpimg.imread('../data/cameraman.tif')
    F = ia.hadamard(f)
    nb = ia.nbshow(2)
    nb.nbshow(f)
    nb.nbshow(ia.normalize(np.log(abs(F) + 1)))
    nb.nbshow()

# ## Measuring time:

# In[ ]:

if testing:
    f = mpimg.imread('../data/cameraman.tif')
    print('Computational time is:')
    get_ipython().run_line_magic('timeit', 'ia.hadamard(f)')

# In[ ]:
# 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
    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)
Ejemplo n.º 12
0
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)))

# ### Image example - 3D
Ejemplo n.º 13
0
    get_ipython().run_line_magic('matplotlib', 'inline')
    import matplotlib.image as mpimg

# ### Example 1

# Show that the point of maximum correlation for two equal images is the origin.
#
#

# In[4]:

if testing:
    # 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))
Ejemplo n.º 14
0
# In[9]:

if testing:
    get_ipython().run_line_magic('matplotlib', 'inline')
    import matplotlib.pyplot as plt
    import matplotlib.image as mpimg
    import sys, os
    ia898path = os.path.abspath('/home/lotufo')
    if ia898path not in sys.path:
        sys.path.append(ia898path)
    import ia898.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[10]:

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

    nb = ia.nbshow(3)
    nb.nbshow(f, 'Imagem original')
    get_ipython().system(' jupyter nbconvert --to python dftmatrix.ipynb')
    import numpy as np
    import sys, os
    import matplotlib.image as mpimg
    ia898path = os.path.abspath('../../')
    if ia898path not in sys.path:
        sys.path.append(ia898path)
    import ia898.src as ia

# ### Example 1

# In[2]:

if testing:
    A = ia.dftmatrix(128)
    ia.adshow(ia.normalize(A.real), 'A.real')
    ia.adshow(ia.normalize(A.imag), 'A.imag')

# Example 2
# ---------

# In[3]:

if testing:
    A = ia.dftmatrix(4)
    print('A=\n', A.round(1))
    print('A-A.T=\n', A - A.T)
    print((np.abs(np.linalg.inv(A) - np.conjugate(A))).max() < 10E-15)

# ### Example 3
#
    print('gamma mat:\n', g[2])

# ## Teste com imagens

# In[5]:

if testing:
    f = mpimg.imread('/home/lotufo/ia898/data/cameraman.tif')
    t = f[10:60, 90:130]
    g = tm_fncc(f, t)
    x, y = g[0]

    nb = ia.nbshow(3)
    nb.nbshow(f, 'Imagem original')
    nb.nbshow(t, 'Template')
    nb.nbshow(ia.normalize(g[2]), 'Gamma')
    nb.nbshow()

    plt.figure(2)
    fig, ax = plt.subplots(1)
    plt.title('Template Matching')
    ax.imshow(f, cmap='gray')
    rect = patches.Rectangle((y - t.shape[1] - 1, x - t.shape[0] - 1),
                             t.shape[1],
                             t.shape[0],
                             linewidth=1,
                             edgecolor='r',
                             facecolor='none')
    ax.add_patch(rect)
    plt.show()
if testing:
    f = mpimg.imread('../data/cameraman.tif')

    g = ia.gshow(f, f > 230)

    nb = ia.nbshow(2)
    nb.nbshow(f, 'Original image')
    nb.nbshow(g, 'Pixels with values above 230 are shown in red')
    nb.nbshow()

# In[4]:

if testing:
    f = ia.gaussian((256, 256), np.transpose([[128, 128]]),
                    [[50 * 50, 0], [0, 80 * 80]])
    fn = ia.normalize(f, [0, 255])

    f1 = ia.gshow(fn, fn > 20, fn > 30, fn > 40, fn > 50, fn > 60, fn > 70)

    nb = ia.nbshow(2)
    nb.nbshow(fn, 'Original image')
    nb.nbshow(f1, 'Overlaid image')
    nb.nbshow()

# ## Reference

# - [Function iagshow](http://adessowiki.fee.unicamp.br/adesso/wiki/ia636/iagshow/view/)

# ## Contributions

# - Tiago Dezotti, 1. sem 2017.

# ## Examples

# In[1]:

testing = (__name__ == "__main__")
if testing:
    get_ipython().system(' jupyter nbconvert --to python isolines.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

# ### 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[ ]:
Ejemplo n.º 19
0
    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')
        sys.path.append(ia898path)
    import ia898.src as ia
    
    get_ipython().run_line_magic('matplotlib', 'inline')
    import matplotlib.pyplot as plt


# ### Example 1 - Numeric 2-dimensional

# In[2]:


if testing:
    f = ia.gaussian((8, 4), np.transpose([[3, 1]]), [[1, 0], [0, 1]])
    print('f=\n', np.array2string(f, precision=4, suppress_small=1))
    g = ia.normalize(f, [0, 255]).astype(np.uint8)
    print('g=\n', g)


# ## Example 2 - one dimensional signal

# In[3]:


# note that for 1-D case, the tuple has extra ,
# and the covariance matrix must be 2-D
if testing:
    f = ia.gaussian( (100,), 50, [[10*10]]) 
    g = ia.normalize(f, [0,1])
    plt.plot(g)
    plt.show()
    print('m:\n', m)
    print('t:\n', t)

# ### Image examples

# ### Example 1.

# In[3]:

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

    (g, a) = ia.sobel(f)

    nb = ia.nbshow(2)
    nb.nbshow(ia.normalize(g), title='Sobel')
    nb.nbshow(ia.normalize(np.log(g + 1)), title='Log of sobel')
    nb.nbshow()

# ### Example 2.

# In[4]:

if testing:
    f = ia.circle([200, 300], 90, [100, 150])
    m, t = ia.sobel(f)

    dt = np.select([m > 2], [t])

    nb = ia.nbshow(3)
    nb.nbshow(f, title='Image f')
    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)$$
#
# $$    mod(i,N) = i - N \lfloor \frac{i}{N} \rfloor $$
#
# $$    (f \ast_W h) (col) = \sum_{cc=0}^{W-1} f(mod(col-cc,W)) h(cc)$$
#
# $$    (f \ast_{(H,W)} h) (row,col) = \sum_{rr=0}^{H-1} \sum_{cc=0}^{W-1} f(mod(row-rr,H), mod(col-cc,W)) h(rr,cc)$$
#
if testing:
    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

# ### Example 1

# In[2]:

if testing:
    f = np.array([100., 500., 1000.])
    g1 = ia.normalize(f, [0, 255])
    print(g1)

# In[3]:

if testing:
    g2 = ia.normalize(f, [-1, 1])
    print(g2)

# In[4]:

if testing:
    g3 = ia.normalize(f, [0, 1])
    print(g3)

# In[5]:
Ejemplo n.º 24
0
    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

# In[7]:

if testing:
    import matplotlib.image as mpimg

    f = mpimg.imread('../data/cameraman.tif')
    get_ipython().run_line_magic('time', 'F1 = ia.dft(f)')
    get_ipython().run_line_magic('time', 'F2 = np.fft.fft2(f)')
    print('Max difference is:', np.abs(F1 - F2).max())

# ## Equation
def dftview(F):
    import ia898.src as ia

    FM = ia.dftshift(np.log(np.abs(F)+1))
    return ia.normalize(FM).astype(np.uint8)
Ejemplo n.º 26
0
    s = ia.sat(f)
    print('f (input):\n', f)
    print('s (output):\n', s)
    a = ia.satarea(s, (0, 0), (3, 8))
    print('area:', a)

# ### Image example
#

# In[3]:

if testing:
    f = mpimg.imread('../data/lenina.pgm')[::2, ::2]
    nb = ia.nbshow(2)
    nb.nbshow(f, 'Original Image')
    nb.nbshow(ia.normalize(ia.sat(f)), 'Integral Image')
    nb.nbshow()

# ### Calculating a rectangle area with SAT (Summed Area Table)

# In[4]:

if testing:
    f = mpimg.imread('../data/lenina.pgm')[::2, ::2]
    H, W = f.shape
    s = ia.sat(f)
    a0 = ia.satarea(s, (0, 0), (H - 1, W - 1))
    atopleft = ia.satarea(s, (0, 0), (H // 2 - 1, W // 2 - 1))
    abotleft = ia.satarea(s, (H // 2, 0), (H - 1, W // 2 - 1))
    atopright = ia.satarea(s, (0, W // 2), (H // 2 - 1, W - 1))
    abotright = ia.satarea(s, (H // 2, W // 2), (H - 1, W - 1))
    ia898path = os.path.abspath('../../')
    if ia898path not in sys.path:
        sys.path.append(ia898path)
    import ia898.src as ia


# ## Examples
# 
# ### Example 1

# In[2]:


if testing:
    A = ia.hadamardmatrix(128)
    ia.adshow(ia.normalize(A, [0, 255]))


# ### Example 2

# In[4]:


if testing:
    A = ia.hadamardmatrix(4)
    print(A)
    print(np.dot(A, np.transpose(A)))


# ## Measuring time:
if testing:
    import sys,os
    get_ipython().system(" jupyter nbconvert --to 'python' imresize")

    path = os.path.abspath('/etc/jupyterhub/ia898_1s2017/d191122/Aula_10/')
    if path not in sys.path:
        sys.path.append(path)
    import imresize as imrsz


# In[4]:

if testing:
    f = mpimg.imread('/home/lotufo/ia898/data/gull.pgm')
    r,c = np.indices(f.shape)
    y = ia.normalize(r == c*2 - 150)
    f = np.maximum(f, y)
    y = ia.normalize(r == c*2 - 151)
    f = np.maximum(f, y)
    y = ia.normalize(r == c*2 - 152)
    f = np.maximum(f, y)


# In[5]:

if testing:
    # Testing tupla 
    scale = (179,178)

    g = imrsz.imresize(f, scale)
    g2 = scipy.misc.imresize(f,scale)
# In[3]:

if testing:
    np.set_printoptions(suppress=True, precision=4)
    A = ia.dctmatrix(4)
    print('Visualiza matriz DCT 4x4:\n', A)
    B = np.dot(A, np.transpose(A))

    print("\nVisualiza propriedade A*A'= I:\n", B)

# ### Example 2

# In[4]:

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

# In[ ]:

# In[ ]:
# ### Example 1

# In[3]:

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

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

    g07 = ia.logfilter(f, 0.7)

    nb = ia.nbshow(3)
    nb.nbshow(f, 'Imagem original')
    nb.nbshow(ia.normalize(g07), 'LoG filter')
    nb.nbshow(g07 > 0, 'positive values')
    nb.nbshow()

# ### Example 2

# In[4]:

if testing:
    g5 = ia.logfilter(f, 5)
    g10 = ia.logfilter(f, 10)

    nb = ia.nbshow(2, 2)
    nb.nbshow(ia.normalize(g5), 'sigma=5')
    nb.nbshow(g5 > 0, 'positive, sigma=5')
    nb.nbshow(ia.normalize(g10), 'sigma=10')