├── 24-Histogram ├── 24-Histogram.py └── color.jpg ├── Contour ├── Contour.py └── shapes.png ├── HSV-LAB-colors ├── 16-HSV-LAB-colors.py └── color.jpg ├── Morphology ├── Morphology.py └── morph.png ├── README.md ├── Thresholding ├── 1-7.jpg ├── Other-Thresholding.py ├── Other-Thresholding2.py ├── mycoins.jpg ├── mycoins2.jpg └── thresholding.py ├── add-sub-image ├── img1.jpg ├── img2.jpg ├── merge-image-W.py └── merge-image.py ├── add-sub ├── add-sub.py └── cameraman.tif ├── bitwise&masking ├── 11-bitwise.py ├── 12-bitwise&mask.py ├── bitwise&masking2.py ├── cameraman.tif ├── cow.jpg └── image-mask.py ├── canny edge ├── 19-canny edge.py └── mycoins.jpg ├── console.js ├── filter ├── 15-filter.py ├── Blur.py ├── Fil-All.py └── cameraman.tif ├── geometric shapes └── 4-line-rec-cir.py ├── img1.jpg ├── img2.jpg ├── mycoins.jpg ├── mycoins2.jpg ├── or.png ├── resize ├── 7-resize.py └── cameraman.tif ├── rotation ├── 6-rotation.py ├── 8-rotation based on x-y.py └── cameraman.tif ├── shapes.png ├── sobel image ├── 18-sobel image.py └── mycoins.jpg ├── split colors ├── 13-split colors.py └── color.jpg ├── temple.png └── transition ├── 5-transition.py └── cameraman.tif /24-Histogram/24-Histogram.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import matplotlib.pyplot as plt 3 | import tkinter 4 | import cv2 5 | #Plot Histogram 6 | image = cv2.imread("color.jpg") 7 | gray = cv2.cvtColor(image,cv2.COLOR_RGB2GRAY) 8 | hist = cv2.calcHist(gray,[0],None,[256],[0,256]) 9 | plt.figure() 10 | plt.title("Histogram Of This Image") 11 | plt.xlabel("Bins") 12 | plt.ylabel("Sharp(#) Of Pixels") 13 | plt.plot(hist) 14 | plt.xlim([0,256]) 15 | 16 | #Normalizing Histogram 17 | hist /=hist.sum() 18 | plt.figure() 19 | plt.title("Normalaized Histogram Of This Image") 20 | plt.xlabel("Bins") 21 | plt.ylabel("Sharp(#) Of Pixels") 22 | plt.plot(hist) 23 | plt.xlim([0,256]) 24 | #Color Histogram 25 | plt.figure() 26 | colors = ("b","g","r") 27 | chans = cv2.split(image) 28 | for (color,chan) in zip(colors,chans): 29 | hist = cv2.calcHist([chan],[0],None,[256],[0,256]) 30 | plt.plot(hist,color=color) 31 | plt.xlim([0,256]) 32 | 33 | plt.show() -------------------------------------------------------------------------------- /24-Histogram/color.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AISoltani/Image_Processing_Tools/ba786b0cf307ff769128dfa80325687024f819f0/24-Histogram/color.jpg -------------------------------------------------------------------------------- /Contour/Contour.py: -------------------------------------------------------------------------------- 1 | from skimage.filters import threshold_otsu, threshold_adaptive 2 | import cv2 3 | 4 | image = cv2.imread("shapes.png") 5 | gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY) 6 | (t,thresh) = cv2.threshold(gray,10,255,cv2.THRESH_BINARY) 7 | cv2.imshow("Thresh",thresh) 8 | 9 | #Contour 10 | 11 | (_,cnts,_) = cv2.findContours(thresh,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE) 12 | for (i, c) in enumerate(cnts): 13 | cv2.drawContours(image,[c],-1,(0,255,0),2) 14 | 15 | cv2.imshow("Contours",image) 16 | cv2.waitKey(0) 17 | -------------------------------------------------------------------------------- /Contour/shapes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AISoltani/Image_Processing_Tools/ba786b0cf307ff769128dfa80325687024f819f0/Contour/shapes.png -------------------------------------------------------------------------------- /HSV-LAB-colors/16-HSV-LAB-colors.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import cv2 3 | 4 | image = cv2.imread("color.jpg") 5 | #HSV Image 6 | hsv_image = cv2.cvtColor(image,cv2.COLOR_BGR2HSV) 7 | cv2.imshow("Orginal Image",image) 8 | cv2.imshow("HSV Image",hsv_image) 9 | for (name,chan) in zip("HSV",cv2.split(hsv_image)): 10 | cv2.imshow(name,chan) 11 | #LAB Image 12 | lab_image = cv2.cvtColor(image,cv2.COLOR_BGR2LAB) 13 | cv2.imshow("LAB Image",lab_image) 14 | 15 | cv2.waitKey(0) 16 | cv2.destroyAllWindows() 17 | 18 | for (name,chan) in zip("LAB",cv2.split(lab_image)): 19 | cv2.imshow(name,chan) 20 | 21 | 22 | cv2.waitKey(0) -------------------------------------------------------------------------------- /HSV-LAB-colors/color.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AISoltani/Image_Processing_Tools/ba786b0cf307ff769128dfa80325687024f819f0/HSV-LAB-colors/color.jpg -------------------------------------------------------------------------------- /Morphology/Morphology.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | 4 | image = cv2.imread('morph.png', 0) 5 | 6 | cv2.imshow('Original', image) 7 | cv2.waitKey(0) 8 | 9 | # Let's define our kernel size 10 | kernel = np.ones((5,5), np.uint8) 11 | 12 | # Now we erode 13 | erosion = cv2.erode(image, kernel, iterations = 1) 14 | cv2.imshow('Erosion', erosion) 15 | cv2.waitKey(0) 16 | 17 | # 18 | dilation = cv2.dilate(image, kernel, iterations = 1) 19 | cv2.imshow('Dilation', dilation) 20 | cv2.waitKey(0) 21 | 22 | # Opening - Good for removing noise 23 | opening = cv2.morphologyEx(image, cv2.MORPH_OPEN, kernel) 24 | cv2.imshow('Opening', opening) 25 | cv2.waitKey(0) 26 | 27 | # Closing - Good for removing noise 28 | closing = cv2.morphologyEx(image, cv2.MORPH_CLOSE, kernel) 29 | cv2.imshow('Closing', closing) 30 | cv2.waitKey(0) 31 | 32 | 33 | cv2.destroyAllWindows() 34 | -------------------------------------------------------------------------------- /Morphology/morph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AISoltani/Image_Processing_Tools/ba786b0cf307ff769128dfa80325687024f819f0/Morphology/morph.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Image_Processing_Tools 2 | Processing makes it simple to handle images, iterate over the pixels of an image and perform operations on them. here we use OpenCV Tools, OpenCV offers all kinds of algorithms from basic image processing to advanced computer vision 3 | 4 | Image processing is the process of transforming an image into a digital form and performing certain operations to get some useful information from it. The image processing system usually treats all images as 2D signals when applying certain predetermined signal processing methods. 5 | We have provided several of the most useful tools here. The codes are written as simply as possible, which helps a lot in learning them. 6 | 7 | Before we jump into image processing, we need to first understand what exactly constitutes an image. An image is represented by its dimensions (height and width) based on the number of pixels. For example, if the dimensions of an image are 500 x 400 (width x height), the total number of pixels in the image is 200000. 8 | 9 | This pixel is a point on the image that takes on a specific shade, opacity or color. It is usually represented in one of the following: 10 | 11 | Grayscale - A pixel is an integer with a value between 0 to 255 (0 is completely black and 255 is completely white). 12 | 13 | RGB - A pixel is made up of 3 integers between 0 to 255 (the integers represent the intensity of red, green, and blue). 14 | 15 | RGBA - It is an extension of RGB with an added alpha field, which represents the opacity of the image. 16 | 17 | Image processing requires fixed sequences of operations that are performed at each pixel of an image. The image processor performs the first sequence of operations on the image, pixel by pixel. Once this is fully done, it will begin to perform the second operation, and so on. The output value of these operations can be computed at any pixel of the image 18 | 19 | 20 | Image Acquisition 21 | Image acquisition is the first step in image processing. This step is also known as preprocessing in image processing. It involves retrieving the image from a source, usually a hardware-based source. 22 | 23 | Image Enhancement 24 | Image enhancement is the process of bringing out and highlighting certain features of interest in an image that has been obscured. This can involve changing the brightness, contrast, etc. 25 | 26 | Image Restoration 27 | Image restoration is the process of improving the appearance of an image. However, unlike image enhancement, image restoration is done using certain mathematical or probabilistic models. 28 | 29 | Color Image Processing 30 | Color image processing includes a number of color modeling techniques in a digital domain. This step has gained prominence due to the significant use of digital images over the internet. 31 | 32 | Wavelets and Multiresolution Processing 33 | Wavelets are used to represent images in various degrees of resolution. The images are subdivided into wavelets or smaller regions for data compression and for pyramidal representation. 34 | 35 | Compression 36 | Compression is a process used to reduce the storage required to save an image or the bandwidth required to transmit it. This is done particularly when the image is for use on the Internet. 37 | 38 | Morphological Processing 39 | Morphological processing is a set of processing operations for morphing images based on their shapes. 40 | -------------------------------------------------------------------------------- /Thresholding/1-7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AISoltani/Image_Processing_Tools/ba786b0cf307ff769128dfa80325687024f819f0/Thresholding/1-7.jpg -------------------------------------------------------------------------------- /Thresholding/Other-Thresholding.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import cv2 3 | 4 | # Load our image as greyscale 5 | image = cv2.imread('cameraman.tif',0) 6 | cv2.imshow('Original', image) 7 | 8 | # Values below 127 goes to 0 (black, everything above goes to 255 (white) 9 | ret,thresh1 = cv2.threshold(image, 127, 255, cv2.THRESH_BINARY) 10 | cv2.imshow('1 Threshold Binary', thresh1) 11 | 12 | # Values below 127 go to 255 and values above 127 go to 0 (reverse of above) 13 | ret,thresh2 = cv2.threshold(image, 127, 255, cv2.THRESH_BINARY_INV) 14 | cv2.imshow('2 Threshold Binary Inverse', thresh2) 15 | 16 | # Values above 127 are truncated (held) at 127 (the 255 argument is unused) 17 | ret,thresh3 = cv2.threshold(image, 127, 255, cv2.THRESH_TRUNC) 18 | cv2.imshow('3 THRESH TRUNC', thresh3) 19 | 20 | # Values below 127 go to 0, above 127 are unchanged 21 | ret,thresh4 = cv2.threshold(image, 127, 255, cv2.THRESH_TOZERO) 22 | cv2.imshow('4 THRESH TOZERO', thresh4) 23 | 24 | # Resever of above, below 127 is unchanged, above 127 goes to 0 25 | ret,thresh5 = cv2.threshold(image, 127, 255, cv2.THRESH_TOZERO_INV) 26 | cv2.imshow('5 THRESH TOZERO INV', thresh5) 27 | cv2.waitKey(0) 28 | 29 | cv2.destroyAllWindows() 30 | -------------------------------------------------------------------------------- /Thresholding/Other-Thresholding2.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | 4 | # Load our new image 5 | image = cv2.imread('cameraman.tif', 0) 6 | 7 | cv2.imshow('Original', image) 8 | cv2.waitKey(0) 9 | 10 | # Values below 127 goes to 0 (black, everything above goes to 255 (white) 11 | ret,thresh1 = cv2.threshold(image, 127, 255, cv2.THRESH_BINARY) 12 | cv2.imshow('Threshold Binary', thresh1) 13 | cv2.waitKey(0) 14 | 15 | 16 | 17 | # Using adaptiveThreshold 18 | thresh = cv2.adaptiveThreshold(image, 255, cv2.ADAPTIVE_THRESH_MEAN_C, 19 | cv2.THRESH_BINARY, 3, 5) 20 | cv2.imshow("Adaptive Mean Thresholding", thresh) 21 | cv2.waitKey(0) 22 | 23 | # Using adaptiveThreshold + GaussianBlur 24 | blur = cv2.GaussianBlur(image,(5,5),0) 25 | thresh = cv2.adaptiveThreshold(blur, 255, cv2.ADAPTIVE_THRESH_MEAN_C, 26 | cv2.THRESH_BINARY, 3, 5) 27 | cv2.imshow("Adaptive Mean Thresholding with GaussianBlur", thresh) 28 | cv2.waitKey(0) 29 | 30 | 31 | ret2,th2 = cv2.threshold(image,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU) 32 | cv2.imshow("Otsu's Thresholding", th2) 33 | cv2.waitKey(0) 34 | 35 | # Otsu's thresholding after Gaussian filtering 36 | blur = cv2.GaussianBlur(image,(5,5),0) 37 | ret3,th3 = cv2.threshold(blur,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU) 38 | cv2.imshow("Guassian Otsu's Thresholding", th3) 39 | cv2.waitKey(0) 40 | 41 | cv2.destroyAllWindows() 42 | -------------------------------------------------------------------------------- /Thresholding/mycoins.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AISoltani/Image_Processing_Tools/ba786b0cf307ff769128dfa80325687024f819f0/Thresholding/mycoins.jpg -------------------------------------------------------------------------------- /Thresholding/mycoins2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AISoltani/Image_Processing_Tools/ba786b0cf307ff769128dfa80325687024f819f0/Thresholding/mycoins2.jpg -------------------------------------------------------------------------------- /Thresholding/thresholding.py: -------------------------------------------------------------------------------- 1 | from skimage.filters import threshold_otsu, threshold_adaptive 2 | import cv2 3 | 4 | image = cv2.imread("1-7.jpg") 5 | gray = image#cv2.cvtColor(image,cv2.COLOR_BGR2GRAY) 6 | 7 | #Simple thresholding 8 | 9 | #(T,thresh) = cv2.threshold(gray.copy(),100,255,cv2.THRESH_BINARY) 10 | #(T2,thresh1) = cv2.threshold(gray,100,255,cv2.THRESH_BINARY_INV) 11 | #cv2.imshow("Simple Thresholding",thresh) 12 | #cv2.imshow("Simple Thresholding_INV",thresh1) 13 | #cv2.waitKey(0) 14 | #print("Threshold Value",T) 15 | #cv2.destroyAllWindows() 16 | 17 | 18 | #Otsu thresholding 19 | 20 | #(T2,thresh2) = cv2.threshold(gray.copy(),0,255,cv2.THRESH_OTSU) 21 | #cv2.imshow("Otsu Thresholding",thresh2) 22 | #cv2.waitKey(0) 23 | #print("Threshold Otsu Value:",T2) 24 | #cv2.destroyAllWindows() 25 | 26 | 27 | #Adaptive Thresholding 28 | 29 | #thresh3=cv2.adaptiveThreshold(gray.copy(),255,cv2.ADAPTIVE_THRESH_MEAN_C,cv2.THRESH_BINARY,35,10) 30 | #cv2.imshow("Adaptive Threshold",thresh3) 31 | #cv2.imshow("Adaptive Threshold Bitwise",cv2.bitwise_not(thresh3)) 32 | #cv2.waitKey(0) 33 | #cv2.destroyAllWindows() 34 | 35 | 36 | #Scikit Image Thresholding 37 | 38 | thresh4 = (threshold_adaptive(gray.copy(),35,offset=10)).astype("uint8")*255 39 | cv2.imshow("Scikit Thresholding",thresh4) 40 | cv2.imshow("Scikit Thresholding Bitwise",cv2.bitwise_not(thresh4)) 41 | cv2.waitKey(0) 42 | cv2.destroyAllWindows() 43 | 44 | 45 | #Show Forground 46 | 47 | 48 | cv2.imshow("Forground",cv2.bitwise_and(image.copy(),image.copy(),mask = cv2.bitwise_not(thresh4))) 49 | cv2.waitKey(0) 50 | cv2.destroyAllWindows() 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /add-sub-image/img1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AISoltani/Image_Processing_Tools/ba786b0cf307ff769128dfa80325687024f819f0/add-sub-image/img1.jpg -------------------------------------------------------------------------------- /add-sub-image/img2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AISoltani/Image_Processing_Tools/ba786b0cf307ff769128dfa80325687024f819f0/add-sub-image/img2.jpg -------------------------------------------------------------------------------- /add-sub-image/merge-image-W.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | 4 | img1 = cv2.imread('img1.jpg') 5 | img2 = cv2.imread('img2.jpg') 6 | dst = cv2.addWeighted(img1,0.7,img2,0.3,0) 7 | cv2.imshow('dst',dst) 8 | 9 | cv2.waitKey(0) 10 | cv2.destroyAllWindows() 11 | -------------------------------------------------------------------------------- /add-sub-image/merge-image.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | 4 | img1 = cv2.imread('img1.jpg') 5 | img2 = cv2.imread('img2.jpg') 6 | 7 | cv2.imshow("ml", img1) 8 | cv2.imshow("opencv", img2) 9 | 10 | cv2.waitKey(0) 11 | 12 | output_image = cv2.add(img1,img2) 13 | cv2.imshow("out", output_image) 14 | 15 | 16 | print(img1.shape) 17 | print(img2.shape) 18 | print(output_image.shape) 19 | 20 | cv2.waitKey(0) 21 | cv2.destroyAllWindows() 22 | -------------------------------------------------------------------------------- /add-sub/add-sub.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | 4 | image = cv2.imread('cameraman.tif') 5 | 6 | M = np.ones(image.shape, dtype = "uint8") * 100 7 | 8 | cv2.imshow("Original", image) 9 | cv2.waitKey(0) 10 | 11 | added = cv2.add(image, M) 12 | cv2.imshow("Added", added) 13 | 14 | subtracted = cv2.subtract(image, M) 15 | cv2.imshow("Subtracted", subtracted) 16 | 17 | cv2.waitKey(0) 18 | cv2.destroyAllWindows() 19 | -------------------------------------------------------------------------------- /add-sub/cameraman.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AISoltani/Image_Processing_Tools/ba786b0cf307ff769128dfa80325687024f819f0/add-sub/cameraman.tif -------------------------------------------------------------------------------- /bitwise&masking/11-bitwise.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import cv2 3 | image1 = np.zeros((300,300),dtype="uint8") 4 | image2 = np.zeros((300,300),dtype="uint8") 5 | cv2.rectangle(image1,(130,130),(170,170),(255),-1) 6 | cv2.circle(image2,(150,150),100,255,-1) 7 | cv2.imshow("And",cv2.bitwise_and(image1,image2)) 8 | cv2.imshow("Or",cv2.bitwise_or(image1,image2)) 9 | cv2.imshow("XOr",cv2.bitwise_xor(image1,image2)) 10 | cv2.imshow("Not 1",cv2.bitwise_not(image1)) 11 | cv2.imshow("Not 2",cv2.bitwise_not(image2)) 12 | cv2.waitKey(0) -------------------------------------------------------------------------------- /bitwise&masking/12-bitwise&mask.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import cv2 3 | 4 | image = cv2.imread("cameraman.tif") 5 | mask1 = np.zeros((image.shape[:2]),dtype="uint8") 6 | mask2 = np.zeros((image.shape[:2]),dtype="uint8") 7 | 8 | #rectange or circle mask 9 | cv2.rectangle(mask1,(100,100),(156,156),255,-1) 10 | cv2.circle(mask2,(int(mask2.shape[1]/2),int(mask2.shape[0]/2)),50,255,-1) 11 | cv2.imshow("Mask 1",mask1) 12 | cv2.imshow("Mask 2",mask2) 13 | cv2.imshow("Filter 1",cv2.bitwise_and(image.copy(),image.copy(),mask=mask1)) 14 | cv2.imshow("Filter 2",cv2.bitwise_and(image,image,mask=mask2)) 15 | 16 | cv2.waitKey(0) 17 | cv2.destroyAllWindows() 18 | -------------------------------------------------------------------------------- /bitwise&masking/bitwise&masking2.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | 4 | square = np.zeros((300, 300), np.uint8) 5 | cv2.rectangle(square, (50, 50), (250, 250), 255, -1) 6 | cv2.imshow("Square", square) 7 | cv2.waitKey(0) 8 | 9 | 10 | ellipse = np.zeros((300, 300), np.uint8) 11 | cv2.ellipse(ellipse, (150, 150), (150, 150), 30, 0, 180, 255, -1) 12 | cv2.imshow("Ellipse", ellipse) 13 | # Shows only where they intersect 14 | And = cv2.bitwise_and(square, ellipse) 15 | cv2.imshow("AND", And) 16 | cv2.waitKey(0) 17 | 18 | # Shows where either square or ellipse is 19 | bitwiseOr = cv2.bitwise_or(square, ellipse) 20 | cv2.imshow("OR", bitwiseOr) 21 | cv2.waitKey(0) 22 | 23 | # Shows where either exist by itself 24 | bitwiseXor = cv2.bitwise_xor(square, ellipse) 25 | cv2.imshow("XOR", bitwiseXor) 26 | cv2.waitKey(0) 27 | 28 | # Shows everything that isn't part of the square 29 | bitwiseNot_sq = cv2.bitwise_not(square) 30 | cv2.imshow("NOT - square", bitwiseNot_sq) 31 | cv2.waitKey(0) 32 | 33 | ### Notice the last operation inverts the image totally 34 | 35 | cv2.destroyAllWindows() 36 | -------------------------------------------------------------------------------- /bitwise&masking/cameraman.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AISoltani/Image_Processing_Tools/ba786b0cf307ff769128dfa80325687024f819f0/bitwise&masking/cameraman.tif -------------------------------------------------------------------------------- /bitwise&masking/cow.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AISoltani/Image_Processing_Tools/ba786b0cf307ff769128dfa80325687024f819f0/bitwise&masking/cow.jpg -------------------------------------------------------------------------------- /bitwise&masking/image-mask.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | 4 | # You can use any input format... 5 | 6 | image = cv2.imread('cow.jpg') 7 | cropped = image[100:600 , 150:650] 8 | cv2.imshow("Beautiful Cow!", cropped) 9 | cv2.waitKey(0) 10 | 11 | circle = np.zeros((500,500,3), np.uint8) 12 | cv2.circle(circle, (250, 250), 250, (255,255,255), -1) 13 | cv2.imshow("Circle", circle) 14 | cv2.waitKey(0) 15 | 16 | output_image = cv2.bitwise_and(cropped, circle) 17 | cv2.imshow("Output Image", output_image) 18 | cv2.waitKey(0) 19 | 20 | cv2.destroyAllWindows() 21 | -------------------------------------------------------------------------------- /canny edge/19-canny edge.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import cv2 3 | 4 | image=cv2.imread("mycoins.jpg") 5 | gray=cv2.cvtColor(image,cv2.COLOR_BGR2GRAY) 6 | #ksize ro mitoni kamo ziad koni 7 | blur=cv2.GaussianBlur(gray,(7,7),0) 8 | canny=cv2.Canny(blur,50,200) 9 | cv2.imshow("Canny",canny) 10 | cv2.waitKey(0) 11 | -------------------------------------------------------------------------------- /canny edge/mycoins.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AISoltani/Image_Processing_Tools/ba786b0cf307ff769128dfa80325687024f819f0/canny edge/mycoins.jpg -------------------------------------------------------------------------------- /console.js: -------------------------------------------------------------------------------- 1 | //Hey this is the comment 2 | console.log("Hello World") 3 | -------------------------------------------------------------------------------- /filter/15-filter.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import cv2 3 | 4 | image=cv2.imread("content.jpg") 5 | kernel = (7,7) 6 | 7 | #simple blue 8 | simple_blur = cv2.blur(image,kernel) 9 | cv2.imshow("Simple Blur",simple_blur) 10 | cv2.imshow("Orginal",image) 11 | 12 | #Gussian blur 13 | Gussian_blur = cv2.GaussianBlur(image,kernel,0) 14 | cv2.imshow("Gussian Blur",Gussian_blur) 15 | 16 | #Median blue 17 | Median_Blur = cv2.medianBlur(image,7) 18 | cv2.imshow("Median Blur,",Median_Blur) 19 | cv2.waitKey(0) 20 | 21 | -------------------------------------------------------------------------------- /filter/Blur.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | 4 | image = cv2.imread('cameraman.tif') 5 | cv2.imshow('Original Image', image) 6 | cv2.waitKey(0) 7 | 8 | # Creating our 3 x 3 kernel 9 | kernel_3x3 = np.ones((3, 3), np.float32) / 9 10 | 11 | # We use the cv2.fitler2D to conovlve the kernal with an image 12 | blurred = cv2.filter2D(image, -1, kernel_3x3) 13 | cv2.imshow('3x3 Kernel Blurring', blurred) 14 | cv2.waitKey(0) 15 | 16 | # Creating our 7 x 7 kernel 17 | kernel_7x7 = np.ones((7, 7), np.float32) / 49 18 | 19 | blurred2 = cv2.filter2D(image, -1, kernel_7x7) 20 | cv2.imshow('7x7 Kernel Blurring', blurred2) 21 | cv2.waitKey(0) 22 | 23 | cv2.destroyAllWindows() 24 | -------------------------------------------------------------------------------- /filter/Fil-All.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | 4 | image = cv2.imread('cameraman.tif') 5 | cv2.imshow('original', image) 6 | cv2.waitKey(0) 7 | 8 | # Averaging done by convolving the image with a normalized box filter. 9 | # This takes the pixels under the box and replaces the central element 10 | # Box size needs to odd and positive 11 | blur = cv2.blur(image, (3,3)) 12 | cv2.imshow('Averaging', blur) 13 | cv2.waitKey(0) 14 | 15 | # Instead of box filter, gaussian kernel 16 | Gaussian = cv2.GaussianBlur(image, (7,7), 0) 17 | cv2.imshow('Gaussian Blurring', Gaussian) 18 | cv2.waitKey(0) 19 | 20 | # Takes median of all the pixels under kernel area and central 21 | # element is replaced with this median value 22 | median = cv2.medianBlur(image, 5) 23 | cv2.imshow('Median Blurring', median) 24 | cv2.waitKey(0) 25 | 26 | # Bilateral is very effective in noise removal while keeping edges sharp 27 | bilateral = cv2.bilateralFilter(image, 9, 75, 75) 28 | cv2.imshow('Bilateral Blurring', bilateral) 29 | cv2.waitKey(0) 30 | cv2.destroyAllWindows() 31 | -------------------------------------------------------------------------------- /filter/cameraman.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AISoltani/Image_Processing_Tools/ba786b0cf307ff769128dfa80325687024f819f0/filter/cameraman.tif -------------------------------------------------------------------------------- /geometric shapes/4-line-rec-cir.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | black=np.zeros((300,300,3),dtype="uint8") 4 | 5 | # cv2.line(black,(150,0),(150,300),(255,255,0),10) 6 | # cv2.rectangle(black,(130,130),(300,170),(0,255,0),-1) 7 | # black[130:170,:]=(-160,255,0) 8 | # (h,w)=black.shape[:2] 9 | # #for i in range(10,120,10): 10 | # # black2=cv2.circle(black,(int(h/2),int(w/2)),i,(255,0,0),2) 11 | # b=np.random.randint(0,255) 12 | # g=np.random.randint(0,255) 13 | # r=np.random.randint(0,255) 14 | # color=(b,g,r) 15 | # h2=np.random.randint(0,h) 16 | # w2=np.random.randint(0,w) 17 | # cv2.circle(black,(h2,w2),100,color,2) 18 | # cv2.imshow("black",black) 19 | 20 | 21 | image=cv2.imread("cameraman.tif") 22 | kernel = (7,7) 23 | 24 | #simple blue 25 | #simple_blur = cv2.blur(image.copy(),kernel) 26 | #cv2.imshow("Simple Blur",simple_blur) 27 | cv2.imshow("Simple Blur",image) 28 | cv2.waitKey(0) 29 | #Gussian blur 30 | 31 | #Median blue 32 | 33 | 34 | cv2.waitKey(0) 35 | -------------------------------------------------------------------------------- /img1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AISoltani/Image_Processing_Tools/ba786b0cf307ff769128dfa80325687024f819f0/img1.jpg -------------------------------------------------------------------------------- /img2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AISoltani/Image_Processing_Tools/ba786b0cf307ff769128dfa80325687024f819f0/img2.jpg -------------------------------------------------------------------------------- /mycoins.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AISoltani/Image_Processing_Tools/ba786b0cf307ff769128dfa80325687024f819f0/mycoins.jpg -------------------------------------------------------------------------------- /mycoins2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AISoltani/Image_Processing_Tools/ba786b0cf307ff769128dfa80325687024f819f0/mycoins2.jpg -------------------------------------------------------------------------------- /or.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AISoltani/Image_Processing_Tools/ba786b0cf307ff769128dfa80325687024f819f0/or.png -------------------------------------------------------------------------------- /resize/7-resize.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | 3 | image = cv2.imread("cameraman.tif") 4 | (h,w) = image.shape[:2] 5 | #height 6 | r = 50/float(w) 7 | dim = (50,int(r*h)) 8 | image0 = cv2.resize(image.copy(),dim,cv2.INTER_AREA) 9 | cv2.imshow("Resize-H",image0) 10 | #wight 11 | r = 50/float(h) 12 | dim = (int(r*h),50) 13 | image1 = cv2.resize(image.copy(),dim,cv2.INTER_AREA) 14 | cv2.imshow("Resize-W",image1) 15 | 16 | 17 | cv2.waitKey(0) -------------------------------------------------------------------------------- /resize/cameraman.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AISoltani/Image_Processing_Tools/ba786b0cf307ff769128dfa80325687024f819f0/resize/cameraman.tif -------------------------------------------------------------------------------- /rotation/6-rotation.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import cv2 3 | 4 | image = cv2.imread("cameraman.tif") 5 | (h,w) = image.shape[:2 6 | x = w/2 7 | y = w/2 8 | m = cv2.getRotationMatrix2D((x,y),-90,1) 9 | cv2.warpAffine(image,m,(w,h),image) 10 | cv2.imshow("Rotate",image) 11 | cv2.waitKey(0) -------------------------------------------------------------------------------- /rotation/8-rotation based on x-y.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | #Horizontal 3 | image=cv2.imread('cameraman.tif') 4 | cv2.flip(image,1,image) 5 | cv2.imshow("Horizontal",image) 6 | 7 | 8 | #Vertical 9 | image=cv2.imread('cameraman.tif') 10 | cv2.flip(image,0,image) 11 | cv2.imshow("Vertical",image) 12 | 13 | #Both 14 | image=cv2.imread('cameraman.tif') 15 | cv2.flip(image,-1,image) 16 | cv2.imshow("Both",image) 17 | cv2.waitKey(0) 18 | -------------------------------------------------------------------------------- /rotation/cameraman.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AISoltani/Image_Processing_Tools/ba786b0cf307ff769128dfa80325687024f819f0/rotation/cameraman.tif -------------------------------------------------------------------------------- /shapes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AISoltani/Image_Processing_Tools/ba786b0cf307ff769128dfa80325687024f819f0/shapes.png -------------------------------------------------------------------------------- /sobel image/18-sobel image.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import cv2 3 | 4 | image=cv2.imread("mycoins.jpg") 5 | #Sobel kernel 6 | gray=cv2.cvtColor(image,cv2.COLOR_BGR2GRAY) 7 | gx=cv2.Sobel(gray,ddepth=cv2.CV_64F,dx=1,dy=0) 8 | gy=cv2.Sobel(gray,ddepth=cv2.CV_64F,dx=0,dy=1) 9 | 10 | gx=cv2.convertScaleAbs(gx) 11 | gy=cv2.convertScaleAbs(gy) 12 | 13 | cv2.imshow("Gx",gx) 14 | cv2.imshow("Gy",gy) 15 | 16 | sobel=cv2.addWeighted(gx,0.5,gy,0.5,0) 17 | cv2.imshow("Sobel Image",sobel) 18 | cv2.waitKey(0) -------------------------------------------------------------------------------- /sobel image/mycoins.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AISoltani/Image_Processing_Tools/ba786b0cf307ff769128dfa80325687024f819f0/sobel image/mycoins.jpg -------------------------------------------------------------------------------- /split colors/13-split colors.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import cv2 3 | image = cv2.imread("color.jpeg") 4 | (B,G,R) = cv2.split(image) 5 | cv2.imshow("B",B) 6 | cv2.imshow("G",G) 7 | cv2.imshow("R",R) 8 | cv2.imshow("Image",cv2.merge([B,G,R])) 9 | zeros = np.zeros(image.shape[:2],dtype="uint8") 10 | cv2.imshow("Blue" , cv2.merge([B,zeros,zeros])) 11 | cv2.imshow("Green",cv2.merge([zeros,G,zeros])) 12 | cv2.imshow("Red", cv2.merge([zeros,zeros,R])) 13 | cv2.waitKey(0) 14 | -------------------------------------------------------------------------------- /split colors/color.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AISoltani/Image_Processing_Tools/ba786b0cf307ff769128dfa80325687024f819f0/split colors/color.jpg -------------------------------------------------------------------------------- /temple.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AISoltani/Image_Processing_Tools/ba786b0cf307ff769128dfa80325687024f819f0/temple.png -------------------------------------------------------------------------------- /transition/5-transition.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import cv2 3 | 4 | image=cv2.imread('cameraman.tif') 5 | m=np.float32([[1,0,35],[0,1,40]]) 6 | cv2.warpAffine(image,m,(image.shape[1],image.shape[0]),image) 7 | #or 8 | image=cv2.warpAffine(image,m,(image.shape[1],image.shape[0])) 9 | cv2.imshow("Transition",image) 10 | cv2.waitKey(0) 11 | -------------------------------------------------------------------------------- /transition/cameraman.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AISoltani/Image_Processing_Tools/ba786b0cf307ff769128dfa80325687024f819f0/transition/cameraman.tif --------------------------------------------------------------------------------