def isccsym(F): import ea979.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()
get_ipython().magic('timeit ptrans(l,3)') get_ipython().magic('timeit ia.ptrans(l,3)') print('teste 2 d') get_ipython().magic('timeit ptrans(x,[1,2])') get_ipython().magic('timeit ia.ptrans(x,[1,2])') print('teste 3 d') get_ipython().magic('timeit ptrans(x3d,[1,2,1])') get_ipython().magic('timeit ia.ptrans(x3d,[1,2,1])') # In[50]: if testing: f = mpimg.imread('../data/cameraman.tif') g1= ptrans(f, np.array(f.shape)//3) g2 =ia.ptrans(f, np.array(f.shape)//3) nb = ia.nbshow(2) nb.nbshow(g1,title='ptrans') nb.nbshow(g2,title='ia.ptrans') 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)
# ### Example 3 # Compare with dft # In[3]: if testing: f = mpimg.imread('../data/cameraman.tif') nb = ia.nbshow(3) nb.nbshow(f, 'Imagem original') F1 = np.fft.fft2(f) F2 = ia.dct(f) nb.nbshow( ia.normalize( np.log( np.abs(ia.ptrans(F1, (f.shape[0] // 2, f.shape[1] // 2)) + 1))), 'DFT') nb.nbshow(ia.normalize(np.log(abs(F2) + 1)), 'DCT') nb.nbshow() print('Tempo de execução DFT:') get_ipython().magic('%timeit F1 = np.fft.fft2(f)') print('\nTempo de execução DCT:') get_ipython().magic('%timeit F2 = ia.dct(f)') # ### Example 4 # Compare with scipy function # In[4]: if testing:
sys.path.append(ea979path) import ea979.src as ia # ### Example 1 # # Numeric examples in 2D and 3D. # In[3]: if testing: # 2D example f = np.arange(15).reshape(3, 5) print("Original 2D image:\n", f, "\n\n") print("Image translated by (0,0):\n", ia.ptrans(f, (0, 0)).astype(int), "\n\n") print("Image translated by (0,1):\n", ia.ptrans(f, (0, 1)).astype(int), "\n\n") print("Image translated by (-1,2):\n", ia.ptrans(f, (-1, 2)).astype(int), "\n\n") # In[4]: if testing: # 3D example f1 = np.arange(60).reshape(3, 4, 5) print("Original 3D image:\n", f1, "\n\n") print("Image translated by (0,0,0):\n", ia.ptrans(f1, (0, 0, 0)).astype(int), "\n\n") print("Image translated by (0,1,0):\n",
def dftshift(f): import ea979.src as ia return ia.ptrans(f, np.array(f.shape) // 2)
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)))) # ### 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')
get_ipython().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))