├── 1_Read_and_show_Image ├── lena.png └── one.py ├── 2_Gray_Scale ├── lena.png └── two.py ├── 3_Image_Histogram ├── lena.png └── three.py ├── 4_Add_noise ├── four.py └── lena.png ├── 5_Flip_Image ├── five.py └── lena.png ├── 6_Add_Constant_to_image ├── lena.png └── sixx.py ├── 7_Convert_RGB_to_HSV_color_map ├── lena.png └── seven.py ├── README.md ├── lena.png └── youtube.png /1_Read_and_show_Image/lena.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaeDukSeo/Python_Basic_Image_Processing/bb82ba2fcfef27ff9df9f192ead6ad0997557883/1_Read_and_show_Image/lena.png -------------------------------------------------------------------------------- /1_Read_and_show_Image/one.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | # For this tutorial series you only need python scipy and matplotlib to display image 4 | from scipy import misc 5 | 6 | # 0. Read the image 7 | image = misc.imread('lena.png') 8 | 9 | # 1. Print the type of the image read 10 | print type(image) 11 | # You will see : 12 | # This indicates that the images are represented by an array values. 13 | 14 | # 2. Get the width and height of the image 15 | width,height,dim = image.shape 16 | 17 | print "Image width : ",width 18 | print "Image height: ", height 19 | print "Image Dim : ", dim 20 | # If image dimension is 3 then this indicates that it is a color image 21 | 22 | import matplotlib.pyplot as plt 23 | 24 | # 3. Display image 25 | plt.imshow(image) 26 | plt.show() 27 | 28 | -------------------------------------------------------------------------------- /2_Gray_Scale/lena.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaeDukSeo/Python_Basic_Image_Processing/bb82ba2fcfef27ff9df9f192ead6ad0997557883/2_Gray_Scale/lena.png -------------------------------------------------------------------------------- /2_Gray_Scale/two.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | # For this tutorial series you only need python scipy and matplotlib to display image 4 | from scipy import misc 5 | import numpy as np 6 | 7 | # 0. Read the image 8 | image = misc.imread('lena.png') 9 | 10 | # 1. Get the image width, height, and dim of color image 11 | width_col,height_col,dim_col = image.shape 12 | 13 | # 2. Convert the image into gray scale 14 | image_gray = misc.imread('lena.png') 15 | 16 | # 3. Operation of dot prodcut to get each channel's porportion 17 | image_gray = np.dot(image_gray[...,:3],[0.299, 0.587, 0.114]) 18 | width_gray,height_gray = image_gray.shape 19 | # Source: http://stackoverflow.com/questions/12201577/how-can-i-convert-an-rgb-image-into-grayscale-in-python 20 | 21 | # 4. Read the gray image directly 22 | # for more information - https://docs.scipy.org/doc/scipy-0.18.1/reference/generated/scipy.misc.imread.html 23 | image_gray_dir = misc.imread('lena.png',mode="L") 24 | 25 | import matplotlib.pyplot as plt 26 | 27 | # 4. Display both images 28 | # plt.imshow(image_gray,cmap = plt.get_cmap('gray')) 29 | # plt.show() 30 | 31 | # Four axes, returned as a 2-d array 32 | f, axarr = plt.subplots(2, 2) 33 | axarr[0, 0].imshow(image) 34 | axarr[0, 0].set_title('Image Color') 35 | 36 | axarr[0, 1].imshow(image_gray,cmap = plt.get_cmap('gray')) 37 | axarr[0, 1].set_title('Image converted to Gray') 38 | 39 | axarr[1, 0].imshow(image_gray_dir,cmap = plt.get_cmap('gray')) 40 | axarr[1, 0].set_title('Image directly read to gray') 41 | 42 | plt.show() 43 | 44 | 45 | # Additional. Experiment on the operation 46 | # temp = np.array([[[1,2,3],[4,5,6],[7,8,9]],[[1,2,3],[4,5,6],[7,8,9]],[[1,2,3],[4,5,6],[7,8,9]] ]) 47 | # print temp.shape 48 | # print temp[0,...,:3] -------------------------------------------------------------------------------- /3_Image_Histogram/lena.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaeDukSeo/Python_Basic_Image_Processing/bb82ba2fcfef27ff9df9f192ead6ad0997557883/3_Image_Histogram/lena.png -------------------------------------------------------------------------------- /3_Image_Histogram/three.py: -------------------------------------------------------------------------------- 1 | # For this tutorial series you only need python scipy and matplotlib to display image 2 | from scipy import misc 3 | import numpy as np 4 | from scipy import ndimage 5 | 6 | # 0. Read the image 7 | image = misc.imread('lena.png',mode="L") 8 | 9 | # 1. Get the histogram of the iamge 10 | hist, bin_edges = np.histogram(image, bins='auto') 11 | bin_centers = 0.5*(bin_edges[:-1] + bin_edges[1:]) 12 | 13 | # 2. Get the min, max, mean, value of the image 14 | im_min = image.min() 15 | im_max = image.max() 16 | im_mean = image.mean() 17 | 18 | print "Min : ",im_min 19 | print "Max : ",im_max 20 | print "Mean : ",im_mean 21 | 22 | 23 | # 3. Plot the histogram 24 | import matplotlib.pyplot as plt 25 | plt.plot(bin_centers, hist, lw=2) 26 | plt.show() 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /4_Add_noise/four.py: -------------------------------------------------------------------------------- 1 | # For this tutorial series you only need python scipy and matplotlib to display image 2 | from scipy import misc 3 | import numpy as np 4 | 5 | # 0. Read the image 6 | image = misc.imread('lena.png',mode="L") 7 | 8 | # 1. Add noises to the image 9 | noisy1 = image + 3 * image.std() * np.random.random(image.shape) 10 | 11 | alot = 2 * image.max() * np.random.random(image.shape) 12 | noisy2 = image + alot 13 | 14 | # 2. Plot the noisy image 15 | import matplotlib.pyplot as plt 16 | f, axarr = plt.subplots(2, 2) 17 | axarr[0, 0].imshow(image,cmap = plt.get_cmap('gray')) 18 | axarr[0, 0].set_title('Image gray') 19 | 20 | axarr[0, 1].imshow(noisy1,cmap = plt.get_cmap('gray')) 21 | axarr[0, 1].set_title('Image noise 1') 22 | 23 | axarr[1, 0].imshow(noisy2,cmap = plt.get_cmap('gray')) 24 | axarr[1, 0].set_title('Image noise 2') 25 | 26 | axarr[1, 1].imshow(alot,cmap = plt.get_cmap('gray')) 27 | axarr[1, 1].set_title('Added Noise') 28 | 29 | 30 | plt.show() -------------------------------------------------------------------------------- /4_Add_noise/lena.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaeDukSeo/Python_Basic_Image_Processing/bb82ba2fcfef27ff9df9f192ead6ad0997557883/4_Add_noise/lena.png -------------------------------------------------------------------------------- /5_Flip_Image/five.py: -------------------------------------------------------------------------------- 1 | # For this tutorial series you only need python scipy and matplotlib to display image 2 | from scipy import misc 3 | import numpy as np 4 | from scipy import ndimage 5 | 6 | # 0. Read the image 7 | image = misc.imread('lena.png') 8 | 9 | # 1. Filp the image to left and right 10 | flip_image_LR = np.fliplr(image) 11 | 12 | # 2. Filp the image upside down 13 | flip_image_UD = np.flipud(image) 14 | 15 | # 3. Filp the image up and down left and right 16 | flip_image_LR_UD = np.flipud(flip_image_LR) 17 | 18 | # 4. Plot the histogram 19 | import matplotlib.pyplot as plt 20 | f, axarr = plt.subplots(2, 2) 21 | axarr[0, 0].imshow(image,cmap = plt.get_cmap('gray')) 22 | axarr[0, 0].set_title('Image Original') 23 | 24 | axarr[0, 1].imshow(flip_image_LR,cmap = plt.get_cmap('gray')) 25 | axarr[0, 1].set_title('Image Flip - Horizontally') 26 | 27 | axarr[1, 0].imshow(flip_image_UD,cmap = plt.get_cmap('gray')) 28 | axarr[1, 0].set_title('Image Flip - Vertically') 29 | 30 | axarr[1, 1].imshow(flip_image_LR_UD,cmap = plt.get_cmap('gray')) 31 | axarr[1, 1].set_title('Image Flip - Vertically and Horizontally') 32 | plt.show() 33 | 34 | # ---- END OF CODE --- -------------------------------------------------------------------------------- /5_Flip_Image/lena.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaeDukSeo/Python_Basic_Image_Processing/bb82ba2fcfef27ff9df9f192ead6ad0997557883/5_Flip_Image/lena.png -------------------------------------------------------------------------------- /6_Add_Constant_to_image/lena.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaeDukSeo/Python_Basic_Image_Processing/bb82ba2fcfef27ff9df9f192ead6ad0997557883/6_Add_Constant_to_image/lena.png -------------------------------------------------------------------------------- /6_Add_Constant_to_image/sixx.py: -------------------------------------------------------------------------------- 1 | # For this tutorial series you only need python scipy and matplotlib to display image 2 | from scipy import misc 3 | import numpy as np 4 | from scipy import ndimage 5 | 6 | # 0. Read the image 7 | image = misc.imread('lena.png',mode="L") 8 | 9 | # 1. Make black and white image 10 | width,height = image.shape 11 | white_image = np.zeros([width,height,3],dtype=np.uint8) 12 | white_image.fill(255) 13 | black_image = np.zeros([width,height,3],dtype=np.uint8) 14 | black_image.fill(0) 15 | 16 | # 2. Slowly add constant to images 17 | added_image_0 = image + 0 18 | added_image_100 = image + 10 19 | added_image_200 = image + 25 20 | 21 | # 4. Plot the histogram 22 | import matplotlib.pyplot as plt 23 | 24 | f, axarr = plt.subplots(2, 3) 25 | axarr[0, 0].imshow(image,cmap='gray') 26 | axarr[0, 0].set_title('Original') 27 | 28 | axarr[0, 1].imshow(white_image) 29 | axarr[0, 1].set_title('Every value 255') 30 | 31 | axarr[0, 2].imshow(black_image,cmap='gray') 32 | axarr[0, 2].set_title('Every value 0') 33 | 34 | axarr[1, 0].imshow(added_image_0,cmap='gray') 35 | axarr[1, 0].set_title('Added 0') 36 | 37 | axarr[1, 1].imshow(added_image_100,cmap='gray') 38 | axarr[1, 1].set_title('Added 10') 39 | 40 | axarr[1, 2].imshow(added_image_200,cmap='gray') 41 | axarr[1, 2].set_title('Added 25') 42 | plt.show() 43 | 44 | # ---- END OF CODE --- -------------------------------------------------------------------------------- /7_Convert_RGB_to_HSV_color_map/lena.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaeDukSeo/Python_Basic_Image_Processing/bb82ba2fcfef27ff9df9f192ead6ad0997557883/7_Convert_RGB_to_HSV_color_map/lena.png -------------------------------------------------------------------------------- /7_Convert_RGB_to_HSV_color_map/seven.py: -------------------------------------------------------------------------------- 1 | # For this tutorial series you only need python scipy and matplotlib to display image 2 | from scipy import misc 3 | import numpy as np 4 | from scipy import ndimage 5 | 6 | # 0. Read the image - 7 | image_RGB = misc.imread('lena.png',mode="RGB") 8 | 9 | # 1. Convert to HSV color scheme 10 | import matplotlib 11 | iamge_HSV = matplotlib.colors.rgb_to_hsv(image_RGB) 12 | 13 | # 2. Plot the image - both image 14 | import matplotlib.pyplot as plt 15 | from matplotlib.colors import rgb_to_hsv 16 | iamge_HSV = rgb_to_hsv(image_RGB) 17 | f, axarr = plt.subplots(2) 18 | axarr[0].imshow(image_RGB) 19 | axarr[0].set_title('Image RGB') 20 | 21 | axarr[ 1].imshow(iamge_HSV) 22 | axarr[ 1].set_title('Image HSV') 23 | 24 | plt.show() 25 | 26 | # ---- END OF THE CODE ------- -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Python_Basic_Image_Processing 2 | This folder contains the code for basic image processing methods done in python. 3 | 4 | Here are the lesson chapters 5 | 6 | 1. Read and Show image 7 | 2. Convert image to gray Scale 8 | 3. Make image Histogram 9 | 4. Add noise to image 10 | 5. Flip Image 11 | 6. Add constant to Image 12 | 7. Convert RGB to HSV color map 13 | 8. Rotation of Image 14 | 9. Crop an Image 15 | 10. Blur an Image 16 | 11. Sharpen an Image 17 | 12. Sobel Filter operation 18 | 13. Canny Edge Filter operation 19 | 14. Roberts Filter operation 20 | 15. Add Super Pixels to an Image -------------------------------------------------------------------------------- /lena.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaeDukSeo/Python_Basic_Image_Processing/bb82ba2fcfef27ff9df9f192ead6ad0997557883/lena.png -------------------------------------------------------------------------------- /youtube.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaeDukSeo/Python_Basic_Image_Processing/bb82ba2fcfef27ff9df9f192ead6ad0997557883/youtube.png --------------------------------------------------------------------------------