import numpy as np import cv2 from matplotlib import pyplot as plt from convolve_np import convolve_np import time img = cv2.imread('images/jet.jpg', cv2.IMREAD_GRAYSCALE) height = img.shape[0] width = img.shape[1] Hx = 1 / 4 * np.array([[1, 0, -1], [2, 0, -2], [1, 0, -1]]) Hy = 1 / 4 * np.array([[-1, -2, -1], [0, 0, 0], [1, 2, 1]]) t0 = time.time() img_x = convolve_np(img, Hx) img_y = convolve_np(img, Hy) img_out = np.sqrt(np.power(img_x, 2) + np.power(img_y, 2)) img_out = (img_out / np.max(img_out)) * 255 t1 = time.time() print(t1 - t0) cv2.imwrite('images/edge_sobel.jpg', img_out) plt.imshow(img_out, cmap='gray', interpolation='bicubic') plt.xticks([]), plt.yticks([]) plt.show()
img = cv2.imread('images/jet.jpg', cv2.IMREAD_GRAYSCALE) height = img.shape[0] width = img.shape[1] Hx = np.array([[-1, 0, 1], [-2, 0, 2], [-1, 0, 1]]) Hy = np.array([[-1, -2, -1], [0, 0, 0], [1, 2, 1]]) t0 = time.time() img_x = convolve_np(img, Hx) / 8.0 img_y = convolve_np(img, Hy) / 8.0 img_out = np.sqrt(np.power(img_x, 2) + np.power(img_y, 2)) img_out = (img_out / np.max(img_out)) * 255 t1 = time.time() print(t1-t0) cv2.imwrite('images/edge_sobel.jpg', img_out) plt.imshow(img_out, cmap = 'gray', interpolation = 'bicubic') plt.xticks([]), plt.yticks([]) # to hide tick values on X and Y axis plt.show()
from convolve_np import convolve_np import edge_canny_get_orientation_sector as ors import edge_canny_is_local_max as locmax import edge_canny_trace_and_threshold as tt img = cv2.imread('images/butterfly.jpg', cv2.IMREAD_GRAYSCALE) height = img.shape[0] width = img.shape[1] # step 1: blur with Gaussian gauss = (1.0 / 57) * np.array([[0, 1, 2, 1, 0], [1, 3, 5, 3, 1], [ 2, 5, 9, 5, 2 ], [1, 3, 5, 3, 1], [0, 1, 2, 1, 0]]) img_blur = convolve_np(img, gauss) # step 2: compute gradient magnitude img_x = convolve_np(img_blur, np.array([[-0.5, 0, 0.5]])) img_y = convolve_np(img_blur, np.array([[-0.5], [0], [0.5]])) E_mag = np.sqrt(np.power(img_x, 2) + np.power(img_y, 2)) E_mag = (E_mag / np.max(E_mag)) * 255 # step 3: non-maximum suppression t_low = 4 E_nms = np.zeros((height, width)) for i in np.arange(1, height - 1): for j in np.arange(1, width - 1): dx = img_x[i, j] dy = img_y[i, j] s_theta = ors.get_orientation_sector(dx, dy)
import numpy as np from matplotlib import pyplot as plt from scipy import ndimage from convolve_np import convolve_np img = cv2.imread('../img/mano.jpg', cv2.IMREAD_GRAYSCALE) #Sovel height = img.shape[0] width = img.shape[1] Hx = np.array([[-1, 0, 1], [-2, 0, 2], [-1, 0, 1]]) Hy = np.array([[-1, -2, -1], [0, 0, 0], [1, 2, 1]]) sobel_x = convolve_np(img, Hx) / 8.0 sobel_y = convolve_np(img, Hy) / 8.0 #prewitt Px = np.array([[-1, 0, 1], [-1, 0, 1], [-1, 0, 1]]) Py = np.array([[-1, -1, -1], [0, 0, 0], [1, 1, 1]]) prewitt_x = convolve_np(img, Px) / 6.0 prewitt_y = convolve_np(img, Py) / 6.0 #robert cross roberts_cross_v = np.array([[0, 0, 0], [0, 1, 0], [0, 0, -1]])