# Nov. 14, 2013 # test separable filter on image data # http://scipy-lectures.github.io/advanced/image_processing/ # convolve1d(input, weights[, axis, output, ...]) #Calculate a one-dimensional convolution along the given axis. import numpy as np from scipy import ndimage import matplotlib.pyplot as plt import matplotlib.cm as cm plt.figure(1) flatten = True # convert to gray scale #testpix = ndimage.imread('arc-triumph.jpg', flatten) testpix = ndimage.imread('test128x128.bmp', flatten) plt.subplot(221) #use subplots plt.imshow(testpix, cmap = cm.Greys_r) # filter operations #testpix_f = ndimage.gaussian_filter(testpix, sigma=3) row_filt=[ 39.0 , 57.0, 64.0, 57.0, 39.0] #scale = np.sum(row_filt) # normalize #row_filt = np.round(256*np.multiply(1.0/scale,row_filt),1) print 'using row_filt=' + str(row_filt) #convolve rows testpix_f = np.round(ndimage.filters.convolve1d(testpix, row_filt, axis=1)/256,0) # axis 0 = y, 1 = x plt.subplot(222) plt.imshow(testpix_f, cmap = cm.Greys_r) # convolve columns testpix_f = np.round(ndimage.filters.convolve1d(testpix_f, row_filt, axis=0)/256,0) # axis 0 = y, 1 = x plt.subplot(223) plt.imshow(testpix_f, cmap = cm.Greys_r) # difference operation diff_image = testpix - testpix_f diff_image = np.add(127,0.5*diff_image) #diff_image = np.multiply(0.5, diff_image) plt.subplot(224) plt.imshow(diff_image, cmap = cm.Greys_r) block = False plt.show(block)