def main(): displayer = Displayer() A = cv2.cvtColor(fetch_image('apple.jpg'), cv2.COLOR_BGR2RGB) B = cv2.cvtColor(fetch_image('orange.jpg'), cv2.COLOR_BGR2RGB) # generate Gaussian pyramid for A G = A.copy() gpA = [G] for i in xrange(6): G = cv2.pyrDown(G) gpA.append(G) # generate Gaussian pyramid for B G = B.copy() gpB = [G] for i in xrange(6): G = cv2.pyrDown(G) gpB.append(G) # generate Laplacian Pyramid for A lpA = [gpA[5]] for i in xrange(5, 0, -1): GE = cv2.pyrUp(gpA[i]) L = cv2.subtract(gpA[i - 1], GE) lpA.append(L) # generate Laplacian Pyramid for B lpB = [gpB[5]] for i in xrange(5, 0, -1): GE = cv2.pyrUp(gpB[i]) L = cv2.subtract(gpB[i - 1], GE) lpB.append(L) # Now add left and right halves of images in each level LS = [] for la, lb in zip(lpA, lpB): rows, cols, dpt = la.shape ls = np.hstack((la[:, 0:cols / 2], lb[:, cols / 2:])) LS.append(ls) # now reconstruct ls_ = LS[0] for i in xrange(1, 6): ls_ = cv2.pyrUp(ls_) displayer.add_image(ls_, i) ls_ = cv2.add(ls_, LS[i]) # image with direct connecting each half real = np.hstack((A[:, :cols / 2], B[:, cols / 2:])) displayer.add_image(ls_, "pyramid") #displayer.add_image(real, "stacked") #for i in range(len(lpA)): # displayer.add_image(LS[i], i) displayer.display()
def main(): displayer = Displayer() A = cv2.cvtColor(fetch_image('apple.jpg'), cv2.COLOR_BGR2RGB) B = cv2.cvtColor(fetch_image('orange.jpg'), cv2.COLOR_BGR2RGB) # generate Gaussian pyramid for A G = A.copy() gpA = [G] for i in xrange(6): G = cv2.pyrDown(G) gpA.append(G) # generate Gaussian pyramid for B G = B.copy() gpB = [G] for i in xrange(6): G = cv2.pyrDown(G) gpB.append(G) # generate Laplacian Pyramid for A lpA = [gpA[5]] for i in xrange(5,0,-1): GE = cv2.pyrUp(gpA[i]) L = cv2.subtract(gpA[i-1],GE) lpA.append(L) # generate Laplacian Pyramid for B lpB = [gpB[5]] for i in xrange(5,0,-1): GE = cv2.pyrUp(gpB[i]) L = cv2.subtract(gpB[i-1],GE) lpB.append(L) # Now add left and right halves of images in each level LS = [] for la,lb in zip(lpA,lpB): rows,cols,dpt = la.shape ls = np.hstack((la[:,0:cols/2], lb[:,cols/2:])) LS.append(ls) # now reconstruct ls_ = LS[0] for i in xrange(1,6): ls_ = cv2.pyrUp(ls_) displayer.add_image(ls_, i) ls_ = cv2.add(ls_, LS[i]) # image with direct connecting each half real = np.hstack((A[:,:cols/2],B[:,cols/2:])) displayer.add_image(ls_, "pyramid") #displayer.add_image(real, "stacked") #for i in range(len(lpA)): # displayer.add_image(LS[i], i) displayer.display()
def main(): displayer = Displayer() orig = cv2.cvtColor(fetch_image(sys.argv[1]), cv2.COLOR_BGR2GRAY) displayer.add_image(orig, 'Original') img = cv2.bilateralFilter(np.float32(orig), 9, 75, 75) x_kernel = np.array([[-1, 0, 1], [-2, 0, 2], [-1, 0, 1]]) y_kernel = np.array([[ 1, 2, 1], [ 0, 0, 0], [-1, -2, -1]]) """ x_kernel = np.array([[3, 10, 3], [0, 0, 0], [-3, -10, -3]]) y_kernel = np.array([[ -3, -0, 3], [ -10, 0, 10], [ -3, -0, 3]]) """ """ y_kernel = x_kernel = np.array([[ 0.5, 1, 0.5], [ 1, -6, 1], [ 0.5, 1, 0.5]]) """ x_gradient = cv2.filter2D(img, -1, x_kernel) abs_x = np.absolute(x_gradient) x_grad_u8 = np.uint8(abs_x) displayer.add_image(x_grad_u8, 'manual x gradient') y_gradient = cv2.filter2D(img, -1, y_kernel) abs_y = np.absolute(y_gradient) y_grad_u8 = np.uint8(abs_y) displayer.add_image(y_grad_u8, 'manual y gradient') magnitude = cv2.magnitude(abs_x, abs_y) magnitude_u8 = np.uint8(magnitude) displayer.add_image(magnitude_u8, 'magnitude') """ lap = cv2.Laplacian(orig, -1, cv2.CV_64F) displayer.add_image(np.uint8(lap), 'laplacian') """ canny = cv2.Canny(orig, 100, 200) displayer.add_image(np.uint8(canny), 'Canny') displayer.display(cmap='gray')
def main(): img = fetch_image(sys.argv[1]) displayer = Displayer() kernel = np.ones((5, 5), np.float32)/25 displayer.add_image(img, 'Original') displayer.add_image(cv2.filter2D(img, -1, kernel), 'Average') displayer.add_image(cv2.GaussianBlur(img, (5, 5), 0), 'Gaussian') displayer.add_image(cv2.medianBlur(img, 5), 'Median') displayer.add_image(cv2.bilateralFilter(img, 9, 75, 75), 'Bilateral') displayer.display()
def main(): displayer = Displayer() orig = cv2.cvtColor(fetch_image(sys.argv[1]), cv2.COLOR_BGR2GRAY) displayer.add_image(orig, 'Original') img = cv2.bilateralFilter(np.float32(orig), 9, 75, 75) x_kernel = np.array([[-1, 0, 1], [-2, 0, 2], [-1, 0, 1]]) y_kernel = np.array([[1, 2, 1], [0, 0, 0], [-1, -2, -1]]) """ x_kernel = np.array([[3, 10, 3], [0, 0, 0], [-3, -10, -3]]) y_kernel = np.array([[ -3, -0, 3], [ -10, 0, 10], [ -3, -0, 3]]) """ """ y_kernel = x_kernel = np.array([[ 0.5, 1, 0.5], [ 1, -6, 1], [ 0.5, 1, 0.5]]) """ x_gradient = cv2.filter2D(img, -1, x_kernel) abs_x = np.absolute(x_gradient) x_grad_u8 = np.uint8(abs_x) displayer.add_image(x_grad_u8, 'manual x gradient') y_gradient = cv2.filter2D(img, -1, y_kernel) abs_y = np.absolute(y_gradient) y_grad_u8 = np.uint8(abs_y) displayer.add_image(y_grad_u8, 'manual y gradient') magnitude = cv2.magnitude(abs_x, abs_y) magnitude_u8 = np.uint8(magnitude) displayer.add_image(magnitude_u8, 'magnitude') """ lap = cv2.Laplacian(orig, -1, cv2.CV_64F) displayer.add_image(np.uint8(lap), 'laplacian') """ canny = cv2.Canny(orig, 100, 200) displayer.add_image(np.uint8(canny), 'Canny') displayer.display(cmap='gray')
def main(): displayer = Displayer() orig = fetch_image(sys.argv[1], 0) displayer.add_image(orig, "Original") square = np.ones((9, 9), np.float32) rectangle = cv2.getStructuringElement(cv2.MORPH_RECT, (1, 13)) ellipse = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (5, 5)) cross = cv2.getStructuringElement(cv2.MORPH_CROSS, (5, 5)) kernel = cross displayer.add_image(cv2.erode(orig, kernel, iterations=1), "Erosion") displayer.add_image(cv2.dilate(orig, kernel, iterations=1), "Dilation") displayer.add_image(cv2.morphologyEx(orig, cv2.MORPH_OPEN, kernel), "Opening") closing = cv2.morphologyEx(orig, cv2.MORPH_CLOSE, kernel) displayer.add_image(closing, "Closing") displayer.add_image(cv2.morphologyEx(closing, cv2.MORPH_OPEN, kernel), "OpeningClosing") displayer.add_image(cv2.morphologyEx(orig, cv2.MORPH_GRADIENT, kernel), "Gradient") displayer.add_image(cv2.morphologyEx(orig, cv2.MORPH_TOPHAT, kernel), "Top Hat") displayer.add_image(cv2.morphologyEx(orig, cv2.MORPH_BLACKHAT, kernel), "Black Hat") displayer.display(cmap="gray")
def main(): displayer = Displayer() orig = fetch_image(sys.argv[1], 0) displayer.add_image(orig, 'Original') square = np.ones((9, 9), np.float32) rectangle = cv2.getStructuringElement(cv2.MORPH_RECT, (1, 13)) ellipse = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (5, 5)) cross = cv2.getStructuringElement(cv2.MORPH_CROSS, (5, 5)) kernel = cross displayer.add_image(cv2.erode(orig, kernel, iterations=1), 'Erosion') displayer.add_image(cv2.dilate(orig, kernel, iterations=1), 'Dilation') displayer.add_image(cv2.morphologyEx(orig, cv2.MORPH_OPEN, kernel), 'Opening') closing = cv2.morphologyEx(orig, cv2.MORPH_CLOSE, kernel) displayer.add_image(closing, 'Closing') displayer.add_image(cv2.morphologyEx(closing, cv2.MORPH_OPEN, kernel), 'OpeningClosing') displayer.add_image(cv2.morphologyEx(orig, cv2.MORPH_GRADIENT, kernel), 'Gradient') displayer.add_image(cv2.morphologyEx(orig, cv2.MORPH_TOPHAT, kernel), 'Top Hat') displayer.add_image(cv2.morphologyEx(orig, cv2.MORPH_BLACKHAT, kernel), 'Black Hat') displayer.display(cmap='gray')