Skip to content

Commit

Permalink
Main: including examples with various kernels
Browse files Browse the repository at this point in the history
  • Loading branch information
ACELabA1 committed May 8, 2015
1 parent 2705dd4 commit 1a56e56
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions Homework_1/Problem1_4/MainConvolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,40 @@
import matplotlib.cm as cm #
from scipy import misc

import FnImConvolution

from FnImConvolution import FnImConvol


# Sample image
TestImage1 = misc.lena()

# Kernel: Sobel
Kernel = 0.125 * np.array([ [-1.0, 0.0, 1.0], [-2.0, 0.0, 2.0], [-1.0, 0.0, 1.0]] )
# Kernel
Kernel_1 = 0.125 * np.array([ [-1.0, 0.0, 1.0], [-2.0, 0.0, 2.0], [-1.0, 0.0, 1.0]] ) # 3x3
Kernel_2 = 1.0/256 * np.array( [ [1.0, 4.0, 6.0, 4.0, 1.0],
[4.0, 16.0, 24.0, 16.0, 4.0],
[6.0, 24.0, 36.0, 24.0, 6.0],
[4.0, 16.0, 24.0, 16.0, 4.0],
[1.0, 4.0, 6.0, 4.0, 1.0]]) # 5x5
Kernel_3 = np.array( [ [-1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0],
[-1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0],
[-1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0],
[-1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0],
[-1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0],
[-1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0],
[-1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0],
[-1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0] ] ) # 8x8

# 2D Convolution
print "Started!"
Result = FnImConvolution.FnImConvol( TestImage1, Kernel, 'mirror' )
print "Finished!"
Result_1 = FnImConvol( TestImage1, Kernel_1, 'zero' )
Result_2 = FnImConvol( TestImage1, Kernel_2, 'mirror' )
Result_3 = FnImConvol( TestImage1, Kernel_3, 'wrap' )

# Plot result
plt.imshow(Result, cmap=cm.Greys_r)
plt.figure('Kernel 1')
plt.imshow(Result_1, cmap=cm.Greys_r)

plt.figure('Kernel 2')
plt.imshow(Result_2, cmap=cm.Greys_r)

plt.figure('Kernel 3')
plt.imshow(Result_3, cmap=cm.Greys_r)
plt.show()

0 comments on commit 1a56e56

Please sign in to comment.