Skip to content

Instantly share code, notes, and snippets.

@erinkhoo
Created November 7, 2020 16:52
Show Gist options
  • Save erinkhoo/70abf7abcebeb57d1f5f5f076fa5fc13 to your computer and use it in GitHub Desktop.
Save erinkhoo/70abf7abcebeb57d1f5f5f076fa5fc13 to your computer and use it in GitHub Desktop.
def laplacian(sigma,image):
"""
sigma: Parameter controlling Gaussian blur
image: input greyscale image n x m
conv_laplacian: output image n x m to be returned,
result of convolution of image with laplacian of Gaussian
"""
# 1 dimension gaussian kernels (Integration scale)
K1,K2 = gauss_kernels(sigma)
# The below code is adopted from the Lession 1 slide 11
K1_derv_x = np.expand_dims(K1,axis=0)
K1_derv_y = np.transpose(K1_derv_x)
K2_derv_x = np.expand_dims(K2,axis=0)
K2_derv_y = np.transpose(K2_derv_x)
Gx = signal.convolve2d(image, K1_derv_x, mode='same')
GxLx = signal.convolve2d(Gx, K2_derv_x, mode='same')
Gy = signal.convolve2d(image, K1_derv_y, mode='same')
GyLy = signal.convolve2d(Gy, K2_derv_y, mode='same')
summed = GxLx+GyLy
conv_laplacian = (summed - np.min(summed)) / (np.max(summed) - np.min(summed))
return conv_laplacian
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment