├── README.md ├── edge detector ├── .idea │ ├── edge detector.iml │ ├── misc.xml │ ├── modules.xml │ ├── vcs.xml │ └── workspace.xml ├── __pycache__ │ └── detector.cpython-37.pyc ├── demo.py └── detector.py ├── histogram equalization ├── .idea │ ├── 4.iml │ ├── misc.xml │ ├── modules.xml │ ├── vcs.xml │ └── workspace.xml ├── __pycache__ │ └── enhancement.cpython-37.pyc ├── demo.py └── enhancement.py ├── image interpolation ├── .idea │ ├── image interpolation.iml │ ├── misc.xml │ ├── modules.xml │ ├── vcs.xml │ └── workspace.xml ├── __pycache__ │ └── interpolation.cpython-37.pyc ├── demo.py └── interpolation.py ├── image segmentation based on k-means ├── .idea │ ├── image segmentation based on k-means.iml │ ├── misc.xml │ ├── modules.xml │ ├── other.xml │ ├── vcs.xml │ └── workspace.xml ├── __pycache__ │ └── segamentation.cpython-37.pyc ├── demo.py └── segamentation.py ├── salt pepper noise and median denoising ├── .idea │ ├── code.iml │ ├── misc.xml │ ├── modules.xml │ ├── vcs.xml │ └── workspace.xml ├── __pycache__ │ ├── denoising.cpython-37.pyc │ └── noise.cpython-37.pyc ├── demo.py ├── denoising.py └── noise.py └── wiener filtering and gaussian white noise ├── .idea ├── misc.xml ├── modules.xml ├── vcs.xml ├── wiener filtering and gaussian white noise.iml └── workspace.xml ├── __pycache__ ├── filtering.cpython-37.pyc └── noise.cpython-37.pyc ├── demo.py ├── filtering.py └── noise.py /README.md: -------------------------------------------------------------------------------- 1 | # Digital-Image-Processing 2 | My A specialty course called Digital Image processing , including code and notes 3 | 4 | # Notes 5 | - [click here](https://www.jianshu.com/nb/30347125) 6 | -------------------------------------------------------------------------------- /edge detector/.idea/edge detector.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 12 | -------------------------------------------------------------------------------- /edge detector/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /edge detector/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /edge detector/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /edge detector/.idea/workspace.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 46 | 47 | 48 | 50 | 51 | 52 | 53 | 54 | 55 | 61 | 62 | 63 | 71 | 72 | 73 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 109 | 110 | 111 | 112 | 113 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 1558934760632 145 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | -------------------------------------------------------------------------------- /image interpolation/__pycache__/interpolation.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iwuqing/Digital-Image-Processing/16a837df326a2fb3db0e166976d38a73fbe418c5/image interpolation/__pycache__/interpolation.cpython-37.pyc -------------------------------------------------------------------------------- /image interpolation/demo.py: -------------------------------------------------------------------------------- 1 | import skimage as sk 2 | import interpolation 3 | from matplotlib import pyplot as plt 4 | import numpy as np 5 | 6 | if __name__ == '__main__': 7 | 8 | image = sk.data.coins() 9 | 10 | zoom_multiples = 0.5 11 | image_processed_with_nearest_neighbor = interpolation.nearest_neighbor(image, zoom_multiples) 12 | 13 | image_processed_with_linear = interpolation.double_linear(image, zoom_multiples) 14 | 15 | plt.imsave("image.png", image) 16 | plt.imsave("image_processed_with_nearest_neighbor.png", image_processed_with_nearest_neighbor) 17 | plt.imsave("image_processed_with_linear.png", image_processed_with_linear) 18 | 19 | -------------------------------------------------------------------------------- /image interpolation/interpolation.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import math 3 | 4 | def nearest_neighbor(input_signal, zoom_multiples): 5 | ''' 6 | 最近邻插值(适用于灰度图) 7 | :param input_signal: 输入图像 8 | :param zoom_multiples: 缩放倍数 9 | :return: 缩放后的图像 10 | ''' 11 | input_signal_cp = np.copy(input_signal) # 输入图像的副本 12 | 13 | input_row, input_col = input_signal_cp.shape # 输入图像的尺寸(行、列) 14 | 15 | # 输出图像的尺寸 16 | output_row = int(input_row * zoom_multiples) 17 | output_col = int(input_col * zoom_multiples) 18 | 19 | output_signal = np.zeros((output_row, output_col)) # 输出图片 20 | 21 | for i in range(output_row): 22 | for j in range(output_col): 23 | # 输出图片中坐标 (i,j)对应至输入图片中的(m,n) 24 | m = round(i / output_row * input_row) 25 | n = round(j / output_col * input_col) 26 | # 防止四舍五入后越界 27 | if m >= input_row: 28 | m = input_row - 1 29 | if n >= input_col: 30 | n = input_col - 1 31 | # 插值 32 | output_signal[i, j] = input_signal_cp[m, n] 33 | 34 | return output_signal 35 | 36 | 37 | def double_linear(input_signal, zoom_multiples): 38 | ''' 39 | 双线性插值 40 | :param input_signal: 输入图像 41 | :param zoom_multiples: 放大倍数 42 | :return: 双线性插值后的图像 43 | ''' 44 | input_signal_cp = np.copy(input_signal) # 输入图像的副本 45 | 46 | input_row, input_col = input_signal_cp.shape # 输入图像的尺寸(行、列) 47 | 48 | # 输出图像的尺寸 49 | output_row = int(input_row * zoom_multiples) 50 | output_col = int(input_col * zoom_multiples) 51 | 52 | output_signal = np.zeros((output_row, output_col)) # 输出图片 53 | 54 | for i in range(output_row): 55 | for j in range(output_col): 56 | # 输出图片中坐标 (i,j)对应至输入图片中的最近的四个点点(x1,y1)(x2, y2),(x3, y3),(x4,y4)的均值 57 | temp_x = i / output_row * input_row 58 | temp_y = j / output_col * input_col 59 | 60 | x1 = int(temp_x) 61 | y1 = int(temp_y) 62 | 63 | x2 = x1 64 | y2 = y1 + 1 65 | 66 | x3 = x1 + 1 67 | y3 = y1 68 | 69 | x4 = x1 + 1 70 | y4 = y1 + 1 71 | 72 | u = temp_x - x1 73 | v = temp_y - y1 74 | 75 | # 防止越界 76 | if x4 >= input_row: 77 | x4 = input_row - 1 78 | x2 = x4 79 | x1 = x4 - 1 80 | x3 = x4 - 1 81 | if y4 >= input_col: 82 | y4 = input_col - 1 83 | y3 = y4 84 | y1 = y4 - 1 85 | y2 = y4 - 1 86 | 87 | # 插值 88 | output_signal[i, j] = (1-u)*(1-v)*int(input_signal_cp[x1, y1]) + (1-u)*v*int(input_signal_cp[x2, y2]) + u*(1-v)*int(input_signal_cp[x3, y3]) + u*v*int(input_signal_cp[x4, y4]) 89 | return output_signal -------------------------------------------------------------------------------- /image segmentation based on k-means/.idea/image segmentation based on k-means.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 12 | -------------------------------------------------------------------------------- /image segmentation based on k-means/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | -------------------------------------------------------------------------------- /image segmentation based on k-means/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /image segmentation based on k-means/.idea/other.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /image segmentation based on k-means/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /image segmentation based on k-means/.idea/workspace.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 11 | 12 | 22 | 23 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 81 | 82 | 83 | 84 | 85 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 1558447228813 117 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | -------------------------------------------------------------------------------- /salt pepper noise and median denoising/__pycache__/denoising.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iwuqing/Digital-Image-Processing/16a837df326a2fb3db0e166976d38a73fbe418c5/salt pepper noise and median denoising/__pycache__/denoising.cpython-37.pyc -------------------------------------------------------------------------------- /salt pepper noise and median denoising/__pycache__/noise.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iwuqing/Digital-Image-Processing/16a837df326a2fb3db0e166976d38a73fbe418c5/salt pepper noise and median denoising/__pycache__/noise.cpython-37.pyc -------------------------------------------------------------------------------- /salt pepper noise and median denoising/demo.py: -------------------------------------------------------------------------------- 1 | import skimage as sk 2 | import matplotlib.pyplot as plt 3 | import noise 4 | import denoising 5 | 6 | if __name__ == '__main__': 7 | 8 | noisy_probability = 0.1 # 椒盐噪声概率 9 | 10 | # 加椒盐噪声 11 | camera_processed_with_salt_pepper, actual_noisy_data_num, theory_noisy_data_num = noise.salt_pepper(sk.data.camera(), noisy_probability) 12 | 13 | # 中值滤波处理 14 | camera_median = denoising.median_filtering(camera_processed_with_salt_pepper) 15 | 16 | plt.figure() 17 | plt.subplot(1, 3, 1) 18 | plt.title("Source Image") 19 | plt.imshow(sk.data.camera(), cmap="gray") 20 | plt.subplot(1, 3, 2) 21 | plt.title("Image processed by Salt Pepper Noise: " + str(noisy_probability)) 22 | plt.imshow(camera_processed_with_salt_pepper, cmap="gray") 23 | plt.subplot(1, 3, 3) 24 | plt.title("Image Processed by Median Filtering") 25 | plt.imshow(camera_median, cmap="gray") 26 | plt.show() -------------------------------------------------------------------------------- /salt pepper noise and median denoising/denoising.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import random 3 | 4 | def median_filtering(input_signal): 5 | ''' 6 | 中值滤波(适用于灰度图) 7 | 如: 8 | - + - 9 | + * + 10 | - + - 11 | * 为噪点,滤波方法为:取4个+的中位数(若某+不在输入信号范围内,则随机添加0或255) 12 | :param input_signal: 输入信号矩阵(2D) 13 | :return: 滤波后的信号 14 | ''' 15 | salt_pepper = [0, 255] 16 | 17 | m, n = input_signal.shape # 获取输入图片的尺寸(行和列) 18 | 19 | input_signal_cp = input_signal.copy() # 输入信号的副本 20 | 21 | nosiy_data_around = [] # 存放噪点上下左右的数据点 22 | # 遍历滤波 23 | for i in range(m): 24 | for j in range(n): 25 | # 当灰度值为0或255时,则认为该数据点为椒盐噪点 26 | if input_signal_cp[i, j] == 255 or input_signal_cp[i, j] == 0: 27 | # 每次无效数据点(即不再范围内)为4,每有一个在范围内,即-1 28 | invalid_data_per = 4 29 | if i + 1 < n: 30 | nosiy_data_around.append(input_signal_cp[i + 1, j]) 31 | invalid_data_per = invalid_data_per - 1 32 | if i - 1 >= 0: 33 | nosiy_data_around.append(input_signal_cp[i - 1, j]) 34 | invalid_data_per = invalid_data_per - 1 35 | if j + 1 < m: 36 | nosiy_data_around.append(input_signal_cp[i, j + 1]) 37 | invalid_data_per = invalid_data_per - 1 38 | if j - 1 >= 0: 39 | nosiy_data_around.append(input_signal_cp[i, j - 1]) 40 | invalid_data_per = invalid_data_per - 1 41 | else: 42 | if invalid_data_per > 0: 43 | # 根据无效数据点的个数,随机添加0或255 44 | for k in range(invalid_data_per): 45 | nosiy_data_around.append(salt_pepper[random.randint(0, 1)]) 46 | # 取中位数 47 | input_signal_cp[i, j] = np.median(nosiy_data_around) 48 | 49 | # 该噪点的周围数据数组清空,为下一个噪点周围数据存在做准备 50 | nosiy_data_around = [] 51 | 52 | return input_signal_cp 53 | 54 | -------------------------------------------------------------------------------- /salt pepper noise and median denoising/noise.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import random 3 | 4 | def salt_pepper(intput_signal, probability): 5 | ''' 6 | 椒盐噪声算法(适用于灰度图) 7 | :param intput_signal: 输入信号矩阵(2D) 8 | :param probability: 噪声概率(如:0.1为10%) 9 | :return: 加噪后的图像、实际噪点数、理论噪点数 10 | ''' 11 | nisy = [0, 255] # 噪声(salt, papper) 12 | 13 | m, n= intput_signal.shape # 获取输入图片尺寸(行和列) 14 | 15 | intput_signal_cp = intput_signal.copy() # 输入信号的副本 16 | intput_signal_cp = intput_signal_cp.reshape(-1) # reshape为一个行向量 17 | 18 | # 该噪声概率下,理论上noisy_data_probability_num个数据点中1一个噪点 19 | noisy_data_probability_num = int(100 / (probability * 100)) 20 | 21 | # 噪点数组,当数组中的值为1时,则认为对应的数据点为噪点 22 | noisy_data = [] 23 | for i in range(m*n): 24 | noisy_data.append(random.randint(1, noisy_data_probability_num)) 25 | 26 | # 实际噪点数与理论噪点数 27 | actual_noisy_data_num = 0 28 | theory_noisy_data_num = int(m * n * probability) 29 | 30 | # 添加噪点 31 | for i in range(m*n): 32 | if noisy_data[i] == 1: 33 | actual_noisy_data_num = actual_noisy_data_num + 1 34 | intput_signal_cp[i] = nisy[random.randint(0, 1)] 35 | 36 | # 重塑至m*n的矩阵 37 | intput_signal_cp = intput_signal_cp.reshape(m, n) 38 | 39 | return intput_signal_cp, actual_noisy_data_num, theory_noisy_data_num -------------------------------------------------------------------------------- /wiener filtering and gaussian white noise/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /wiener filtering and gaussian white noise/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /wiener filtering and gaussian white noise/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /wiener filtering and gaussian white noise/.idea/wiener filtering and gaussian white noise.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 12 | -------------------------------------------------------------------------------- /wiener filtering and gaussian white noise/.idea/workspace.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 11 | 12 | 13 | 14 | 15 | 20 | 21 | 22 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 37 | 38 | 39 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 |