├── Adaptive+Gaussian Thresholding ├── AG.jpg ├── AM.jpg ├── Global.jpg ├── adaptive_thr.py └── page.jpg ├── Basic Transformations ├── Translation.jpg ├── basic_transform.py └── calvinHobbes.jpeg ├── Box Filter ├── boxfil.png ├── filter.py ├── orig.png └── panda1.jpg ├── Capture Video Frames └── capt_video_frame.py ├── Contours-OpenCV ├── CannyFish.jpg ├── Contours.jpg ├── LargestContour.jpg ├── bubblingFish.jpg └── contour.py ├── Digital_Image_Processing,_4th Edition-Rafael Gonzalez.pdf ├── Discrete Fourier Transformation ├── DFT.png ├── Untitled.png ├── dft.py └── idft.jpg ├── Est. Transformation ├── 1.jpg ├── image.jpg └── piecewise.py ├── Fitting Polygons ├── Contours.jpg ├── Threshold.jpg ├── Triangles.jpg ├── polygon.py └── polygons.jpg ├── GaussianFilter+Kernels ├── convolution.py └── panda.jpg ├── Grabcut ├── Screenshot from 2020-08-14 23-16-57.png ├── cut_messi.jpg ├── grabcut.py └── messi.jpg ├── Histogram Equalisation ├── Equalized Image.png ├── equal-hist.png ├── hist.png ├── hist.py └── lowContrast.png ├── Hough Lines ├── canny.jpg ├── dilate.jpg ├── erode.jpg ├── hough.jpg ├── sudoku.jpg └── sudoku.py ├── Image Averaging └── average.py ├── Image Temperature ├── hist.png ├── warm.py └── warmed.jpg ├── Interpolation-Inverse Mapping ├── NearestNeighbour.jpg ├── interpolation.py ├── original.jpg └── pexels.jpeg ├── Interpolations ├── Bicubic.jpg ├── Bilinear.jpg ├── Nearest Neighbour.jpg ├── block.png ├── intrpolation.py └── panda.jpg ├── Laplacian+Gaussian ├── Gaussian + Laplacian.jpg ├── Laplacian.jpg ├── laplacian.py └── monarch.jpg ├── Laplacian, Sobel, CannyEdge ├── CannyChess.jpg ├── CannyLenna.jpg ├── ChessBoardGrad.png ├── LaplacianChess.png ├── LaplacianLenna.png ├── Lenna.png ├── SobelXChess.jpg ├── SobelXLenna.jpg ├── SobelYChess.jpg ├── SobelYLenna.jpg ├── cannyChess.py ├── cannyLenna.py ├── laplacianChess.py ├── laplacianLenna.py ├── originallenna.jpg ├── sobelxChess.py ├── sobelxLenna.py ├── sobelyChess.py └── sobelyLenna.py ├── Laplacian ├── laplacian.jpg ├── laplacian.py ├── monarch.jpg ├── original.jpg └── pand.jpg ├── Live Hand Gesture Recognition ├── Aptfile ├── Procfile ├── README.md ├── __pycache__ │ └── recognize.cpython-36.pyc ├── app.py ├── recognize.py ├── requirements.txt ├── runtime.txt ├── static │ ├── image1.png │ └── styles │ │ └── home.css └── templates │ └── index.html ├── Log and Contrast_Stretching ├── contrast_stretch.jpg ├── contrast_stretching.py ├── log.jpg ├── log_trans.py └── log_transformed.jpg ├── Morphological Fingerprint Processing ├── 11.jpg ├── 9-p.jpg ├── Closing.png ├── ErodeDilateClose.png ├── ErosionPlusDilation.png ├── Final-ComparisionImage.png ├── Improved.png ├── Input.png ├── Opening.png ├── Processed.png └── morph3.py ├── Morphological Outline ├── 16.jpg ├── Outline.png └── morph4.py ├── Morphological Processing ├── 5.jpg ├── Closing.png ├── Dilation.png ├── Erosion.png ├── Opening.png └── morph1.py ├── Morphological Text Processing ├── 7.jpg ├── Dilation + Erosion.png ├── Dilation.png ├── Processed 1.png ├── Processed 2.png ├── improved.jpg └── morph2.py ├── Normalize Histogram ├── equilised.jpg ├── equilisedAutomated.jpg ├── hist.png ├── hist.py ├── histogram.png └── norm.png ├── OTSU Thresholding ├── Otsus.jpg ├── binarythresh1.jpg ├── blur1.jpg ├── gray1.jpg ├── noisy_leaf.jpg ├── otsu-orig.png ├── otsu-transform.png └── thresholding.py ├── Object Movement Tracking ├── Screenshot from 2020-04-12 22-02-01.png ├── blue_cap.py └── get_hsv.py ├── OpenCV KMeans ├── building.png ├── k=3.jpg ├── k=5.jpg ├── k=8.jpg └── kmeans.py ├── Perspective Transformation ├── ch.jpeg ├── ch.jpg ├── chDistorted.jpeg ├── dist.py └── distortion.py ├── README.md ├── Shading Correction ├── ChessBoardGrad.png ├── Converted.png └── chess.py ├── Sobel-X and Y ├── LaplacianLenna.png ├── SobelXLenna.jpg ├── SobelYLenna.jpg ├── pand.jpg ├── sobel-y.py └── sobel.py ├── Successive Rotations ├── 8.jpg ├── rotated45.jpg ├── rotated90.jpg └── rotation.py ├── Video background Subtraction ├── cap_diff.py └── singleframe.py ├── VideoCapture_GoogleColab └── vcgc.py └── images ├── DIP.jpg ├── DIP.png ├── averaging.png ├── f.png └── gradient.png /Adaptive+Gaussian Thresholding/AG.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Adaptive+Gaussian Thresholding/AG.jpg -------------------------------------------------------------------------------- /Adaptive+Gaussian Thresholding/AM.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Adaptive+Gaussian Thresholding/AM.jpg -------------------------------------------------------------------------------- /Adaptive+Gaussian Thresholding/Global.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Adaptive+Gaussian Thresholding/Global.jpg -------------------------------------------------------------------------------- /Adaptive+Gaussian Thresholding/adaptive_thr.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | 4 | img = cv2.imread('page.jpg', cv2.IMREAD_GRAYSCALE) 5 | cv2.imshow('gray', img) 6 | 7 | blur = cv2.GaussianBlur(img,(5,5),0) 8 | cv2.imshow('blur', blur) 9 | 10 | ret,th1 = cv2.threshold(blur,150,255,cv2.THRESH_BINARY) 11 | cv2.imshow('Global', th1) 12 | cv2.imwrite('Global.jpg',th1) 13 | 14 | 15 | th2 = cv2.adaptiveThreshold(blur,255,cv2.ADAPTIVE_THRESH_MEAN_C,cv2.THRESH_BINARY,11,2) 16 | cv2.imshow('Adaptive Mean', th2) 17 | cv2.imwrite('AM.jpg',th2) 18 | 19 | 20 | th3 = cv2.adaptiveThreshold(blur,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,cv2.THRESH_BINARY,11,2) 21 | cv2.imshow('Adaptive Gaussian', th3) 22 | cv2.imwrite('AG.jpg',th3) 23 | cv2.waitKey(0) 24 | cv2.destroyAllWindows() 25 | -------------------------------------------------------------------------------- /Adaptive+Gaussian Thresholding/page.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Adaptive+Gaussian Thresholding/page.jpg -------------------------------------------------------------------------------- /Basic Transformations/Translation.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Basic Transformations/Translation.jpg -------------------------------------------------------------------------------- /Basic Transformations/basic_transform.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | 4 | image = cv2.imread('calvinHobbes.jpeg') 5 | 6 | 7 | height, width = image.shape[:2] 8 | quarter_height, quarter_width = height/4, width/4 9 | 10 | T = np.float32([[1, 0, quarter_width], [0, 1, quarter_height]]) 11 | img_translation = cv2.warpAffine(image, T, (width, height)) 12 | 13 | cv2.imshow("Originalimage", image) 14 | cv2.imshow('Translation', img_translation) 15 | cv2.imwrite('Translation.jpg', img_translation) 16 | cv2.waitKey() 17 | 18 | cv2.destroyAllWindows() 19 | 20 | 21 | # cv2.imshow("Nearest Neighbour", scaled) 22 | # cv2.waitKey(0) 23 | # cv2.destroyAllWindows() 24 | 25 | # cv2.imshow("Bilinear", scaled) 26 | # cv2.waitKey(0) 27 | # cv2.destroyAllWindows() 28 | 29 | # cv2.imshow("Bicubic", scaled) 30 | # cv2.waitKey(0) 31 | # cv2.destroyAllWindows() 32 | -------------------------------------------------------------------------------- /Basic Transformations/calvinHobbes.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Basic Transformations/calvinHobbes.jpeg -------------------------------------------------------------------------------- /Box Filter/boxfil.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Box Filter/boxfil.png -------------------------------------------------------------------------------- /Box Filter/filter.py: -------------------------------------------------------------------------------- 1 | # import cv2 2 | # import numpy as np 3 | # from matplotlib import pyplot as plt 4 | 5 | # img = cv2.imread('panda1.jpg',0) 6 | # x = int(input()) 7 | 8 | # kernel = np.ones((x,x),np.float32)/pow(x,2) 9 | # dst = cv2.blur(img,0,kernel,img,(-1,-1),False,cv2.BORDER_DEFAULT) 10 | # #cv2.imwrite('dts.png', dst) 11 | # plt.subplot(121),plt.imshow(img),plt.title('Original') 12 | # plt.xticks([]), plt.yticks([]) 13 | # plt.subplot(122),plt.imshow(dst),plt.title('Averaging') 14 | # plt.xticks([]), plt.yticks([]) 15 | # plt.show() 16 | 17 | import cv2 18 | import numpy as np 19 | from matplotlib import pyplot as plt 20 | 21 | img = cv2.imread('panda1.jpg') 22 | 23 | blur = cv2.blur(img,(5,5)) 24 | 25 | plt.imshow(img),plt.title('Original') 26 | plt.show() 27 | cv2.imwrite('orig.png', img) 28 | plt.xticks([]), plt.yticks([]) 29 | plt.imshow(blur),plt.title('Blurred') 30 | plt.xticks([]), plt.yticks([]) 31 | plt.show() 32 | cv2.imwrite('boxfil.png', blur) -------------------------------------------------------------------------------- /Box Filter/orig.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Box Filter/orig.png -------------------------------------------------------------------------------- /Box Filter/panda1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Box Filter/panda1.jpg -------------------------------------------------------------------------------- /Capture Video Frames/capt_video_frame.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | vid = cv2.VideoCapture(0) 3 | i=0 4 | while(True): 5 | ret, frame = vid.read() 6 | cv2.imshow('frame', frame) 7 | if cv2.waitKey(1) & 0xFF == ord('q'): 8 | break 9 | cv2.imwrite('bhanu'+str(i)+'.jpg',frame) 10 | i+=1 11 | 12 | vid.release() 13 | cv2.destroyAllWindows() -------------------------------------------------------------------------------- /Contours-OpenCV/CannyFish.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Contours-OpenCV/CannyFish.jpg -------------------------------------------------------------------------------- /Contours-OpenCV/Contours.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Contours-OpenCV/Contours.jpg -------------------------------------------------------------------------------- /Contours-OpenCV/LargestContour.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Contours-OpenCV/LargestContour.jpg -------------------------------------------------------------------------------- /Contours-OpenCV/bubblingFish.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Contours-OpenCV/bubblingFish.jpg -------------------------------------------------------------------------------- /Contours-OpenCV/contour.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | 4 | image = cv2.imread('bubblingFish.jpg') 5 | gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) 6 | 7 | edged = cv2.Canny(gray, 30, 200) 8 | cv2.waitKey(0) 9 | contours, hierarchy = cv2.findContours(edged, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) 10 | cv2.imshow('Canny Edges After Contouring', edged) 11 | cv2.imwrite('CannyFish.jpg', edged) 12 | cv2.waitKey(0) 13 | 14 | print("Number of Contours: " + str(len(contours))) 15 | 16 | cv2.drawContours(image, contours, -1, (0, 255, 0), 3) 17 | 18 | cv2.imshow('Contours', image) 19 | cv2.imwrite('Contours.jpg', image) 20 | cv2.waitKey(0) 21 | 22 | image2 = cv2.imread('bubblingFish.jpg') 23 | if len(contours) != 0: 24 | c = max(contours, key = cv2.contourArea) 25 | cv2.drawContours(image2, c, -1, (0, 255, 0), 3) 26 | cv2.imshow('Largest Contour', image2) 27 | cv2.imwrite('LargestContour.jpg', image2) 28 | cv2.waitKey(0) 29 | 30 | cv2.destroyAllWindows() -------------------------------------------------------------------------------- /Digital_Image_Processing,_4th Edition-Rafael Gonzalez.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Digital_Image_Processing,_4th Edition-Rafael Gonzalez.pdf -------------------------------------------------------------------------------- /Discrete Fourier Transformation/DFT.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Discrete Fourier Transformation/DFT.png -------------------------------------------------------------------------------- /Discrete Fourier Transformation/Untitled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Discrete Fourier Transformation/Untitled.png -------------------------------------------------------------------------------- /Discrete Fourier Transformation/dft.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import cv2 3 | from matplotlib import pyplot as plt 4 | 5 | img = cv2.imread('Untitled.png',0) 6 | 7 | dft = cv2.dft(np.float32(img),flags = cv2.DFT_COMPLEX_OUTPUT) 8 | dft_shift = np.fft.fftshift(dft) 9 | 10 | magnitude_spectrum = 20*np.log(cv2.magnitude(dft_shift[:,:,0],dft_shift[:,:,1])) 11 | 12 | plt.subplot(121),plt.imshow(img, cmap = 'gray') 13 | plt.title('Input Image'), plt.xticks([]), plt.yticks([]) 14 | cv2.imwrite("idft.jpg", magnitude_spectrum) 15 | plt.subplot(122),plt.imshow(magnitude_spectrum, cmap = 'gray') 16 | plt.title('Magnitude Spectrum'), plt.xticks([]), plt.yticks([]) 17 | plt.show() 18 | 19 | rows, cols = img.shape 20 | crow,ccol = rows//2 , cols//2 21 | 22 | # create a mask first, center square is 1, remaining all zeros 23 | mask = np.zeros((rows,cols,2),np.uint8) 24 | mask[crow-30:crow+30, ccol-30:ccol+30] = 1 25 | 26 | # apply mask and inverse DFT 27 | fshift = dft_shift*mask 28 | f_ishift = np.fft.ifftshift(fshift) 29 | img_back = cv2.idft(f_ishift) 30 | img_back = cv2.magnitude(img_back[:,:,0],img_back[:,:,1]) 31 | 32 | plt.subplot(121),plt.imshow(img, cmap = 'gray') 33 | plt.title('Input Image'), plt.xticks([]), plt.yticks([]) 34 | plt.subplot(122),plt.imshow(img_back, cmap = 'gray') 35 | plt.title('Magnitude Spectrum'), plt.xticks([]), plt.yticks([]) 36 | plt.show() 37 | 38 | 39 | c = 255/(np.log(1 + np.max(img))) 40 | log_transformed = c * np.log(1 + img) 41 | 42 | # Specify the data type. 43 | log_transformed = np.array(log_transformed, dtype = np.uint8) 44 | 45 | cv2.imshow(log_transformed, "transformed") 46 | cv2.imwrite("idft1.jpg", log_transformed) 47 | cv2.waitkey(0) -------------------------------------------------------------------------------- /Discrete Fourier Transformation/idft.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Discrete Fourier Transformation/idft.jpg -------------------------------------------------------------------------------- /Est. Transformation/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Est. Transformation/1.jpg -------------------------------------------------------------------------------- /Est. Transformation/image.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Est. Transformation/image.jpg -------------------------------------------------------------------------------- /Est. Transformation/piecewise.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | 4 | def piecewise(img,h,w): 5 | for i in range(h): 6 | for j in range(w): 7 | if(img[i][j] > 105 and img[i][j] < 165): 8 | img[i][j] =10 9 | 10 | 11 | img = cv2.imread('1.jpg', 0) 12 | (h,w) = img.shape[:2] 13 | 14 | piecewise(img,h,w) 15 | 16 | cv2.imshow("image",img) 17 | cv2.imwrite("image.jpg", img) 18 | cv2.waitKey(0) -------------------------------------------------------------------------------- /Fitting Polygons/Contours.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Fitting Polygons/Contours.jpg -------------------------------------------------------------------------------- /Fitting Polygons/Threshold.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Fitting Polygons/Threshold.jpg -------------------------------------------------------------------------------- /Fitting Polygons/Triangles.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Fitting Polygons/Triangles.jpg -------------------------------------------------------------------------------- /Fitting Polygons/polygon.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | 4 | count=0 5 | img = cv2.imread('polygons.jpg', cv2.IMREAD_GRAYSCALE) 6 | cv2.imshow('gray', img) 7 | cv2.waitKey(0) 8 | 9 | _,threshold = cv2.threshold(img, 200, 255, cv2.THRESH_BINARY) 10 | cv2.imshow('Threshold Image', threshold) 11 | cv2.imwrite('Threshold.jpg', threshold) 12 | cv2.waitKey(0) 13 | 14 | contours, hierarchy = cv2.findContours(threshold, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) 15 | cv2.drawContours(img, contours, -1, (0, 255, 0), 3) 16 | cv2.imshow('Contours', img) 17 | cv2.imwrite('Contours.jpg', img) 18 | cv2.waitKey(0) 19 | 20 | image2 = cv2.imread('polygons.jpg') 21 | for contour in contours: 22 | peri = cv2.arcLength(contour, True) 23 | approx = cv2.approxPolyDP(contour,0.05 * cv2.arcLength(contour, True), True) 24 | if len(approx) == 3 : 25 | cv2.drawContours(image2, contour, -1, (0, 0, 0), 3) 26 | count = count + 1 27 | 28 | print("Number of Triangles in the image: " + str(count)) 29 | cv2.imshow('Triangles Detected', image2) 30 | cv2.imwrite('Triangles.jpg', image2) 31 | cv2.waitKey(0) 32 | cv2.destroyAllWindows() -------------------------------------------------------------------------------- /Fitting Polygons/polygons.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Fitting Polygons/polygons.jpg -------------------------------------------------------------------------------- /GaussianFilter+Kernels/convolution.py: -------------------------------------------------------------------------------- 1 | #run the program "python3 convolution.py -i panda.jpg" 2 | from skimage.exposure import rescale_intensity 3 | import numpy as np 4 | import argparse 5 | import cv2 6 | 7 | def convolve(image, kernel): 8 | (ih,iw) = image.shape[:2] 9 | (kh,kw) = kernel.shape[:2] 10 | 11 | pad = (kw-1)//2 12 | image = cv2.copyMakeBorder(image, pad, pad, pad, pad, cv2.BORDER_REPLICATE) 13 | output=np.zeros((ih,iw), dtype="float32") 14 | 15 | for y in np.arange(pad, ih+pad): 16 | for x in np.arange(pad, iw+pad): 17 | 18 | roi = image[y-pad:y+pad+1, x-pad:x+pad+1] 19 | k = (roi*kernel).sum() 20 | 21 | output[y-pad, x-pad] = k 22 | 23 | output = rescale_intensity(output, in_range=(0,255)) 24 | output = (output*255).astype("uint8") 25 | 26 | return output 27 | 28 | 29 | ap= argparse.ArgumentParser() 30 | ap.add_argument("-i", "--image", required=True, help="path to the image") 31 | args = vars(ap.parse_args()) 32 | 33 | 34 | 35 | smallBlur = np.ones((7,7), dtype="float")*(1.0/(7*7)) 36 | largeBlur = np.ones((21,21), dtype="float")*(1.0/(21*21)) 37 | 38 | sharpen = np.array(( 39 | [0, -1, 0], 40 | [-1, 5, -1], 41 | [0, -1, 0]), dtype="int") 42 | 43 | laplacian = np.array(( 44 | [0, 1, 0], 45 | [1, -4, 1], 46 | [0, 1, 0]), dtype="int") 47 | 48 | sobelX = np.array(( 49 | [-1, 0, 1], 50 | [-2, 0, 2], 51 | [-1, 0, 1]), dtype="int") 52 | 53 | sobelY = np.array(( 54 | [-1, -2, -1], 55 | [0, 0, 0], 56 | [1, 2, 1]), dtype="int") 57 | 58 | 59 | kernelBank = ( 60 | 61 | ("small_blur", smallBlur), 62 | ("large_blur", largeBlur), 63 | ("sharpen", sharpen), 64 | ("laplacian", laplacian), 65 | ("sobel_x", sobelX), 66 | ("sobel_y", sobelY) 67 | ) 68 | 69 | image = cv2.imread(args["image"]) 70 | gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) 71 | for (kernelName, kernel) in kernelBank: 72 | print("[INFO] applying {} kernel".format(kernelName)) 73 | convoleOutput = convolve(gray, kernel) 74 | opencvOutput = cv2.filter2D(gray, -1, kernel) 75 | cv2.imshow("original", gray) 76 | cv2.imshow("{} - convole".format(kernelName), convoleOutput) 77 | cv2.imshow("{} - opencv".format(kernelName), opencvOutput) 78 | cv2.waitKey(0) 79 | cv2.destroyAllWindows() 80 | -------------------------------------------------------------------------------- /GaussianFilter+Kernels/panda.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/GaussianFilter+Kernels/panda.jpg -------------------------------------------------------------------------------- /Grabcut/Screenshot from 2020-08-14 23-16-57.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Grabcut/Screenshot from 2020-08-14 23-16-57.png -------------------------------------------------------------------------------- /Grabcut/cut_messi.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Grabcut/cut_messi.jpg -------------------------------------------------------------------------------- /Grabcut/grabcut.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import cv2 3 | from matplotlib import pyplot as plt 4 | 5 | img = cv2.imread('messi.jpg') 6 | cv2.imshow('img', img) 7 | 8 | mask = np.zeros(img.shape[:2],np.uint8) 9 | bgdModel = np.zeros((1,65),np.float64) 10 | fgdModel = np.zeros((1,65),np.float64) 11 | rect = (70,65,400,290) 12 | 13 | cv2.grabCut(img,mask,rect,bgdModel,fgdModel,5,cv2.GC_INIT_WITH_RECT) 14 | 15 | mask2 = np.where((mask==2)|(mask==0),0,1).astype('uint8') 16 | img_cut = img*mask2[:,:,np.newaxis] 17 | 18 | cv2.imshow('img_cut', img_cut) 19 | cv2.imwrite('cut_messi.jpg', img_cut) 20 | cv2.waitKey(0) -------------------------------------------------------------------------------- /Grabcut/messi.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Grabcut/messi.jpg -------------------------------------------------------------------------------- /Histogram Equalisation/Equalized Image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Histogram Equalisation/Equalized Image.png -------------------------------------------------------------------------------- /Histogram Equalisation/equal-hist.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Histogram Equalisation/equal-hist.png -------------------------------------------------------------------------------- /Histogram Equalisation/hist.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Histogram Equalisation/hist.png -------------------------------------------------------------------------------- /Histogram Equalisation/hist.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | from matplotlib import pyplot as plt 4 | 5 | img = cv2.imread('lowContrast.png',0) 6 | plt.hist(img.ravel(),256,[0,256]) 7 | 8 | plt.show() 9 | plt.savefig('hist.png') 10 | 11 | equ = cv2.equalizeHist(img) 12 | res = np.hstack((img,equ)) 13 | 14 | cv2.imshow('Equalized Image',res) 15 | cv2.imwrite('Equalized Image.png',res) 16 | 17 | plt.hist(res.ravel(),256,[0,256]) 18 | 19 | plt.show() 20 | plt.savefig('equal-hist.png') 21 | -------------------------------------------------------------------------------- /Histogram Equalisation/lowContrast.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Histogram Equalisation/lowContrast.png -------------------------------------------------------------------------------- /Hough Lines/canny.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Hough Lines/canny.jpg -------------------------------------------------------------------------------- /Hough Lines/dilate.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Hough Lines/dilate.jpg -------------------------------------------------------------------------------- /Hough Lines/erode.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Hough Lines/erode.jpg -------------------------------------------------------------------------------- /Hough Lines/hough.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Hough Lines/hough.jpg -------------------------------------------------------------------------------- /Hough Lines/sudoku.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Hough Lines/sudoku.jpg -------------------------------------------------------------------------------- /Hough Lines/sudoku.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | 4 | img = cv2.imread('sudoku.jpg') 5 | gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) 6 | cv2.imshow('gray',gray) 7 | cv2.waitKey(0) 8 | 9 | edges = cv2.Canny(gray,20,100,apertureSize = 3) 10 | cv2.imshow('canny',edges) 11 | cv2.imwrite('canny.jpg',edges) 12 | cv2.waitKey(0) 13 | 14 | kernel = np.ones((3,3),np.uint8) 15 | edges = cv2.dilate(edges,kernel,iterations = 1) 16 | cv2.imshow('dilate',edges) 17 | cv2.imwrite('dilate.jpg', edges) 18 | cv2.waitKey(0) 19 | 20 | kernel = np.ones((5,5),np.uint8) 21 | edges = cv2.erode(edges,kernel,iterations = 1) 22 | cv2.imshow('erode',edges) 23 | cv2.imwrite('erode.jpg', edges) 24 | cv2.waitKey(0) 25 | 26 | lines = cv2.HoughLines(edges,1,np.pi/180,150) 27 | print('number of Hough lines:', len(lines)) 28 | 29 | 30 | for line in lines: 31 | rho,theta = line[0] 32 | a = np.cos(theta) 33 | b = np.sin(theta) 34 | x0 = a*rho 35 | y0 = b*rho 36 | x1 = int(x0 + 1000*(-b)) 37 | y1 = int(y0 + 1000*(a)) 38 | x2 = int(x0 - 1000*(-b)) 39 | y2 = int(y0 - 1000*(a)) 40 | 41 | cv2.line(img,(x1,y1),(x2,y2),(0,0,255),2) 42 | 43 | cv2.imshow('hough.jpg',img) 44 | cv2.imwrite('hough.jpg',img) 45 | cv2.waitKey(0) 46 | cv2.destroyAllWindows() -------------------------------------------------------------------------------- /Image Averaging/average.py: -------------------------------------------------------------------------------- 1 | Open Lab: Digital Image ProcessingCSE S6 2 | Due Jan 4, 11:59 PM 3 | Basics with images 4 | 100 points 5 | Ram Kumar Dec 9, 2019 (Edited Dec 20, 2019) 6 | 2019-12-09.pdf 7 | PDF 8 | resources.txt 9 | Text 10 | Your work 11 | Turned in 12 | lab2.py 13 | Text 14 | Private comments 15 | 5 class comments 16 | mummaneni prabhathJan 8 17 | sir, 18 | you said you will change the due date of assignment 19 | Ram KumarJan 8 20 | Well I did change once to Dec 9. Most of them have completed. 21 | 22 | Not going to postpone again. 23 | mummaneni prabhathJan 8 24 | Last class you said you will give time for two more days, for rotation of image question 25 | . 26 | Ram KumarJan 8 27 | You can still upload despite the deadline. 28 | mummaneni prabhathJan 9 29 | ok sir. 30 | 31 | import numpy as np 32 | import argparse as ap 33 | import cv2 34 | import glob 35 | import warnings 36 | import imutils 37 | from math import cos, sin 38 | 39 | # a = list(map(int,input().split())) 40 | # arr = np.array(a) 41 | # arr2 = np.uint8(arr) 42 | # print(arr) 43 | 44 | # img = cv2.imread("ff_disney5_f.jpg") 45 | # print(img[0][0]) 46 | 47 | # img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) 48 | # print(img_gray) 49 | 50 | # cv2.imshow('Greyscale image', img_gray) 51 | # cv2.waitKey(0) 52 | 53 | # images = [cv2.imread(file) for file in glob.glob("/panda_images/*.jpg")] 54 | 55 | # with warnings.catch_warnings(): 56 | # warnings.simplefilter("ignore", category=RuntimeWarning) 57 | # foo = np.nanmean(images, axis=0) 58 | 59 | # images = [] 60 | # for img in glob.glob("panda_images/*.jpg"): 61 | # n = cv2.imread(img) 62 | # images.append(n) 63 | 64 | # images = [cv2.imread(file)/26 for file in glob.glob('./panda_images/*.jpg')] 65 | # for i in range(len(images)): 66 | # print(images[i][0][0]) 67 | 68 | # avg = cv2.add(images[0], images[1])//1 69 | # for i in range(2,26): 70 | # avg = cv2.add(avg, images[i])//1 71 | 72 | # cv2.imshow('Average image', avg) 73 | # cv2.waitKey(0) 74 | 75 | # image = np.zeros((576, 1024), dtype=np.float64) 76 | # for file in glob.glob("./panda_images/*.jpg"): 77 | # img = cv2.imread(file) 78 | # gimg = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)/26 79 | # # print(gimg.dtype) 80 | # image = cv2.add(image, gimg) 81 | 82 | # image = image.astype(np.uint8) 83 | # # print(image) 84 | # # cv2.imshow("", image) 85 | # # cv2.waitKey() 86 | 87 | image = cv2.imread("./panda_images/panda01.jpg") 88 | t=image.flatten() 89 | arr=[] 90 | for i in range(576): 91 | for j in range(1024): 92 | arr.append([i,j]) 93 | arr = np.array(arr) 94 | c,s = cos(45),sin(45) 95 | m = [[c,-s],[s,c]] 96 | f = arr.dot(np.array(m)) 97 | f = f.astype(int) 98 | k = np.zeros((1200, 1200), dtype=np.uint32) 99 | for i,j in zip(f,t): 100 | k[i[0],i[1]+600]=j 101 | k = k.astype(np.uint8) 102 | cv2.imshow("", k) 103 | cv2.waitKey() 104 | 105 | lab2.py 106 | Page 1 of 1 -------------------------------------------------------------------------------- /Image Temperature/hist.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Image Temperature/hist.png -------------------------------------------------------------------------------- /Image Temperature/warm.py: -------------------------------------------------------------------------------- 1 | #Code Resource - http://www.askaswiss.com/2016/02/how-to-manipulate-color-temperature-opencv-python.html 2 | 3 | import cv2 4 | import numpy as np 5 | import collections 6 | import matplotlib.pyplot as plt 7 | from scipy.interpolate import UnivariateSpline 8 | 9 | def create_LUT_8UC1(x, y): 10 | spl = UnivariateSpline(x, y) 11 | return spl(range(256)) 12 | 13 | incr_ch_lut = create_LUT_8UC1([0, 64, 128, 192, 256],[0, 70, 140, 210, 256]) 14 | decr_ch_lut = create_LUT_8UC1([0, 64, 128, 192, 256],[0, 30, 80, 120, 192]) 15 | 16 | img_bgr_in = cv2.imread("hist.png") 17 | 18 | c_b, c_g, c_r = cv2.split(img_bgr_in) 19 | c_r = cv2.LUT(c_r, incr_ch_lut).astype(np.uint8) 20 | c_b = cv2.LUT(c_b, decr_ch_lut).astype(np.uint8) 21 | img_bgr_warm = cv2.merge((c_b, c_g, c_r)) 22 | c_b = cv2.LUT(c_b, decr_ch_lut).astype(np.uint8) 23 | 24 | c_h, c_s, c_v = cv2.split(cv2.cvtColor(img_bgr_warm,cv2.COLOR_BGR2HSV)) 25 | c_s = cv2.LUT(c_s, incr_ch_lut).astype(np.uint8) 26 | 27 | img_bgr_warm = cv2.cvtColor(cv2.merge((c_h, c_s, c_v)),cv2.COLOR_HSV2BGR) 28 | 29 | cv2.imshow("ajskd",img_bgr_warm) 30 | cv2.waitKey(0) 31 | -------------------------------------------------------------------------------- /Image Temperature/warmed.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Image Temperature/warmed.jpg -------------------------------------------------------------------------------- /Interpolation-Inverse Mapping/NearestNeighbour.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Interpolation-Inverse Mapping/NearestNeighbour.jpg -------------------------------------------------------------------------------- /Interpolation-Inverse Mapping/interpolation.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy 3 | import math 4 | 5 | a=math.pi/4 6 | 7 | img = cv2.imread("pexels.jpeg") 8 | dim = img.shape 9 | 10 | imgt = numpy.zeros((int(abs(dim[0]*math.cos(a))+abs(dim[1]*math.sin(a))),int(abs(dim[0]*math.sin(a))+abs(dim[1]*math.cos(a))),3), numpy.uint8) 11 | dimt = imgt.shape 12 | 13 | imgf = numpy.zeros((int(abs(dimt[0]*math.cos(a))+abs(dimt[1]*math.sin(a)))+1,int(abs(dimt[0]*math.sin(a))+abs(dimt[1]*math.cos(a)))+1,3), numpy.uint8) 14 | dimf = imgf.shape 15 | 16 | org=[0,0] 17 | org[0]=((dimf[0]-dim[0]-1)//2) 18 | org[1]=((dimf[1]-dim[1]-1)//2) 19 | 20 | for i in range(dim[0]): 21 | for j in range(dim[1]): 22 | imgf[i+org[0]][j+org[1]]=img[i][j] 23 | 24 | pos = numpy.zeros((dimt[0]*dimt[1],2), numpy.uint16) 25 | 26 | k=0 27 | for i in range(dimt[0]): 28 | for j in range(dimt[1]): 29 | pos[k]=[i,j] 30 | k+=1 31 | 32 | mat = numpy.array([[math.cos(-a),-math.sin(-a)],[math.sin(-a),math.cos(-a)]]) 33 | newPos=numpy.dot(pos,mat) 34 | pos=newPos.copy() 35 | 36 | minx=pos.min(axis=0) 37 | 38 | #1 39 | for i in range(k): 40 | pos[i][0]+=(-minx[0]) 41 | pos[i][1]+=(-minx[1]) 42 | pos[i][0]=(round(pos[i][0])) 43 | pos[i][1]=(round(pos[i][1])) 44 | k-=1 45 | 46 | pos=pos.astype(int) 47 | 48 | k=0 49 | for i in range(dimt[0]): 50 | for j in range(dimt[1]): 51 | imgt[i][j]=imgf[pos[k][0]][pos[k][1]] 52 | k+=1 53 | 54 | cv2.imshow("original",img) 55 | cv2.imshow("NearestNeighbour",imgt) 56 | 57 | cv2.imwrite("original.jpg",img) 58 | cv2.imwrite("NearestNeighbour.jpg",imgt) 59 | 60 | #2 61 | for i in range(k): 62 | newPos[i][0]+=(-minx[0]) 63 | newPos[i][1]+=(-minx[1]) 64 | k-=1 65 | 66 | k=0 67 | for i in range(dimt[0]): 68 | for j in range(dimt[1]): 69 | if math.ceil(newPos[k][0])==newPos[k][0]: 70 | x=numpy.array([[0.5,0.5]]) 71 | else: 72 | x=numpy.array([[ math.ceil(newPos[k][0])-newPos[k][0] , newPos[k][0]-math.floor(newPos[k][0])]]) 73 | 74 | if math.ceil(newPos[k][1])==newPos[k][1]: 75 | y=numpy.array([ [0.5],[0.5] ]) 76 | else: 77 | y=numpy.array([ [math.ceil(newPos[k][1])-newPos[k][1]], 78 | [newPos[k][1]-math.floor(newPos[k][1])] ]) 79 | 80 | points=numpy.array([ 81 | [imgf[math.floor(newPos[k][0])][math.floor(newPos[k][1])], imgf[math.floor(newPos[k][0])][math.ceil(newPos[k][1])]], 82 | [imgf[math.ceil (newPos[k][0])][math.floor(newPos[k][1])], imgf[math.ceil (newPos[k][0])][math.ceil(newPos[k][1])]] 83 | ]) 84 | 85 | val=numpy.dot(x,points) 86 | 87 | for l in range(3): 88 | imgt[i][j][l]=numpy.dot(val[:,:,l],y) 89 | k+=1 90 | 91 | cv2.imshow("bilinear",imgt) 92 | cv2.imshow("bilinear.jpg",imgt) 93 | cv2.waitKey(0) 94 | cv2.destroyAllWindows() 95 | -------------------------------------------------------------------------------- /Interpolation-Inverse Mapping/original.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Interpolation-Inverse Mapping/original.jpg -------------------------------------------------------------------------------- /Interpolation-Inverse Mapping/pexels.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Interpolation-Inverse Mapping/pexels.jpeg -------------------------------------------------------------------------------- /Interpolations/Bicubic.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Interpolations/Bicubic.jpg -------------------------------------------------------------------------------- /Interpolations/Bilinear.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Interpolations/Bilinear.jpg -------------------------------------------------------------------------------- /Interpolations/Nearest Neighbour.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Interpolations/Nearest Neighbour.jpg -------------------------------------------------------------------------------- /Interpolations/block.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Interpolations/block.png -------------------------------------------------------------------------------- /Interpolations/intrpolation.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | 4 | img = cv2.imread('panda.jpg', 0) 5 | (h,w) = img.shape[:2] 6 | center = (w/2, h/2) 7 | angle45 = 45 8 | scale = 1.0 9 | 10 | M = cv2.getRotationMatrix2D(center, angle45, scale) 11 | 12 | 13 | abs_cos = abs(M[0,0]) 14 | abs_sin = abs(M[0,1]) 15 | 16 | 17 | bound_w = int(h * abs_sin + w * abs_cos) 18 | bound_h = int(h * abs_cos + w * abs_sin) 19 | 20 | M[0, 2] += bound_w/2 - center[0] 21 | M[1, 2] += bound_h/2 - center[1] 22 | 23 | rotated30 = cv2.warpAffine(img, M, (bound_w,bound_h)) 24 | 25 | # cv2.imshow('Original Image', img) 26 | # cv2.imshow('Rotated by 30', rotated30) 27 | # cv2.waitKey(0) 28 | # cv2.destroyAllWindows() 29 | 30 | scale_percent = 110 31 | width = int(rotated30.shape[1] * scale_percent / 100) 32 | height = int(rotated30.shape[0] * scale_percent / 100) 33 | dim = (width, height) 34 | 35 | scaled = cv2.resize(rotated30, dim, interpolation=cv2.INTER_NEAREST) 36 | scaled1 = cv2.resize(rotated30, dim, interpolation=cv2.INTER_LINEAR) 37 | scaled2 = cv2.resize(rotated30, dim, interpolation=cv2.INTER_CUBIC) 38 | 39 | cv2.imshow("Nearest Neighbour", scaled) 40 | cv2.imshow("Bilinear", scaled1) 41 | cv2.imshow("Bicubic", scaled2) 42 | 43 | cv2.imwrite("Nearest Neighbour.jpg", scaled) 44 | cv2.imwrite("Bilinear.jpg", scaled1) 45 | cv2.imwrite("Bicubic.jpg", scaled2) 46 | cv2.waitKey(0) 47 | cv2.destroyAllWindows() -------------------------------------------------------------------------------- /Interpolations/panda.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Interpolations/panda.jpg -------------------------------------------------------------------------------- /Laplacian+Gaussian/Gaussian + Laplacian.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Laplacian+Gaussian/Gaussian + Laplacian.jpg -------------------------------------------------------------------------------- /Laplacian+Gaussian/Laplacian.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Laplacian+Gaussian/Laplacian.jpg -------------------------------------------------------------------------------- /Laplacian+Gaussian/laplacian.py: -------------------------------------------------------------------------------- 1 | from skimage.exposure import rescale_intensity 2 | import numpy as np 3 | import argparse 4 | import cv2 5 | 6 | def convolve(image, kernel): 7 | (iH, iW) = image.shape[:2] 8 | (kH, kW) = kernel.shape[:2] 9 | pad = (kW - 1) // 2 10 | image = cv2.copyMakeBorder(image, pad, pad, pad, pad, 11 | cv2.BORDER_REPLICATE) 12 | output = np.zeros((iH, iW), dtype="float32") 13 | for y in np.arange(pad, iH + pad): 14 | for x in np.arange(pad, iW + pad): 15 | roi = image[y - pad:y + pad + 1, x - pad:x + pad + 1] 16 | k = (roi * kernel).sum() 17 | output[y - pad, x - pad] = k 18 | 19 | output = rescale_intensity(output, in_range=(0, 255)) 20 | output = (output * 255).astype("uint8") 21 | return output 22 | 23 | ap = argparse.ArgumentParser() 24 | ap.add_argument("-i", "--image", required=True, 25 | help="path to the input image") 26 | args = vars(ap.parse_args()) 27 | 28 | laplacian = np.array(( 29 | [0, 1, 0], 30 | [1, -4, 1], 31 | [0, 1, 0]), dtype="int") 32 | 33 | 34 | kernelBank = ( 35 | ("laplacian", laplacian), 36 | ) 37 | 38 | 39 | image = cv2.imread(args["image"]) 40 | gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) 41 | blur = cv2.GaussianBlur(gray,(3,3),0) 42 | 43 | for (kernelName, kernel) in kernelBank: 44 | print("[INFO] applying {} kernel".format(kernelName)) 45 | convoleOutput = convolve(gray, kernel) 46 | opencvOutput = cv2.filter2D(gray, -1, kernel) 47 | convoleOutput2 = convolve(blur, kernel) 48 | 49 | cv2.imshow("original", gray) 50 | cv2.imshow("{} - convole".format(kernelName), convoleOutput) 51 | cv2.imshow("{} - opencv".format(kernelName), opencvOutput) 52 | cv2.imshow('Gaussian + Laplacian', convoleOutput2) 53 | 54 | cv2.imwrite("Laplacian.jpg", convoleOutput) 55 | cv2.imwrite('Gaussian + Laplacian.jpg', convoleOutput2) 56 | 57 | cv2.waitKey(0) 58 | cv2.destroyAllWindows() -------------------------------------------------------------------------------- /Laplacian+Gaussian/monarch.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Laplacian+Gaussian/monarch.jpg -------------------------------------------------------------------------------- /Laplacian, Sobel, CannyEdge/CannyChess.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Laplacian, Sobel, CannyEdge/CannyChess.jpg -------------------------------------------------------------------------------- /Laplacian, Sobel, CannyEdge/CannyLenna.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Laplacian, Sobel, CannyEdge/CannyLenna.jpg -------------------------------------------------------------------------------- /Laplacian, Sobel, CannyEdge/ChessBoardGrad.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Laplacian, Sobel, CannyEdge/ChessBoardGrad.png -------------------------------------------------------------------------------- /Laplacian, Sobel, CannyEdge/LaplacianChess.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Laplacian, Sobel, CannyEdge/LaplacianChess.png -------------------------------------------------------------------------------- /Laplacian, Sobel, CannyEdge/LaplacianLenna.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Laplacian, Sobel, CannyEdge/LaplacianLenna.png -------------------------------------------------------------------------------- /Laplacian, Sobel, CannyEdge/Lenna.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Laplacian, Sobel, CannyEdge/Lenna.png -------------------------------------------------------------------------------- /Laplacian, Sobel, CannyEdge/SobelXChess.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Laplacian, Sobel, CannyEdge/SobelXChess.jpg -------------------------------------------------------------------------------- /Laplacian, Sobel, CannyEdge/SobelXLenna.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Laplacian, Sobel, CannyEdge/SobelXLenna.jpg -------------------------------------------------------------------------------- /Laplacian, Sobel, CannyEdge/SobelYChess.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Laplacian, Sobel, CannyEdge/SobelYChess.jpg -------------------------------------------------------------------------------- /Laplacian, Sobel, CannyEdge/SobelYLenna.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Laplacian, Sobel, CannyEdge/SobelYLenna.jpg -------------------------------------------------------------------------------- /Laplacian, Sobel, CannyEdge/cannyChess.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | from matplotlib import pyplot as plt 4 | 5 | img = cv2.imread('ChessBoardGrad.png',0) 6 | edges = cv2.Canny(img,100,200) 7 | 8 | cv2.imshow('Original',img) 9 | cv2.imshow('Edges',edges) 10 | 11 | cv2.imwrite('CannyChess.jpg', edges) 12 | cv2.waitKey(0) 13 | cv2.destroyAllWindows() -------------------------------------------------------------------------------- /Laplacian, Sobel, CannyEdge/cannyLenna.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | from matplotlib import pyplot as plt 4 | 5 | img = cv2.imread('Lenna.png',0) 6 | edges = cv2.Canny(img,100,200) 7 | 8 | cv2.imshow('Original',img) 9 | cv2.imshow('Edges',edges) 10 | 11 | cv2.imwrite('CannyLenna.jpg', edges) 12 | cv2.waitKey(0) 13 | cv2.destroyAllWindows() -------------------------------------------------------------------------------- /Laplacian, Sobel, CannyEdge/laplacianChess.py: -------------------------------------------------------------------------------- 1 | from skimage.exposure import rescale_intensity 2 | import numpy as np 3 | import argparse 4 | import cv2 5 | 6 | def convolve(image, kernel): 7 | (iH, iW) = image.shape[:2] 8 | (kH, kW) = kernel.shape[:2] 9 | pad = (kW - 1) // 2 10 | image = cv2.copyMakeBorder(image, pad, pad, pad, pad, 11 | cv2.BORDER_REPLICATE) 12 | output = np.zeros((iH, iW), dtype="float32") 13 | for y in np.arange(pad, iH + pad): 14 | for x in np.arange(pad, iW + pad): 15 | roi = image[y - pad:y + pad + 1, x - pad:x + pad + 1] 16 | k = (roi * kernel).sum() 17 | output[y - pad, x - pad] = k 18 | 19 | output = rescale_intensity(output, in_range=(0, 255)) 20 | output = (output * 255).astype("uint8") 21 | return output 22 | 23 | ap = argparse.ArgumentParser() 24 | ap.add_argument("-i", "--image", required=True, 25 | help="path to the input image") 26 | args = vars(ap.parse_args()) 27 | 28 | laplacian = np.array(( 29 | [0, 1, 0], 30 | [1, -4, 1], 31 | [0, 1, 0]), dtype="int") 32 | 33 | 34 | kernelBank = ( 35 | ("laplacian", laplacian), 36 | ) 37 | 38 | 39 | image = cv2.imread(args["image"]) 40 | gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) 41 | 42 | for (kernelName, kernel) in kernelBank: 43 | print("[INFO] applying {} kernel".format(kernelName)) 44 | convoleOutput = convolve(gray, kernel) 45 | opencvOutput = cv2.filter2D(gray, -1, kernel) 46 | cv2.imshow("original", gray) 47 | cv2.imshow("{} - convole".format(kernelName), convoleOutput) 48 | cv2.imshow("{} - opencv".format(kernelName), opencvOutput) 49 | 50 | cv2.imwrite("LaplacianChess.png", convoleOutput) 51 | cv2.waitKey(0) 52 | cv2.destroyAllWindows() -------------------------------------------------------------------------------- /Laplacian, Sobel, CannyEdge/laplacianLenna.py: -------------------------------------------------------------------------------- 1 | from skimage.exposure import rescale_intensity 2 | import numpy as np 3 | import argparse 4 | import cv2 5 | 6 | def convolve(image, kernel): 7 | (iH, iW) = image.shape[:2] 8 | (kH, kW) = kernel.shape[:2] 9 | pad = (kW - 1) // 2 10 | image = cv2.copyMakeBorder(image, pad, pad, pad, pad, 11 | cv2.BORDER_REPLICATE) 12 | output = np.zeros((iH, iW), dtype="float32") 13 | for y in np.arange(pad, iH + pad): 14 | for x in np.arange(pad, iW + pad): 15 | roi = image[y - pad:y + pad + 1, x - pad:x + pad + 1] 16 | k = (roi * kernel).sum() 17 | output[y - pad, x - pad] = k 18 | 19 | output = rescale_intensity(output, in_range=(0, 255)) 20 | output = (output * 255).astype("uint8") 21 | return output 22 | 23 | ap = argparse.ArgumentParser() 24 | ap.add_argument("-i", "--image", required=True, 25 | help="path to the input image") 26 | args = vars(ap.parse_args()) 27 | 28 | laplacian = np.array(( 29 | [0, 1, 0], 30 | [1, -4, 1], 31 | [0, 1, 0]), dtype="int") 32 | 33 | 34 | kernelBank = ( 35 | ("laplacian", laplacian), 36 | ) 37 | 38 | 39 | image = cv2.imread(args["image"]) 40 | gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) 41 | cv2.imwrite("originallenna.jpg", gray) 42 | 43 | for (kernelName, kernel) in kernelBank: 44 | print("[INFO] applying {} kernel".format(kernelName)) 45 | convoleOutput = convolve(gray, kernel) 46 | opencvOutput = cv2.filter2D(gray, -1, kernel) 47 | cv2.imshow("original", gray) 48 | cv2.imshow("{} - convole".format(kernelName), convoleOutput) 49 | cv2.imshow("{} - opencv".format(kernelName), opencvOutput) 50 | 51 | cv2.imwrite("LaplacianLenna.png", convoleOutput) 52 | cv2.waitKey(0) 53 | cv2.destroyAllWindows() -------------------------------------------------------------------------------- /Laplacian, Sobel, CannyEdge/originallenna.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Laplacian, Sobel, CannyEdge/originallenna.jpg -------------------------------------------------------------------------------- /Laplacian, Sobel, CannyEdge/sobelxChess.py: -------------------------------------------------------------------------------- 1 | from skimage.exposure import rescale_intensity 2 | import numpy as np 3 | import argparse 4 | import cv2 5 | 6 | def convolve(image, kernel): 7 | (iH, iW) = image.shape[:2] 8 | (kH, kW) = kernel.shape[:2] 9 | pad = (kW - 1) // 2 10 | image = cv2.copyMakeBorder(image, pad, pad, pad, pad, 11 | cv2.BORDER_REPLICATE) 12 | output = np.zeros((iH, iW), dtype="float32") 13 | for y in np.arange(pad, iH + pad): 14 | for x in np.arange(pad, iW + pad): 15 | roi = image[y - pad:y + pad + 1, x - pad:x + pad + 1] 16 | k = (roi * kernel).sum() 17 | output[y - pad, x - pad] = k 18 | 19 | output = rescale_intensity(output, in_range=(0, 255)) 20 | output = (output * 255).astype("uint8") 21 | return output 22 | 23 | ap = argparse.ArgumentParser() 24 | ap.add_argument("-i", "--image", required=True, 25 | help="path to the input image") 26 | args = vars(ap.parse_args()) 27 | 28 | sobelX = np.array(( 29 | [-1, 0, 1], 30 | [-2, 0, 2], 31 | [-1, 0, 1]), dtype="int") 32 | 33 | kernelBank = ( 34 | ("sobel_x", sobelX), 35 | ) 36 | 37 | 38 | image = cv2.imread(args["image"]) 39 | gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) 40 | 41 | for (kernelName, kernel) in kernelBank: 42 | print("[INFO] applying {} kernel".format(kernelName)) 43 | convoleOutput = convolve(gray, kernel) 44 | opencvOutput = cv2.filter2D(gray, -1, kernel) 45 | cv2.imshow("original", gray) 46 | cv2.imshow("{} - convole".format(kernelName), convoleOutput) 47 | cv2.imshow("{} - opencv".format(kernelName), opencvOutput) 48 | cv2.imwrite("SobelXChess.jpg", convoleOutput) 49 | cv2.waitKey(0) 50 | cv2.destroyAllWindows() -------------------------------------------------------------------------------- /Laplacian, Sobel, CannyEdge/sobelxLenna.py: -------------------------------------------------------------------------------- 1 | from skimage.exposure import rescale_intensity 2 | import numpy as np 3 | import argparse 4 | import cv2 5 | 6 | def convolve(image, kernel): 7 | (iH, iW) = image.shape[:2] 8 | (kH, kW) = kernel.shape[:2] 9 | pad = (kW - 1) // 2 10 | image = cv2.copyMakeBorder(image, pad, pad, pad, pad, 11 | cv2.BORDER_REPLICATE) 12 | output = np.zeros((iH, iW), dtype="float32") 13 | for y in np.arange(pad, iH + pad): 14 | for x in np.arange(pad, iW + pad): 15 | roi = image[y - pad:y + pad + 1, x - pad:x + pad + 1] 16 | k = (roi * kernel).sum() 17 | output[y - pad, x - pad] = k 18 | 19 | output = rescale_intensity(output, in_range=(0, 255)) 20 | output = (output * 255).astype("uint8") 21 | return output 22 | 23 | ap = argparse.ArgumentParser() 24 | ap.add_argument("-i", "--image", required=True, 25 | help="path to the input image") 26 | args = vars(ap.parse_args()) 27 | 28 | sobelX = np.array(( 29 | [-1, 0, 1], 30 | [-2, 0, 2], 31 | [-1, 0, 1]), dtype="int") 32 | 33 | kernelBank = ( 34 | ("sobel_x", sobelX), 35 | ) 36 | 37 | 38 | image = cv2.imread(args["image"]) 39 | gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) 40 | 41 | for (kernelName, kernel) in kernelBank: 42 | print("[INFO] applying {} kernel".format(kernelName)) 43 | convoleOutput = convolve(gray, kernel) 44 | opencvOutput = cv2.filter2D(gray, -1, kernel) 45 | cv2.imshow("original", gray) 46 | cv2.imshow("{} - convole".format(kernelName), convoleOutput) 47 | cv2.imshow("{} - opencv".format(kernelName), opencvOutput) 48 | cv2.imwrite("SobelXLenna.jpg", convoleOutput) 49 | cv2.waitKey(0) 50 | cv2.destroyAllWindows() -------------------------------------------------------------------------------- /Laplacian, Sobel, CannyEdge/sobelyChess.py: -------------------------------------------------------------------------------- 1 | from skimage.exposure import rescale_intensity 2 | import numpy as np 3 | import argparse 4 | import cv2 5 | 6 | def convolve(image, kernel): 7 | (iH, iW) = image.shape[:2] 8 | (kH, kW) = kernel.shape[:2] 9 | pad = (kW - 1) // 2 10 | image = cv2.copyMakeBorder(image, pad, pad, pad, pad, 11 | cv2.BORDER_REPLICATE) 12 | output = np.zeros((iH, iW), dtype="float32") 13 | for y in np.arange(pad, iH + pad): 14 | for x in np.arange(pad, iW + pad): 15 | roi = image[y - pad:y + pad + 1, x - pad:x + pad + 1] 16 | k = (roi * kernel).sum() 17 | output[y - pad, x - pad] = k 18 | 19 | output = rescale_intensity(output, in_range=(0, 255)) 20 | output = (output * 255).astype("uint8") 21 | return output 22 | 23 | ap = argparse.ArgumentParser() 24 | ap.add_argument("-i", "--image", required=True, 25 | help="path to the input image") 26 | args = vars(ap.parse_args()) 27 | 28 | sobelY = np.array(( 29 | [-1, -2, -1], 30 | [0, 0, 0], 31 | [1, 2, 1]), dtype="int") 32 | 33 | kernelBank = ( 34 | ("sobel_y", sobelY), 35 | ) 36 | 37 | 38 | image = cv2.imread(args["image"]) 39 | gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) 40 | 41 | for (kernelName, kernel) in kernelBank: 42 | print("[INFO] applying {} kernel".format(kernelName)) 43 | convoleOutput = convolve(gray, kernel) 44 | opencvOutput = cv2.filter2D(gray, -1, kernel) 45 | cv2.imshow("original", gray) 46 | cv2.imshow("{} - convole".format(kernelName), convoleOutput) 47 | cv2.imshow("{} - opencv".format(kernelName), opencvOutput) 48 | cv2.imwrite("SobelYChess.jpg", convoleOutput) 49 | cv2.waitKey(0) 50 | cv2.destroyAllWindows() -------------------------------------------------------------------------------- /Laplacian, Sobel, CannyEdge/sobelyLenna.py: -------------------------------------------------------------------------------- 1 | from skimage.exposure import rescale_intensity 2 | import numpy as np 3 | import argparse 4 | import cv2 5 | 6 | def convolve(image, kernel): 7 | (iH, iW) = image.shape[:2] 8 | (kH, kW) = kernel.shape[:2] 9 | pad = (kW - 1) // 2 10 | image = cv2.copyMakeBorder(image, pad, pad, pad, pad, 11 | cv2.BORDER_REPLICATE) 12 | output = np.zeros((iH, iW), dtype="float32") 13 | for y in np.arange(pad, iH + pad): 14 | for x in np.arange(pad, iW + pad): 15 | roi = image[y - pad:y + pad + 1, x - pad:x + pad + 1] 16 | k = (roi * kernel).sum() 17 | output[y - pad, x - pad] = k 18 | 19 | output = rescale_intensity(output, in_range=(0, 255)) 20 | output = (output * 255).astype("uint8") 21 | return output 22 | 23 | ap = argparse.ArgumentParser() 24 | ap.add_argument("-i", "--image", required=True, 25 | help="path to the input image") 26 | args = vars(ap.parse_args()) 27 | 28 | sobelY = np.array(( 29 | [-1, -2, -1], 30 | [0, 0, 0], 31 | [1, 2, 1]), dtype="int") 32 | 33 | kernelBank = ( 34 | ("sobel_y", sobelY), 35 | ) 36 | 37 | 38 | image = cv2.imread(args["image"]) 39 | gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) 40 | 41 | for (kernelName, kernel) in kernelBank: 42 | print("[INFO] applying {} kernel".format(kernelName)) 43 | convoleOutput = convolve(gray, kernel) 44 | opencvOutput = cv2.filter2D(gray, -1, kernel) 45 | cv2.imshow("original", gray) 46 | cv2.imshow("{} - convole".format(kernelName), convoleOutput) 47 | cv2.imshow("{} - opencv".format(kernelName), opencvOutput) 48 | cv2.imwrite("SobelYLenna.jpg", convoleOutput) 49 | cv2.waitKey(0) 50 | cv2.destroyAllWindows() -------------------------------------------------------------------------------- /Laplacian/laplacian.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Laplacian/laplacian.jpg -------------------------------------------------------------------------------- /Laplacian/laplacian.py: -------------------------------------------------------------------------------- 1 | from skimage.exposure import rescale_intensity 2 | import numpy as np 3 | import argparse 4 | import cv2 5 | 6 | def convolve(image, kernel): 7 | (iH, iW) = image.shape[:2] 8 | (kH, kW) = kernel.shape[:2] 9 | pad = (kW - 1) // 2 10 | image = cv2.copyMakeBorder(image, pad, pad, pad, pad, 11 | cv2.BORDER_REPLICATE) 12 | output = np.zeros((iH, iW), dtype="float32") 13 | for y in np.arange(pad, iH + pad): 14 | for x in np.arange(pad, iW + pad): 15 | roi = image[y - pad:y + pad + 1, x - pad:x + pad + 1] 16 | k = (roi * kernel).sum() 17 | output[y - pad, x - pad] = k 18 | 19 | output = rescale_intensity(output, in_range=(0, 255)) 20 | output = (output * 255).astype("uint8") 21 | return output 22 | 23 | ap = argparse.ArgumentParser() 24 | ap.add_argument("-i", "--image", required=True, 25 | help="path to the input image") 26 | args = vars(ap.parse_args()) 27 | 28 | laplacian = np.array(( 29 | [0, 1, 0], 30 | [1, -4, 1], 31 | [0, 1, 0]), dtype="int") 32 | 33 | 34 | kernelBank = ( 35 | ("laplacian", laplacian), 36 | ) 37 | 38 | 39 | image = cv2.imread(args["image"]) 40 | gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) 41 | cv2.imwrite("original.jpg",gray) 42 | 43 | for (kernelName, kernel) in kernelBank: 44 | print("[INFO] applying {} kernel".format(kernelName)) 45 | convoleOutput = convolve(gray, kernel) 46 | opencvOutput = cv2.filter2D(gray, -1, kernel) 47 | cv2.imshow("original", gray) 48 | cv2.imshow("{} - convole".format(kernelName), convoleOutput) 49 | cv2.imshow("{} - opencv".format(kernelName), opencvOutput) 50 | cv2.imwrite("laplacian.jpg", convoleOutput) 51 | cv2.waitKey(0) 52 | cv2.destroyAllWindows() -------------------------------------------------------------------------------- /Laplacian/monarch.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Laplacian/monarch.jpg -------------------------------------------------------------------------------- /Laplacian/original.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Laplacian/original.jpg -------------------------------------------------------------------------------- /Laplacian/pand.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Laplacian/pand.jpg -------------------------------------------------------------------------------- /Live Hand Gesture Recognition/Aptfile: -------------------------------------------------------------------------------- 1 | libsm6 2 | libxrender1 3 | libfontconfig1 4 | libice6 -------------------------------------------------------------------------------- /Live Hand Gesture Recognition/Procfile: -------------------------------------------------------------------------------- 1 | web: gunicorn app:app --log-file - -------------------------------------------------------------------------------- /Live Hand Gesture Recognition/README.md: -------------------------------------------------------------------------------- 1 | [](https://github.com/ellerbrock/open-source-badges/) [](https://github.com/Naereen/StrapDown.js) 2 | [](https://www.python.org/downloads/release/python-360/) 3 | 4 | # Live Hand Gesture Detection 5 | 6 | ## Introduction 7 | Live Gesture Recognition is an application that captures and interprets human gestures as numbers. Gesture here, can refer to any physical movement, large or small of the fingers. This project has been built using OpenCV and Python. It is based on the concepts of object segmentation. It segments one foreground obeject which in this case is our hand, from a live video sequence. 8 | 9 | ## Working 10 | 11 | The two essential parts of this project are 12 | 1. Segmentation of hand region from the video sequence 13 | 2. Counting the number of fingers from segmented region 14 | 15 | ### 1. Segmentation of the Hand Region 16 | One of the efficient methods to separate foreground from background is using the concept of running averages. More about running averages can be found over [here](http://opencvpython.blogspot.com/2012/07/background-extraction-using-running.html). The system looks over a particular number of frames of the background and runs the average of those. The background is figured out with this average. 17 | 18 | When the hand is brought inside the frame after the calibration(once the application starts, it takes 30 sec to calibrate itself according to the background), absolute difference between the background model and the current frame is obtained resulting in a single foreground object - the hand. This method so far as a whole, is known as Background subtraction. 19 | 20 | Getting the foreground object does not suffice, there is a need to threshold the difference image to make the hand region visible making all other regions black. To detect the motion of the fingers, contours are of great help. Contours of the difference image are taken and the contour with the largest area is assumed to be the hand. 21 | 22 | ### 2. Counting the number of fingers from segmented region 23 | The process of counting the fingers has five intermediate steps 24 | + Finding the convex hull of the segmented hand region. 25 | + Computing the most extreme points in the convex hull 26 | + Finding the center of the palm using t he extreme points. 27 | + Constructing a cricle around the hand with centre of the palm as origin. 28 | + Bitwise AND between the thresholded hand image and the circle(also known as ROI - Region Of Interest) 29 |  30 | 31 | ## Installation 32 | 33 | ### Pre-requisites 34 | + OpenCV 35 | + Python3 36 | + Flask 37 | 38 | ### Installation Instructions 39 | 1. Install Python3 and pip 40 | 2. Install `virtualenv` and add it to your terminal path. 41 | 3. Clone the repository and create the virtual environment 42 | ``` 43 | $ git clone https://github.com/abhishekbvs/Gesture-Detection.git 44 | $ cd Gesture-Detection 45 | ``` 46 | 4. Create a python 3 virtualenv, and activate the environment. 47 | ``` 48 | $ virtualenv -p python3 . 49 | $ source bin/activate 50 | ``` 51 | 5. Install the dependencies from `requirements.txt` 52 | ``` 53 | $ pip install -r requirements.txt 54 | ``` 55 | 6. Run the Flask application 56 | ``` 57 | $ python app.py 58 | ``` 59 | 60 | ## Team 61 | 62 | + [Bhanu Prakash](https://github.com/BhanuPrakashNani/) 63 | + [Abhishek BVS](https://github.com/abhishekbvs/) 64 | + [Bala Sai Praneeth](https://github.com/PraneethVankayala) 65 | 66 | ## Future Scope 67 | This project can be extended to understand the gestures and execute commands based on the gestures. 68 | 69 | [](https://github.com/abhishekbvs/Gesture-Detection) -------------------------------------------------------------------------------- /Live Hand Gesture Recognition/__pycache__/recognize.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Live Hand Gesture Recognition/__pycache__/recognize.cpython-36.pyc -------------------------------------------------------------------------------- /Live Hand Gesture Recognition/app.py: -------------------------------------------------------------------------------- 1 | from flask import Flask, render_template, Response 2 | from recognize import VideoCamera 3 | app = Flask(__name__) 4 | 5 | @app.route('/') 6 | def index(): 7 | return render_template('index.html') 8 | 9 | def gen(camera): 10 | while True: 11 | frame = camera.get_frame() 12 | yield (b'--frame\r\n' 13 | b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n\r\n') 14 | 15 | @app.route('/main_video_feed') 16 | def main_video_feed(): 17 | return Response(gen(VideoCamera()),mimetype='multipart/x-mixed-replace; boundary=frame') 18 | 19 | if __name__ == '__main__': 20 | app.run(threaded=True, port=5000) -------------------------------------------------------------------------------- /Live Hand Gesture Recognition/recognize.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import imutils 3 | import numpy as np 4 | from sklearn.metrics import pairwise 5 | 6 | class VideoCamera(object): 7 | def __init__(self): 8 | self.video = cv2.VideoCapture(0) 9 | self.num_frames = 0 10 | self.bg = None 11 | 12 | def __del__(self): 13 | self.video.release() 14 | 15 | def get_frame(self): 16 | try: 17 | accumWeight = 0.5 18 | calibrated = False 19 | top, right, bottom, left = 10, 350, 225, 590 20 | grabbed, frame = self.video.read() 21 | frame = imutils.resize(frame, height=530) 22 | frame = cv2.flip(frame, 1) 23 | clone = frame.copy() 24 | thresholded = np.zeros((265,295, 3), np.uint8) 25 | number = np.zeros((265,295, 3), np.uint8) 26 | (height, width) = frame.shape[:2] 27 | roi = frame[top:bottom, right:left] 28 | gray = cv2.cvtColor(roi, cv2.COLOR_BGR2GRAY) 29 | gray = cv2.GaussianBlur(gray, (7, 7), 0) 30 | 31 | if self.num_frames < 30: 32 | 33 | self.run_avg(gray, accumWeight) 34 | if self.num_frames == 1: 35 | print("[STATUS] please wait! calibrating...") 36 | elif self.num_frames == 29: 37 | print("[STATUS] calibration successfull...") 38 | self.num_frames += 1 39 | else: 40 | 41 | hand = self.segment(gray) 42 | if hand is not None: 43 | (thresholded, segmented) = hand 44 | cv2.drawContours(clone, [segmented + (right, top)], -1, (0, 0, 255)) 45 | fingers = self.count(thresholded, segmented) 46 | thresholded = imutils.resize(thresholded, height=265) 47 | thresholded = cv2.cvtColor(thresholded, cv2.COLOR_GRAY2BGR) 48 | cv2.putText(number, str(fingers), (125,150), cv2.FONT_HERSHEY_DUPLEX, 3, (255,255,255), 2) 49 | 50 | cv2.rectangle(clone, (left, top), (right, bottom), (0,255,0), 2) 51 | 52 | vertical_concat = np.concatenate((thresholded, number), axis=0) 53 | final = np.concatenate((clone, vertical_concat), axis=1) 54 | except: 55 | final = np.zeros((530,1001, 3), np.uint8) 56 | 57 | ret, jpeg = cv2.imencode('.jpg', final) 58 | return jpeg.tobytes() 59 | 60 | def run_avg(self,image, accumWeight): 61 | 62 | if self.bg is None: 63 | self.bg = image.copy().astype("float") 64 | 65 | cv2.accumulateWeighted(image, self.bg, accumWeight) 66 | 67 | def segment(self,image, threshold=25): 68 | 69 | diff = cv2.absdiff(self.bg.astype("uint8"), image) 70 | 71 | thresholded = cv2.threshold(diff, threshold, 255, cv2.THRESH_BINARY)[1] 72 | cnts,_ = cv2.findContours(thresholded.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) 73 | 74 | if len(cnts) == 0: 75 | return 76 | else: 77 | segmented = max(cnts, key=cv2.contourArea) 78 | return (thresholded, segmented) 79 | 80 | def count(self, thresholded, segmented): 81 | 82 | chull = cv2.convexHull(segmented) 83 | extreme_top = tuple(chull[chull[:, :, 1].argmin()][0]) 84 | extreme_bottom = tuple(chull[chull[:, :, 1].argmax()][0]) 85 | extreme_left = tuple(chull[chull[:, :, 0].argmin()][0]) 86 | extreme_right = tuple(chull[chull[:, :, 0].argmax()][0]) 87 | cX = int((extreme_left[0] + extreme_right[0]) / 2) 88 | cY = int((extreme_top[1] + extreme_bottom[1]) / 2) 89 | 90 | distance = pairwise.euclidean_distances([(cX, cY)], Y=[extreme_left, extreme_right, extreme_top, extreme_bottom])[0] 91 | maximum_distance = distance[distance.argmax()] 92 | radius = int(0.8 * maximum_distance) 93 | circumference = (2 * np.pi * radius) 94 | circular_roi = np.zeros(thresholded.shape[:2], dtype="uint8") 95 | cv2.circle(circular_roi, (cX, cY), radius, 255, 1) 96 | circular_roi = cv2.bitwise_and(thresholded, thresholded, mask=circular_roi) 97 | cnts,_ = cv2.findContours(circular_roi.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE) 98 | 99 | count = 0 100 | 101 | for c in cnts: 102 | (x, y, w, h) = cv2.boundingRect(c) 103 | 104 | if ((cY + (cY * 0.25)) > (y + h)) and ((circumference * 0.25) > c.shape[0]): 105 | count += 1 106 | 107 | return count -------------------------------------------------------------------------------- /Live Hand Gesture Recognition/requirements.txt: -------------------------------------------------------------------------------- 1 | Flask == 1.1.2 2 | opencv-python == 4.2.0.34 3 | imutils == 0.5.3 4 | scikit-learn == 0.23.1 5 | gunicorn == 20.0.4 -------------------------------------------------------------------------------- /Live Hand Gesture Recognition/runtime.txt: -------------------------------------------------------------------------------- 1 | python-3.7.4 -------------------------------------------------------------------------------- /Live Hand Gesture Recognition/static/image1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Live Hand Gesture Recognition/static/image1.png -------------------------------------------------------------------------------- /Live Hand Gesture Recognition/static/styles/home.css: -------------------------------------------------------------------------------- 1 | body { 2 | display:flex; 3 | flex-direction:column; 4 | min-height:95vh; 5 | text-align: center; 6 | padding: 20px 50px 0px; 7 | background-color: #f0f5f9; 8 | } 9 | h1 { 10 | font-family: 'Alegreya Sans', sans-serif; 11 | float: center; 12 | } 13 | p { 14 | font-family: 'Open Sans', sans-serif; 15 | } 16 | .header a{ 17 | display: inline; 18 | float: right; 19 | } 20 | 21 | .header h1{ 22 | display: inline; 23 | } 24 | .main-frame{ 25 | filter: drop-shadow(5px 5px 5px #222); 26 | margin: 20px 10px 20px 27 | } -------------------------------------------------------------------------------- /Live Hand Gesture Recognition/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 |This application captures and interprets human gestures as numbers. Gesture here, 17 | can refer to any physical movement, large or small of the fingers. This project has been built using Python, OpenCV and Flask. 18 | It is based on the concepts of object segmentation. It segments one foreground obeject which in this case 19 | is our hand, from a live video sequence.
20 | 21 | -------------------------------------------------------------------------------- /Log and Contrast_Stretching/contrast_stretch.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Log and Contrast_Stretching/contrast_stretch.jpg -------------------------------------------------------------------------------- /Log and Contrast_Stretching/contrast_stretching.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | 4 | # Function to map each intensity level to output intensity level. 5 | def pixelVal(pix, r1, s1, r2, s2): 6 | if (0 <= pix and pix <= r1): 7 | return (s1 / r1)*pix 8 | elif (r1 < pix and pix <= r2): 9 | return ((s2 - s1)/(r2 - r1)) * (pix - r1) + s1 10 | else: 11 | return ((255 - s2)/(255 - r2)) * (pix - r2) + s2 12 | 13 | 14 | img = cv2.imread('log.jpg') 15 | r1 = 70 16 | s1 = 0 17 | r2 = 140 18 | s2 = 255 19 | 20 | # Vectorize the function to apply it to each value in the Numpy array. 21 | pixelVal_vec = np.vectorize(pixelVal) 22 | 23 | contrast_stretched = pixelVal_vec(img, r1, s1, r2, s2) 24 | 25 | cv2.imwrite('contrast_stretch.jpg', contrast_stretched) 26 | 27 | cv2.imshow('contrast_stretch',contrast_stretched) 28 | 29 | cv2.waitKey(0) 30 | cv2.destroyAllWindows() -------------------------------------------------------------------------------- /Log and Contrast_Stretching/log.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Log and Contrast_Stretching/log.jpg -------------------------------------------------------------------------------- /Log and Contrast_Stretching/log_trans.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | 4 | img = cv2.imread('log.jpg') 5 | c = 255/(np.log(1 + np.max(img))) 6 | log_transformed = c * np.log(1 + img) 7 | 8 | # Specify the data type. 9 | log_transformed = np.array(log_transformed, dtype = np.uint8) 10 | 11 | cv2.imwrite('log_transformed.jpg', log_transformed) 12 | 13 | cv2.imshow('log_transformed',log_transformed) 14 | 15 | cv2.waitKey(0) 16 | cv2.destroyAllWindows() 17 | -------------------------------------------------------------------------------- /Log and Contrast_Stretching/log_transformed.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Log and Contrast_Stretching/log_transformed.jpg -------------------------------------------------------------------------------- /Morphological Fingerprint Processing/11.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Morphological Fingerprint Processing/11.jpg -------------------------------------------------------------------------------- /Morphological Fingerprint Processing/9-p.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Morphological Fingerprint Processing/9-p.jpg -------------------------------------------------------------------------------- /Morphological Fingerprint Processing/Closing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Morphological Fingerprint Processing/Closing.png -------------------------------------------------------------------------------- /Morphological Fingerprint Processing/ErodeDilateClose.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Morphological Fingerprint Processing/ErodeDilateClose.png -------------------------------------------------------------------------------- /Morphological Fingerprint Processing/ErosionPlusDilation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Morphological Fingerprint Processing/ErosionPlusDilation.png -------------------------------------------------------------------------------- /Morphological Fingerprint Processing/Final-ComparisionImage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Morphological Fingerprint Processing/Final-ComparisionImage.png -------------------------------------------------------------------------------- /Morphological Fingerprint Processing/Improved.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Morphological Fingerprint Processing/Improved.png -------------------------------------------------------------------------------- /Morphological Fingerprint Processing/Input.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Morphological Fingerprint Processing/Input.png -------------------------------------------------------------------------------- /Morphological Fingerprint Processing/Opening.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Morphological Fingerprint Processing/Opening.png -------------------------------------------------------------------------------- /Morphological Fingerprint Processing/Processed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Morphological Fingerprint Processing/Processed.png -------------------------------------------------------------------------------- /Morphological Fingerprint Processing/morph3.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | 4 | img = cv2.imread('11.jpg',0) 5 | img2 = cv2.imread('9-p.jpg',0) 6 | kernel = np.ones((5,5), np.uint8) 7 | kernel2 = np.ones((7,7), np.uint8) 8 | kernel3 = np.array(( 9 | [0, 1, 0], 10 | [1, 1, 1], 11 | [0, 1, 0]),dtype='uint8') 12 | 13 | img_opening = cv2.morphologyEx(img, cv2.MORPH_OPEN, kernel) 14 | img_closing = cv2.morphologyEx(img, cv2.MORPH_CLOSE, kernel) 15 | 16 | img_erosion = cv2.erode(img, kernel3, iterations=1) 17 | img_dilation = cv2.dilate(img_erosion, kernel3, iterations=1) 18 | img_opening3 = cv2.morphologyEx(img_dilation, cv2.MORPH_OPEN, kernel2) 19 | img_closing2 = cv2.morphologyEx(img_dilation, cv2.MORPH_CLOSE, kernel) 20 | img_opening2 = cv2.morphologyEx(img_closing2, cv2.MORPH_OPEN, kernel3) 21 | 22 | 23 | opening = cv2.morphologyEx(img, cv2.MORPH_OPEN, kernel) 24 | close = cv2.morphologyEx(opening, cv2.MORPH_CLOSE, kernel) 25 | 26 | cv2.imshow('Input', img) 27 | cv2.imshow('Opening', img_opening) 28 | cv2.imshow('Closing', img_closing) 29 | cv2.imshow('Erosion Plus Dilation', img_dilation) 30 | cv2.imshow('Erode + Dilate + Close',img_closing2) 31 | cv2.imshow('Processed',img_closing2) 32 | cv2.imshow('Final-Comparision Image', img2) 33 | cv2.imshow('Improved', close) 34 | 35 | 36 | cv2.imwrite('Input.png', img) 37 | cv2.imwrite('Opening.png', img_opening) 38 | cv2.imwrite('Closing.png', img_closing) 39 | cv2.imwrite('ErosionPlusDilation.png', img_dilation) 40 | cv2.imwrite('ErodeDilateClose.png',img_closing2) 41 | cv2.imwrite('Processed.png',img_closing2) 42 | cv2.imwrite('Final-ComparisionImage.png', img2) 43 | cv2.imwrite('Improved.png', close) 44 | 45 | cv2.waitKey(0) 46 | cv2.destroyAllWindows() -------------------------------------------------------------------------------- /Morphological Outline/16.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Morphological Outline/16.jpg -------------------------------------------------------------------------------- /Morphological Outline/Outline.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Morphological Outline/Outline.png -------------------------------------------------------------------------------- /Morphological Outline/morph4.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | 4 | img = cv2.imread('16.jpg',0) 5 | kernel = np.ones((5,5), np.uint8) 6 | 7 | gradient = cv2.morphologyEx(img, cv2.MORPH_GRADIENT, kernel) 8 | 9 | cv2.imshow('Input', img) 10 | cv2.imshow('Outline', gradient) 11 | 12 | cv2.imwrite('Outline.png', gradient) 13 | 14 | cv2.waitKey(0) 15 | cv2.destroyAllWindows() -------------------------------------------------------------------------------- /Morphological Processing/5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Morphological Processing/5.jpg -------------------------------------------------------------------------------- /Morphological Processing/Closing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Morphological Processing/Closing.png -------------------------------------------------------------------------------- /Morphological Processing/Dilation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Morphological Processing/Dilation.png -------------------------------------------------------------------------------- /Morphological Processing/Erosion.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Morphological Processing/Erosion.png -------------------------------------------------------------------------------- /Morphological Processing/Opening.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Morphological Processing/Opening.png -------------------------------------------------------------------------------- /Morphological Processing/morph1.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | 4 | img = cv2.imread('5.jpg',0) 5 | kernel = np.ones((5,5), np.uint8) 6 | 7 | img_erosion = cv2.erode(img, kernel, iterations=1) 8 | img_dilation = cv2.dilate(img, kernel, iterations=1) 9 | img_opening = cv2.morphologyEx(img, cv2.MORPH_OPEN, kernel) 10 | img_closing = cv2.morphologyEx(img, cv2.MORPH_CLOSE, kernel) 11 | 12 | 13 | cv2.imshow('Input', img) 14 | cv2.imshow('Erosion', img_erosion) 15 | cv2.imshow('Dilation', img_dilation) 16 | cv2.imshow('Opening', img_opening) 17 | cv2.imshow('Closing', img_closing) 18 | 19 | cv2.imwrite('Erosion.png', img_erosion) 20 | cv2.imwrite('Dilation.png', img_dilation) 21 | cv2.imwrite('Opening.png', img_opening) 22 | cv2.imwrite('Closing.png', img_closing) 23 | 24 | cv2.waitKey(0) 25 | cv2.destroyAllWindows() -------------------------------------------------------------------------------- /Morphological Text Processing/7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Morphological Text Processing/7.jpg -------------------------------------------------------------------------------- /Morphological Text Processing/Dilation + Erosion.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Morphological Text Processing/Dilation + Erosion.png -------------------------------------------------------------------------------- /Morphological Text Processing/Dilation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Morphological Text Processing/Dilation.png -------------------------------------------------------------------------------- /Morphological Text Processing/Processed 1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Morphological Text Processing/Processed 1.png -------------------------------------------------------------------------------- /Morphological Text Processing/Processed 2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Morphological Text Processing/Processed 2.png -------------------------------------------------------------------------------- /Morphological Text Processing/improved.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Morphological Text Processing/improved.jpg -------------------------------------------------------------------------------- /Morphological Text Processing/morph2.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | 4 | img = cv2.imread('7.jpg',0) 5 | kernel = np.ones((5,5), np.uint8) 6 | kernel2 = np.ones((2,2), np.uint8) 7 | 8 | img_erosion = cv2.erode(img, kernel, iterations=1) 9 | img_dilation = cv2.dilate(img, kernel2, iterations=1) 10 | img_opening = cv2.morphologyEx(img, cv2.MORPH_OPEN, kernel) 11 | img_closing = cv2.morphologyEx(img, cv2.MORPH_CLOSE, kernel) 12 | 13 | img_dilation2 = cv2.dilate(img, kernel, iterations=1) 14 | img_erosion2 = cv2.erode(img_dilation2, kernel, iterations=1) 15 | 16 | cv2.imshow('Input', img) 17 | # cv2.imshow('Erosion', img_erosion) 18 | cv2.imshow('Dilation', img_dilation) 19 | cv2.imshow('Dilation + Erosion', img_erosion2) 20 | cv2.imshow('Processed 2', img_dilation + img_closing - img_erosion + img_opening) 21 | cv2.imshow('Processed 1', img_closing - img_erosion + img_opening) 22 | 23 | cv2.imwrite('Dilation.png', img_dilation) 24 | cv2.imwrite('Dilation + Erosion.png', img_erosion2) 25 | cv2.imwrite('Processed 2.png', img_dilation + img_closing - img_erosion + img_opening) 26 | cv2.imwrite('Processed 1.png', img_closing - img_erosion + img_opening) 27 | 28 | cv2.waitKey(0) 29 | cv2.destroyAllWindows() -------------------------------------------------------------------------------- /Normalize Histogram/equilised.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Normalize Histogram/equilised.jpg -------------------------------------------------------------------------------- /Normalize Histogram/equilisedAutomated.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Normalize Histogram/equilisedAutomated.jpg -------------------------------------------------------------------------------- /Normalize Histogram/hist.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Normalize Histogram/hist.png -------------------------------------------------------------------------------- /Normalize Histogram/hist.py: -------------------------------------------------------------------------------- 1 | import cv2 as cv 2 | path = 'hist.png' 3 | img = cv.imread(path) 4 | img = cv.resize(img, (800, 800)) 5 | cv.normalize(img, None, 0, 255, cv.NORM_L1) 6 | cv.imshow('dst_rt', img) 7 | cv.imwrite('norm.png', img) 8 | cv.waitKey(0) 9 | cv.destroyAllWindows() -------------------------------------------------------------------------------- /Normalize Histogram/histogram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Normalize Histogram/histogram.png -------------------------------------------------------------------------------- /Normalize Histogram/norm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Normalize Histogram/norm.png -------------------------------------------------------------------------------- /OTSU Thresholding/Otsus.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/OTSU Thresholding/Otsus.jpg -------------------------------------------------------------------------------- /OTSU Thresholding/binarythresh1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/OTSU Thresholding/binarythresh1.jpg -------------------------------------------------------------------------------- /OTSU Thresholding/blur1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/OTSU Thresholding/blur1.jpg -------------------------------------------------------------------------------- /OTSU Thresholding/gray1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/OTSU Thresholding/gray1.jpg -------------------------------------------------------------------------------- /OTSU Thresholding/noisy_leaf.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/OTSU Thresholding/noisy_leaf.jpg -------------------------------------------------------------------------------- /OTSU Thresholding/otsu-orig.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/OTSU Thresholding/otsu-orig.png -------------------------------------------------------------------------------- /OTSU Thresholding/otsu-transform.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/OTSU Thresholding/otsu-transform.png -------------------------------------------------------------------------------- /OTSU Thresholding/thresholding.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | 4 | img = cv2.imread('noisy_leaf.jpg', cv2.IMREAD_GRAYSCALE) 5 | cv2.imshow('gray', img) 6 | cv2.imwrite('gray1.jpg',img) 7 | 8 | blur = cv2.GaussianBlur(img,(7,7),0) 9 | cv2.imshow('blur', img) 10 | cv2.imwrite('blur1.jpg',img) 11 | 12 | x,threshold = cv2.threshold(blur, 200, 255, cv2.THRESH_BINARY) 13 | cv2.imshow('Binary threshold', threshold) 14 | cv2.imwrite('binarythresh1.jpg',img) 15 | 16 | ret2,th2 = cv2.threshold(blur,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU) 17 | cv2.imshow('Otsus Thresholding', th2) 18 | cv2.imwrite('Otsus.jpg',img) 19 | 20 | cv2.waitKey(0) 21 | -------------------------------------------------------------------------------- /Object Movement Tracking/Screenshot from 2020-04-12 22-02-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Object Movement Tracking/Screenshot from 2020-04-12 22-02-01.png -------------------------------------------------------------------------------- /Object Movement Tracking/blue_cap.py: -------------------------------------------------------------------------------- 1 | #Code Resource - https://www.pyimagesearch.com/2015/09/14/ball-tracking-with-opencv/ 2 | 3 | from collections import deque 4 | import numpy as np 5 | import argparse 6 | import imutils 7 | import cv2 8 | 9 | 10 | ap = argparse.ArgumentParser() 11 | ap.add_argument("-v", "--video", 12 | help="path to the (optional) video file") 13 | ap.add_argument("-b", "--buffer", type=int, default=64, 14 | help="max buffer size") 15 | args = vars(ap.parse_args()) 16 | 17 | colorLower = (90, 100, 100) 18 | colorUpper = (110, 255, 255) 19 | pts = deque(maxlen=args["buffer"]) 20 | 21 | # if a video path was not supplied, grab the reference 22 | # to the webcam 23 | if not args.get("video", False): 24 | camera = cv2.VideoCapture(0) 25 | 26 | # otherwise, grab a reference to the video file 27 | else: 28 | camera = cv2.VideoCapture(args["video"]) 29 | 30 | 31 | while True: 32 | (grabbed, frame) = camera.read() 33 | if args.get("video") and not grabbed: 34 | break 35 | 36 | frame = imutils.resize(frame, width=600) 37 | hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) 38 | mask = cv2.inRange(hsv, colorLower, colorUpper) 39 | mask = cv2.erode(mask, None, iterations=2) 40 | mask = cv2.dilate(mask, None, iterations=2) 41 | 42 | cnts = cv2.findContours(mask.copy(), cv2.RETR_EXTERNAL, 43 | cv2.CHAIN_APPROX_SIMPLE)[-2] 44 | center = None 45 | 46 | if(len(cnts) > 0): 47 | c = max(cnts, key=cv2.contourArea) 48 | ((x, y), radius) = cv2.minEnclosingCircle(c) 49 | M = cv2.moments(c) 50 | center = (int(M["m10"] / M["m00"]), int(M["m01"] / M["m00"])) 51 | if radius > 5: 52 | cv2.circle(frame, (int(x), int(y)), int(radius), 53 | (0, 255, 255), 2) 54 | cv2.circle(frame, center, 5, (0, 0, 255), -1) 55 | pts.appendleft(center) 56 | 57 | for i in range(1, len(pts)): 58 | if pts[i - 1] is None or pts[i] is None: 59 | continue 60 | 61 | thickness = int(np.sqrt(args["buffer"] / float(i + 1)) * 2.5) 62 | cv2.line(frame, pts[i - 1], pts[i], (0, 0, 255), thickness) 63 | 64 | cv2.imshow("Frame", frame) 65 | key = cv2.waitKey(1) & 0xFF 66 | 67 | if key == ord("q"): 68 | break 69 | 70 | camera.release() 71 | cv2.destroyAllWindows() 72 | -------------------------------------------------------------------------------- /Object Movement Tracking/get_hsv.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import numpy as np 3 | import cv2 4 | 5 | blue = sys.argv[1] 6 | green = sys.argv[2] 7 | red = sys.argv[3] 8 | 9 | color = np.uint8([[[blue, green, red]]]) 10 | hsv_color = cv2.cvtColor(color, cv2.COLOR_BGR2HSV) 11 | 12 | hue = hsv_color[0][0][0] 13 | 14 | print("Lower bound is :"), 15 | print("[" + str(hue-10) + ", 100, 100]\n") 16 | 17 | print("Upper bound is :"), 18 | print("[" + str(hue + 10) + ", 255, 255]") -------------------------------------------------------------------------------- /OpenCV KMeans/building.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/OpenCV KMeans/building.png -------------------------------------------------------------------------------- /OpenCV KMeans/k=3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/OpenCV KMeans/k=3.jpg -------------------------------------------------------------------------------- /OpenCV KMeans/k=5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/OpenCV KMeans/k=5.jpg -------------------------------------------------------------------------------- /OpenCV KMeans/k=8.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/OpenCV KMeans/k=8.jpg -------------------------------------------------------------------------------- /OpenCV KMeans/kmeans.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import cv2 3 | 4 | img = cv2.imread('building.png') 5 | Z = img.reshape((-1,3)) 6 | 7 | Z = np.float32(Z) 8 | 9 | criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 10, 1.0) 10 | K = 3 11 | ret,label,center=cv2.kmeans(Z,K,None,criteria,10,cv2.KMEANS_RANDOM_CENTERS) 12 | 13 | center = np.uint8(center) 14 | res = center[label.flatten()] 15 | res2 = res.reshape((img.shape)) 16 | 17 | cv2.imshow('k=3',res2) 18 | cv2.imwrite('k=3.jpg',res2) 19 | 20 | K = 5 21 | ret,label,center=cv2.kmeans(Z,K,None,criteria,10,cv2.KMEANS_RANDOM_CENTERS) 22 | 23 | center = np.uint8(center) 24 | res = center[label.flatten()] 25 | res2 = res.reshape((img.shape)) 26 | 27 | cv2.imshow('k=5',res2) 28 | cv2.imwrite('k=5.jpg',res2) 29 | 30 | K = 8 31 | ret,label,center=cv2.kmeans(Z,K,None,criteria,10,cv2.KMEANS_RANDOM_CENTERS) 32 | 33 | center = np.uint8(center) 34 | res = center[label.flatten()] 35 | res2 = res.reshape((img.shape)) 36 | 37 | cv2.imshow('k=8',res2) 38 | cv2.imwrite('k=8.jpg',res2) 39 | cv2.waitKey(0) 40 | cv2.destroyAllWindows() -------------------------------------------------------------------------------- /Perspective Transformation/ch.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Perspective Transformation/ch.jpeg -------------------------------------------------------------------------------- /Perspective Transformation/ch.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Perspective Transformation/ch.jpg -------------------------------------------------------------------------------- /Perspective Transformation/chDistorted.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teja0508/Image_Preprocessing_Techniques/10045a4e592c9b877a70970a4e547aab630bf280/Perspective Transformation/chDistorted.jpeg -------------------------------------------------------------------------------- /Perspective Transformation/dist.py: -------------------------------------------------------------------------------- 1 | 2 | # import the required library 3 | import numpy as np 4 | import cv2 5 | from matplotlib import pyplot as plt 6 | 7 | 8 | # read the image 9 | img = cv2.imread('chDistorted.jpeg') 10 | 11 | # convert image to gray scale image 12 | gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) 13 | 14 | # detect corners with the goodFeaturesToTrack function. 15 | corners = cv2.goodFeaturesToTrack(gray, 27, 0.01, 10) 16 | corners = np.int0(corners) 17 | 18 | # we iterate through each corner, 19 | # making a circle at each point that we think is a corner. 20 | for i in corners: 21 | x, y = i.ravel() 22 | cv2.circle(img, (x, y), 3, 255, -1) 23 | 24 | (h,w) = img.shape[:2] 25 | 26 | pts1=np.float32([[0,0],[0,h],[w,0],[w,h]]) 27 | pts2=np.float32([(7.17803, 6.05628),(67.6975,198.332),(209.54, 50.1851),(231.604, 226.7)]) 28 | 29 | m = cv2.getPerspectiveTransform(pts2,pts1) 30 | img = cv2.warpPerspective(img,m,(w,h)) 31 | 32 | cv2.imshow('Perspective', img) 33 | plt.imshow(img), plt.show() 34 | cv2.waitKey(0) 35 | cv2.destroyAllWindows() 36 | 37 | -------------------------------------------------------------------------------- /Perspective Transformation/distortion.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy 3 | 4 | imgtrn = cv2.imread("chDistorted.jpeg") 5 | dimtrn = imgtrn.shape 6 | 7 | imgray = cv2.cvtColor(imgtrn, cv2.COLOR_BGR2GRAY) 8 | ret, binary = cv2.threshold(imgray, 60, 255, 0) 9 | cv2.imshow("binary",binary) 10 | contours, hierarchy = cv2.findContours(binary, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE) 11 | contours.remove(contours[0]) 12 | 13 | contours = max(contours, key=cv2.contourArea) 14 | 15 | br=[0,0] 16 | tl=[dimtrn[0],dimtrn[1]] 17 | tr=[0,dimtrn[1]] 18 | bl=[dimtrn[0],0] 19 | for i in contours: 20 | for j in i: 21 | if br[0]+br[1]