






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







Import numpy as np
Image = cv2.imread(“flower.jpg”) Gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
Fourier = cv2.dft(np.float32(gray), flags=cv2.DFT_COMPLEX_OUTPUT)
Fourier_shift = np.fft.fftshift(fourier)
Magnitude = 20*np.log(cv2.magnitude(fourier_shift[:,:,0],fourier_shift[:,:,1]))
Magnitude = cv2.normalize(magnitude, None, 0, 255, cv2.NORM_MINMAX, cv2.CV_8UC1)
Cv2.imshow(‘Fourier Transform’, magnitude) Cv2.waitKey(0) Cv2.destroyAllWindows() ORIGINAL IMAGE :-
Import cv Import numpy as np Img1=cv2.imread(“sudoku.jpg”, cv2.IMREAD_GRAYSCALE) Img2=cv2.imread(“exp4b.jpg”, cv2.IMREAD_GRAYSCALE) Orbb=cv2.ORB_create() Kp1, des1 = orbb.detectAndCompute(img1, None) Kp2, des2 = orbb.detectAndCompute(img2, None) Brute_force=cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True) Matches=brute_force.match(des1, des2) Matches=sorted(matches, key=lambda x:x.distance) Matching_results=cv2.drawMatches(img1, kp1, img2, kp2, matches, None) Cv2.imshow(“Feature_Matching”, matching_results) Cv2.waitKey(0) Cv2.destroyAllWindows()
Kp, des = orb.compute(img, kp)
Img2 = cv.drawKeypoints(img, kp, None, color=(0,255,0), flags=0) Plt.imshow(img2), plt.show() ORIGINAL IMAGE :- OUTPUT :-
Import cv Import numpy as np Img1=cv2.imread(“exp4.jpg”, cv2.IMREAD_GRAYSCALE) Img2=cv2.imread(“exp4b.jpg”, cv2.IMREAD_GRAYSCALE) Orbb=cv2.ORB_create()
Kp1, des1 = orbb.detectAndCompute(img1, None) Kp2, des2 = orbb.detectAndCompute(img2, None) Brute_force=cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True) Matches=brute_force.match(des1, des2) Matches=sorted(matches, key=lambda x:x.distance) Matching_results=cv2.drawMatches(img1, kp1, img2, kp2, matches, None) Cv2.imshow(“Feature_Matching”, matching_results) Cv2.waitKey(0) Cv2.destroyAllWindows() ORIGINAL IMAGE :- OUTPUT :-
Import cv Import numpy as np
Img1 = cv2.imread(‘exp4.jpg’, cv2.IMREAD_GRAYSCALE) Img2 = cv2.imread(‘exp4b.jpg’, cv2.IMREAD_GRAYSCALE)
Orb = cv2.ORB_create()
Kp1, des1 = orb.detectAndCompute(img1, None) Kp2, des2 = orb.detectAndCompute(img2, None)
Bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)
Matches = bf.match(des1, des2)
Matches = sorted(matches, key=lambda x: x.distance)
Img_matches = cv2.drawMatches(img1, kp1, img2, kp2, matches[:10], None, Flags=cv2.DrawMatchesFlags_NOT_DRAW_SINGLE_POINTS)
Cv2.imshow(‘Matches’, img_matches) Cv2.waitKey(0) Cv2.destroyAllWindows()
Src_pts = np.float32([kp1[m.queryIdx].pt for m in matches]).reshape(-1, 1, 2) Dst_pts = np.float32([kp2[m.trainIdx].pt for m in matches]).reshape(-1, 1, 2)
H, _ = cv2.findHomography(src_pts, dst_pts, cv2.RANSAC)
Aligned_img = cv2.warpPerspective(img1, H, (img2.shape[1], img2.shape[0]))
Cv2.imshow(‘Aligned Image’, aligned_img) Cv2.waitKey(0) Cv2.destroyAllWindows() ORIGINAL IMAGE :- OUPUT :-
Import numpy as np Import cv Def grabcut_segmentation(image):