SIFT學習--第一話---高斯濾波器

Python code to demonstrate separable Gaussian filter on test128x128.bmp. from CS150 Fall 2013

安裝好Canopy之後就可以執行了。注意全路徑還是C盤,所以文件的地址要補全。

這個是結果:


# 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('F:/0InterviewCoding/test/py/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)



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章