def timeChallenge(): im = io.imread('zebra.png') t1=time.time() a3.gaussianBlur(im,2, 3) print time.time()-t1, 'seconds for Gaussian Blur' t2=time.time() a3.convolve(im, a3.gauss2D()) print time.time()-t2, 'seconds for Convolve'
def test_convolve_gauss(): im=io.imread('pru.png') gauss3=np.array([[1, 2, 1], [2, 4, 2], [1, 2, 1]]) kernel=gauss3.astype(float) kernel=kernel/sum(sum(kernel)) out=a3.convolve(im, kernel) io.imwrite(out, 'my_gaussblur.png')
import a3 import imageIO as io import time zebra = io.imread('zebra.png') print 'Begin separable Gaussian' start = time.time() zebra1 = a3.gaussianBlur(zebra, 3, 3) end = time.time() print end - start, 'seconds' print 'Begin 2D Gaussian' start = time.time() zebra2 = a3.convolve(zebra, a3.gauss2D(3, 3)) end = time.time() print end - start, 'seconds' io.imwrite(zebra1, 'zebraSeparableGaussian.png') io.imwrite(zebra2, 'zebra2DGaussian.png')
def test_equal(): im=io.imread('pru.png') out1=a3.convolve(im, a3.gauss2D()) out2=a3.gaussianBlur(im,2, 3) res=abs(out1-out2); return (sum(res.flatten())<0.1)
def test_gauss2D(): im=io.imread('pru.png') out=a3.convolve(im, a3.gauss2D()) io.imwrite(out, 'my_gauss2DBlur.png')
def test_horigauss(): im=io.imread('pru.png') kernel=a3.horiGaussKernel(2,3) out=a3.convolve(im, kernel) io.imwrite(out, 'my_horigauss.png')
def test_convolve_Sobel(): im=io.imread('pru.png') Sobel=np.array([[-1, 0, 1], [-2, 0, 2], [-1, 0, 1]]) out=a3.convolve(im, Sobel) io.imwrite(out, 'my_Sobel.png')
def test_convolve_deriv(): im=io.imread('pru.png') deriv=np.array([[-1, 1]]) out=a3.convolve(im, deriv) io.imwrite(out, 'my_deriv.png')