├── DIP ├── DIP作业.doc ├── DIP期末作业 │ ├── DIP作业.pdf │ └── code │ │ ├── assets │ │ ├── clip_image002-1568343516615.jpg │ │ ├── clip_image002.jpg │ │ ├── clip_image004-1568343516616.jpg │ │ ├── clip_image004.jpg │ │ ├── clip_image006-1568343516616.jpg │ │ └── clip_image006.jpg │ │ ├── my_imfilter.m │ │ ├── proj1.m │ │ ├── readme.md │ │ └── vis_hybrid_image.m ├── assignment1 │ ├── README.md │ ├── couple.png │ ├── main.py │ └── run.bat ├── assignment2 │ ├── README.md │ ├── assets │ │ ├── 1555581226588.png │ │ ├── 1555589295084.png │ │ ├── 1555589343997.png │ │ ├── 75922-20180328175321961-461589862.png │ │ ├── ContrastStretch.png │ │ ├── GraySlicing.png │ │ ├── HE.png │ │ ├── Negative.png │ │ ├── a.png │ │ ├── a1.png │ │ ├── cat.png │ │ ├── clahe1.png │ │ ├── compression.png │ │ ├── false.png │ │ ├── haze.png │ │ ├── homo.png │ │ ├── lena.png │ │ ├── lena1.png │ │ ├── lena2.png │ │ ├── lena3.png │ │ ├── lena4.png │ │ ├── lena5.png │ │ ├── sharpen.png │ │ └── sub.png │ ├── src │ │ ├── 20.jpg │ │ ├── DIP2.m │ │ ├── GLS.png │ │ ├── HazeRemoval.py │ │ ├── README.md │ │ ├── a.png │ │ ├── cat.jpg │ │ ├── circle.png │ │ ├── couple.png │ │ ├── homo.jpg │ │ ├── lena.png │ │ ├── mammogram.png │ │ ├── retinex.py │ │ ├── run_hazeRemoval.bat │ │ ├── run_retinex.bat │ │ ├── son1.png │ │ ├── son2.png │ │ └── t.png │ ├── 图像增强综述.md │ └── 图像增强综述.pdf ├── assignment3 │ ├── project6 Image Filtering and Hybrid Images.docx │ └── project6 │ │ ├── Hybrid Images Report.pdf │ │ ├── OlivaTorralb_Hybrid_Siggraph06.pdf │ │ ├── code │ │ ├── BicycleAndMotorcycle │ │ │ ├── high_frequencies.jpg │ │ │ ├── hybrid_image.jpg │ │ │ ├── hybrid_image_scales.jpg │ │ │ └── low_frequencies.jpg │ │ ├── BirdAndPlane │ │ │ ├── high_frequencies.jpg │ │ │ ├── hybrid_image.jpg │ │ │ ├── hybrid_image_scales.jpg │ │ │ └── low_frequencies.jpg │ │ ├── CatAndDog │ │ │ ├── high_frequencies.jpg │ │ │ ├── hybrid_image.jpg │ │ │ ├── hybrid_image_scales.jpg │ │ │ └── low_frequencies.jpg │ │ ├── FIshAndSubmarine │ │ │ ├── high_frequencies.jpg │ │ │ ├── hybrid_image.jpg │ │ │ ├── hybrid_image_scales.jpg │ │ │ └── low_frequencies.jpg │ │ ├── MarilynAndEinstein │ │ │ ├── high_frequencies.jpg │ │ │ ├── hybrid_image.jpg │ │ │ ├── hybrid_image_scales.jpg │ │ │ └── low_frequencies.jpg │ │ ├── my_imfilter.m │ │ ├── proj1.m │ │ ├── proj1_test_filtering.m │ │ └── vis_hybrid_image.m │ │ ├── data │ │ ├── bicycle.bmp │ │ ├── bird.bmp │ │ ├── cat.bmp │ │ ├── dog.bmp │ │ ├── einstein.bmp │ │ ├── fish.bmp │ │ ├── marilyn.bmp │ │ ├── motorcycle.bmp │ │ ├── plane.bmp │ │ └── submarine.bmp │ │ └── p2Hybrid.pdf └── some_slides │ ├── 08076993.pdf │ ├── 1003.4053.pdf │ ├── enhancement1.PDF │ ├── imagee.pdf │ ├── 研究生DIPch5 图像增强(1).pdf │ ├── 研究生DIPch5 图像增强(2).pdf │ ├── 研究生DIPch5 图像增强(3).pdf │ ├── 研究生DIPch6 图像复原.pdf │ ├── 研究生DIPch7 图像分析(1)——图像分割.pdf │ ├── 研究生DIPch7 图像分析(2)——数学形态学.pdf │ └── 研究生DIPch7 图像分析(3)——表示与描述.pdf ├── DSP ├── README.md ├── code │ ├── GUI.fig │ ├── GUI.m │ ├── cameraman.tif │ ├── hw1.m │ ├── hw2.m │ ├── hw3.m │ ├── hw4.m │ └── hw5.m ├── fy.pdf └── ppt │ ├── MATLAB与信号处理(1).pdf │ ├── MATLAB与信号处理(4).pdf │ ├── MATLAB与信号处理(5) .pdf │ ├── Matlab与信号处理(2).pdf │ └── Matlab与信号处理(3).pdf ├── ML ├── 2019机器学习方法及应用试题.pdf └── ml.docx ├── README.md ├── 基于内容的视觉信息检索 ├── 基于内容的视觉信息检索试题_2017.doc ├── 基于内容的视觉信息检索试题_2017.pdf └── 研究生课程考试命题_基于内容的视觉信息检索.doc └── 有源网络 ├── 有源网络综合.pdf ├── 研究生课程考试-网络综合(1).doc └── 研究生课程考试-网络综合(1).pdf /DIP/DIP作业.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/DIP作业.doc -------------------------------------------------------------------------------- /DIP/DIP期末作业/DIP作业.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/DIP期末作业/DIP作业.pdf -------------------------------------------------------------------------------- /DIP/DIP期末作业/code/assets/clip_image002-1568343516615.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/DIP期末作业/code/assets/clip_image002-1568343516615.jpg -------------------------------------------------------------------------------- /DIP/DIP期末作业/code/assets/clip_image002.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/DIP期末作业/code/assets/clip_image002.jpg -------------------------------------------------------------------------------- /DIP/DIP期末作业/code/assets/clip_image004-1568343516616.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/DIP期末作业/code/assets/clip_image004-1568343516616.jpg -------------------------------------------------------------------------------- /DIP/DIP期末作业/code/assets/clip_image004.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/DIP期末作业/code/assets/clip_image004.jpg -------------------------------------------------------------------------------- /DIP/DIP期末作业/code/assets/clip_image006-1568343516616.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/DIP期末作业/code/assets/clip_image006-1568343516616.jpg -------------------------------------------------------------------------------- /DIP/DIP期末作业/code/assets/clip_image006.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/DIP期末作业/code/assets/clip_image006.jpg -------------------------------------------------------------------------------- /DIP/DIP期末作业/code/my_imfilter.m: -------------------------------------------------------------------------------- 1 | function output = my_imfilter(image, filter) 2 | 3 | intput_image = image; 4 | 5 | % 获取输入图像的行和列大小,并过滤以允许多尺寸图像 6 | [intput_row, intput_col] = size(intput_image(:,:,1)); 7 | [filter_row, filter_col] = size(filter); 8 | 9 | % 用零填充图像(数量=过滤器的最小需求=行和列的一半) 10 | pad_input_image = padarray(intput_image, [(filter_row - 1)/2, (filter_col - 1)/2]); 11 | 12 | output = []; 13 | 14 | for layer = 1:size(intput_image, 3) % 当输入是灰色图像时,确保正常 15 | % 使输入图像的所有filter_row*filter_col大小块都是列 16 | columns = im2col(pad_input_image(:,:,layer), [filter_row, filter_col]); 17 | 18 | % 转置滤波器,使其卷积(但不相关) 19 | filter2 = transpose(filter(:)); 20 | 21 | % 过滤图像 22 | filterd_columns = filter2 * columns; 23 | 24 | % 从列恢复到图像形式s 25 | output(:,:,layer) = col2im(filterd_columns, [1, 1], [intput_row, intput_col]); 26 | end 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /DIP/DIP期末作业/code/proj1.m: -------------------------------------------------------------------------------- 1 | close all; 2 | 3 | %读取图像 4 | image1 = im2single(imread('../data/einstein.bmp')); 5 | image2 = im2single(imread('../data/marilyn.bmp')); 6 | 7 | %设置截断频率 8 | cutoff_frequency = 12; 9 | 10 | %设立高斯低通滤波器 11 | filter = fspecial('Gaussian', cutoff_frequency*4+1, cutoff_frequency); 12 | 13 | %进行高斯低通滤波,得到低通分量 14 | low_frequencies = my_imfilter(my_imfilter(image1, filter), filter'); 15 | 16 | %减去低频得到高频分量 17 | high_frequencies = image2 - my_imfilter(my_imfilter(image2, filter), filter'); 18 | 19 | %结合低频和高频分量 20 | hybrid_image = low_frequencies + high_frequencies; 21 | 22 | %可视化并保存结果 23 | figure(1); imshow(low_frequencies) 24 | figure(2); imshow(high_frequencies + 0.5); 25 | vis = vis_hybrid_image(hybrid_image); 26 | figure(3); imshow(vis); 27 | imwrite(low_frequencies, 'low_frequencies.jpg', 'quality', 95); 28 | imwrite(high_frequencies + 0.5, 'high_frequencies.jpg', 'quality', 95); 29 | imwrite(hybrid_image, 'hybrid_image.jpg', 'quality', 95); 30 | imwrite(vis, 'hybrid_image_scales.jpg', 'quality', 95); -------------------------------------------------------------------------------- /DIP/DIP期末作业/code/readme.md: -------------------------------------------------------------------------------- 1 | # DIP 2 | 3 | [TOC] 4 | 5 | ## 代码执行结果 6 | 7 | ### Bird-Plane pair 8 | 9 | ![img](assets/clip_image002-1568343516615.jpg) 10 | 11 | ​ 飞机与鸟 12 | 13 | ### Motorcycle-bicycle pair 14 | 15 | ![img](assets/clip_image004-1568343516616.jpg) 16 | 17 | ​ 自行车与摩托车 18 | 19 | ### Fish-Submarine pair 20 | 21 | ![img](assets/clip_image006-1568343516616.jpg) 22 | 23 | ​ 潜艇与鱼 24 | 25 | ## 代码说明 26 | 27 | ### proj1.m (运行模块) 28 | 29 | ```matlab 30 | close all; 31 | 32 | %读取图像 33 | image1 = im2single(imread('../data/einstein.bmp')); 34 | image2 = im2single(imread('../data/marilyn.bmp')); 35 | 36 | %设置截断频率 37 | cutoff_frequency = 12; 38 | 39 | %设立高斯低通滤波器 40 | filter = fspecial('Gaussian', cutoff_frequency*4+1, cutoff_frequency); 41 | 42 | %进行高斯低通滤波,得到低通分量 (调用了my_imfilter.m的函数) 43 | low_frequencies = my_imfilter(my_imfilter(image1, filter), filter'); 44 | 45 | %减去低频得到高频分量 46 | high_frequencies = image2 - my_imfilter(my_imfilter(image2, filter), filter'); 47 | 48 | %结合低频和高频分量 49 | hybrid_image = low_frequencies + high_frequencies; 50 | 51 | %可视化并保存结果 52 | figure(1); imshow(low_frequencies) 53 | figure(2); imshow(high_frequencies + 0.5); 54 | vis = vis_hybrid_image(hybrid_image); %调用vis_hybrid_image.m中的函数 55 | figure(3); imshow(vis); 56 | imwrite(low_frequencies, 'low_frequencies.jpg', 'quality', 95); 57 | imwrite(high_frequencies + 0.5, 'high_frequencies.jpg', 'quality', 95); 58 | imwrite(hybrid_image, 'hybrid_image.jpg', 'quality', 95); 59 | imwrite(vis, 'hybrid_image_scales.jpg', 'quality', 95); 60 | ``` 61 | 62 | ### my_imfilter.m(自定义滤波器模块) 63 | 64 | ```matlab 65 | function output = my_imfilter(image, filter) 66 | 67 | intput_image = image; 68 | 69 | % 获取输入图像的行和列大小,并过滤以允许多尺寸图像 70 | [intput_row, intput_col] = size(intput_image(:,:,1)); 71 | [filter_row, filter_col] = size(filter); 72 | 73 | % 用零填充图像(数量=过滤器的最小需求=行和列的一半) 74 | pad_input_image = padarray(intput_image, [(filter_row - 1)/2, (filter_col - 1)/2]); 75 | 76 | output = []; 77 | 78 | for layer = 1:size(intput_image, 3) % 当输入是灰色图像时,确保正常 79 | % 使输入图像的所有filter_row*filter_col大小块都是列 80 | columns = im2col(pad_input_image(:,:,layer), [filter_row, filter_col]); 81 | 82 | % 转置滤波器,使其卷积(但不相关) 83 | filter2 = transpose(filter(:)); 84 | 85 | % 过滤图像 86 | filterd_columns = filter2 * columns; 87 | 88 | % 从列恢复到图像形式s 89 | output(:,:,layer) = col2im(filterd_columns, [1, 1], [intput_row, intput_col]); 90 | end 91 | ``` 92 | 93 | ### vis_hybrid_image.m(可视化模块) 94 | 95 | ```matla 96 | function output = vis_hybrid_image(hybrid_image) 97 | %通过逐步向下采样图像并将所有图像连接在一起,可视化混合图像。 98 | 99 | scales = 5; %5个下采样版本 100 | scale_factor = 0.5; %每次下采样缩小2倍 101 | padding = 5; %像素填充5 102 | 103 | original_height = size(hybrid_image,1); 104 | num_colors = size(hybrid_image,3); %计算图像通道数 105 | output = hybrid_image; 106 | cur_image = hybrid_image; 107 | 108 | for i = 2:scales 109 | %填充部分 110 | output = cat(2, output, ones(original_height, padding, num_colors)); 111 | 112 | %下采样图像 113 | cur_image = imresize(cur_image, scale_factor, 'bilinear'); 114 | %合并图像 115 | tmp = cat(1,ones(original_height - size(cur_image,1), size(cur_image,2), num_colors), cur_image); 116 | output = cat(2, output, tmp); 117 | end 118 | ``` 119 | 120 | ## 运行环境与运行方式 121 | 122 | 环境: matlab2014a 123 | 124 | 运行方式:直接运行**proj1.m**,需要自行设定图像路径 -------------------------------------------------------------------------------- /DIP/DIP期末作业/code/vis_hybrid_image.m: -------------------------------------------------------------------------------- 1 | function output = vis_hybrid_image(hybrid_image) 2 | %通过逐步向下采样图像并将所有图像连接在一起,可视化混合图像。 3 | 4 | scales = 5; %5个下采样版本 5 | scale_factor = 0.5; %每次下采样缩小2倍 6 | padding = 5; %像素填充5 7 | 8 | original_height = size(hybrid_image,1); 9 | num_colors = size(hybrid_image,3); %计算图像通道数 10 | output = hybrid_image; 11 | cur_image = hybrid_image; 12 | 13 | for i = 2:scales 14 | %填充部分 15 | output = cat(2, output, ones(original_height, padding, num_colors)); 16 | 17 | %下采样图像 18 | cur_image = imresize(cur_image, scale_factor, 'bilinear'); 19 | %合并图像 20 | tmp = cat(1,ones(original_height - size(cur_image,1), size(cur_image,2), num_colors), cur_image); 21 | output = cat(2, output, tmp); 22 | end 23 | 24 | 25 | -------------------------------------------------------------------------------- /DIP/assignment1/README.md: -------------------------------------------------------------------------------- 1 | # 要求 2 | 编程实现对一副图像进行以下三种方法处理,比较实验结果。 3 | - 直方图均衡 4 | - 自适应直方图均衡 5 | - CLAHE -------------------------------------------------------------------------------- /DIP/assignment1/couple.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment1/couple.png -------------------------------------------------------------------------------- /DIP/assignment1/main.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import argparse 3 | import cv2 4 | 5 | ap = argparse.ArgumentParser() 6 | ap.add_argument('--image', required=True) 7 | args = vars(ap.parse_args()) 8 | 9 | image = cv2.imread(args["image"]) 10 | image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) 11 | 12 | eh_image = cv2.equalizeHist(image) 13 | 14 | ahe = cv2.createCLAHE(clipLimit=0.0, tileGridSize=(8,8)) 15 | ahe_image = ahe.apply(image) 16 | 17 | clahe = cv2.createCLAHE(clipLimit=10.0, tileGridSize=(8,8)) 18 | clahe_image = clahe.apply(image) 19 | 20 | cv2.imshow("Histogram Equalization", np.hstack([image, eh_image, 21 | ahe_image, clahe_image])) 22 | cv2.waitKey(0) -------------------------------------------------------------------------------- /DIP/assignment1/run.bat: -------------------------------------------------------------------------------- 1 | python main.py --image couple.png -------------------------------------------------------------------------------- /DIP/assignment2/README.md: -------------------------------------------------------------------------------- 1 | # Image Enhancement Review 2 | 3 | - Point Operations 4 | - Image Negative 5 | - Contrast Stretching 6 | - Compression of dynamic range 7 | - Grey level slicing 8 | - Image Subtraction 9 | - Image Averaging 10 | - Histogram 11 | - Histogram Equalization 12 | - adaptive histogram equalization 13 | - Contrast Limited Adaptive Hitogram Equalization(CLAHE) 14 | - Mask Operations 15 | - Smoothing operations 16 | - Median Filtering 17 | - sharpening operations 18 | - Derivative operations 19 | - Transform operations 20 | - Low pass filtering 21 | - High pass filtering 22 | - Band pass filtering 23 | - Homomorphic filtering 24 | - Coloring Operations 25 | - False coloring 26 | - Full color processing 27 | - Retinex 28 | - SSR 29 | - MSR 30 | - MSRCR 31 | - Experiment 32 | - Dark Channel Prior 33 | - Reference -------------------------------------------------------------------------------- /DIP/assignment2/assets/1555581226588.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment2/assets/1555581226588.png -------------------------------------------------------------------------------- /DIP/assignment2/assets/1555589295084.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment2/assets/1555589295084.png -------------------------------------------------------------------------------- /DIP/assignment2/assets/1555589343997.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment2/assets/1555589343997.png -------------------------------------------------------------------------------- /DIP/assignment2/assets/75922-20180328175321961-461589862.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment2/assets/75922-20180328175321961-461589862.png -------------------------------------------------------------------------------- /DIP/assignment2/assets/ContrastStretch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment2/assets/ContrastStretch.png -------------------------------------------------------------------------------- /DIP/assignment2/assets/GraySlicing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment2/assets/GraySlicing.png -------------------------------------------------------------------------------- /DIP/assignment2/assets/HE.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment2/assets/HE.png -------------------------------------------------------------------------------- /DIP/assignment2/assets/Negative.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment2/assets/Negative.png -------------------------------------------------------------------------------- /DIP/assignment2/assets/a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment2/assets/a.png -------------------------------------------------------------------------------- /DIP/assignment2/assets/a1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment2/assets/a1.png -------------------------------------------------------------------------------- /DIP/assignment2/assets/cat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment2/assets/cat.png -------------------------------------------------------------------------------- /DIP/assignment2/assets/clahe1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment2/assets/clahe1.png -------------------------------------------------------------------------------- /DIP/assignment2/assets/compression.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment2/assets/compression.png -------------------------------------------------------------------------------- /DIP/assignment2/assets/false.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment2/assets/false.png -------------------------------------------------------------------------------- /DIP/assignment2/assets/haze.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment2/assets/haze.png -------------------------------------------------------------------------------- /DIP/assignment2/assets/homo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment2/assets/homo.png -------------------------------------------------------------------------------- /DIP/assignment2/assets/lena.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment2/assets/lena.png -------------------------------------------------------------------------------- /DIP/assignment2/assets/lena1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment2/assets/lena1.png -------------------------------------------------------------------------------- /DIP/assignment2/assets/lena2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment2/assets/lena2.png -------------------------------------------------------------------------------- /DIP/assignment2/assets/lena3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment2/assets/lena3.png -------------------------------------------------------------------------------- /DIP/assignment2/assets/lena4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment2/assets/lena4.png -------------------------------------------------------------------------------- /DIP/assignment2/assets/lena5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment2/assets/lena5.png -------------------------------------------------------------------------------- /DIP/assignment2/assets/sharpen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment2/assets/sharpen.png -------------------------------------------------------------------------------- /DIP/assignment2/assets/sub.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment2/assets/sub.png -------------------------------------------------------------------------------- /DIP/assignment2/src/20.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment2/src/20.jpg -------------------------------------------------------------------------------- /DIP/assignment2/src/DIP2.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment2/src/DIP2.m -------------------------------------------------------------------------------- /DIP/assignment2/src/GLS.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment2/src/GLS.png -------------------------------------------------------------------------------- /DIP/assignment2/src/HazeRemoval.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import argparse 3 | import numpy as np 4 | 5 | 6 | def hazeRemoval(img, w=0.7, t0=0.1): 7 | #求每个像素的暗通道 8 | darkChannel = img.min(axis=2) 9 | #取暗通道的最大值最为全球大气光 10 | A = darkChannel.max() 11 | darkChannel = darkChannel.astype(np.double) 12 | #利用公式求得透射率 13 | t = 1 - w * (darkChannel / A) 14 | #设定透射率的最小值 15 | t[t < t0] = t0 16 | 17 | J = img 18 | #对每个通道分别进行去雾 19 | J[:, :, 0] = (img[:, :, 0] - (1 - t) * A) / t 20 | J[:, :, 1] = (img[:, :, 1] - (1 - t) * A) / t 21 | J[:, :, 2] = (img[:, :, 2] - (1 - t) * A) / t 22 | return J 23 | 24 | def main(): 25 | ap = argparse.ArgumentParser() 26 | ap.add_argument('--image', required=True) 27 | args = vars(ap.parse_args()) 28 | 29 | hazeImage = cv2.imread(args["image"]) 30 | 31 | result = hazeRemoval(hazeImage.copy()) 32 | 33 | cv2.imshow("HazeRemoval", np.hstack([hazeImage, result])) 34 | cv2.waitKey(0) 35 | 36 | 37 | if __name__ == '__main__': 38 | main() 39 | -------------------------------------------------------------------------------- /DIP/assignment2/src/README.md: -------------------------------------------------------------------------------- 1 | # package 2 | python: numpy and cv2. -------------------------------------------------------------------------------- /DIP/assignment2/src/a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment2/src/a.png -------------------------------------------------------------------------------- /DIP/assignment2/src/cat.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment2/src/cat.jpg -------------------------------------------------------------------------------- /DIP/assignment2/src/circle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment2/src/circle.png -------------------------------------------------------------------------------- /DIP/assignment2/src/couple.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment2/src/couple.png -------------------------------------------------------------------------------- /DIP/assignment2/src/homo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment2/src/homo.jpg -------------------------------------------------------------------------------- /DIP/assignment2/src/lena.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment2/src/lena.png -------------------------------------------------------------------------------- /DIP/assignment2/src/mammogram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment2/src/mammogram.png -------------------------------------------------------------------------------- /DIP/assignment2/src/retinex.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | import numpy as np 3 | import cv2 4 | 5 | 6 | def singleScaleRetinexProcess(img, sigma): 7 | temp = cv2.GaussianBlur(img, (0, 0), sigma) 8 | gaussian = np.where(temp == 0, 0.01, temp) 9 | retinex = np.log10(img + 0.01) - np.log10(gaussian) 10 | return retinex 11 | 12 | def multiScaleRetinexProcess(img, sigma_list): 13 | retinex = np.zeros_like(img * 1.0) 14 | for sigma in sigma_list: 15 | retinex = singleScaleRetinexProcess(img, sigma) 16 | retinex = retinex / len(sigma_list) 17 | return retinex 18 | 19 | def colorRestoration(img, alpha, beta): 20 | img_sum = np.sum(img, axis=2, keepdims=True) 21 | color_restoration = beta * (np.log10(alpha * img) - np.log10(img_sum)) 22 | return color_restoration 23 | 24 | def multiScaleRetinexWithColorRestorationProcess(img, sigma_list, G, b, alpha, beta): 25 | img = np.float64(img) + 1.0 26 | img_retinex = multiScaleRetinexProcess(img, sigma_list) 27 | img_color = colorRestoration(img, alpha, beta) 28 | img_msrcr = G * (img_retinex * img_color + b) 29 | return img_msrcr 30 | 31 | def simplestColorBalance(img, low_clip, high_clip): 32 | total = img.shape[0] * img.shape[1] 33 | for i in range(img.shape[2]): 34 | unique, counts = np.unique(img[:, :, i], return_counts=True) 35 | current = 0 36 | for u, c in zip(unique, counts): 37 | if float(current) / total < low_clip: 38 | low_val = u 39 | if float(current) / total < high_clip: 40 | high_val = u 41 | current += c 42 | img[:, :, i] = np.maximum(np.minimum(img[:, :, i], high_val), low_val) 43 | return img 44 | 45 | def touint8(img): 46 | for i in range(img.shape[2]): 47 | img[:, :, i] = (img[:, :, i] - np.min(img[:, :, i])) / \ 48 | (np.max(img[:, :, i]) - np.min(img[:, :, i])) * 255 49 | img = np.uint8(np.minimum(np.maximum(img, 0), 255)) 50 | return img 51 | 52 | def SSR(img, sigma=300): 53 | ssr = singleScaleRetinexProcess(img, sigma) 54 | ssr = touint8(ssr) 55 | return ssr 56 | 57 | def MSR(img, sigma_list=[15, 80, 250]): 58 | msr = multiScaleRetinexProcess(img, sigma_list) 59 | msr = touint8(msr) 60 | return msr 61 | 62 | def MSRCR(img, sigma_list=[15, 80, 250], G=5, b=25, alpha=125, beta=46, low_clip=0.01, high_clip=0.99): 63 | msrcr = multiScaleRetinexWithColorRestorationProcess(img, sigma_list, G, b, alpha, beta) 64 | msrcr = touint8(msrcr) 65 | msrcr = simplestColorBalance(msrcr, low_clip, high_clip) 66 | return msrcr 67 | 68 | def main(): 69 | ap = argparse.ArgumentParser() 70 | ap.add_argument('--image', required=True) 71 | args = vars(ap.parse_args()) 72 | 73 | image = cv2.imread(args["image"]) 74 | 75 | ssr = SSR(image) 76 | msr = MSR(image) 77 | msrcr = MSRCR(image) 78 | 79 | cv2.imshow("Retinex", np.hstack([image, ssr, msr, msrcr])) 80 | cv2.waitKey(0) 81 | 82 | 83 | if __name__ == "__main__": 84 | main() 85 | 86 | -------------------------------------------------------------------------------- /DIP/assignment2/src/run_hazeRemoval.bat: -------------------------------------------------------------------------------- 1 | python HazeRemoval.py --image 20.jpg -------------------------------------------------------------------------------- /DIP/assignment2/src/run_retinex.bat: -------------------------------------------------------------------------------- 1 | python retinex.py --image couple.png -------------------------------------------------------------------------------- /DIP/assignment2/src/son1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment2/src/son1.png -------------------------------------------------------------------------------- /DIP/assignment2/src/son2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment2/src/son2.png -------------------------------------------------------------------------------- /DIP/assignment2/src/t.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment2/src/t.png -------------------------------------------------------------------------------- /DIP/assignment2/图像增强综述.md: -------------------------------------------------------------------------------- 1 | # 图像增强综述 2 | 3 | 作者: 方阳 4 | 5 | 这篇文章是DIP的第二次作业,对图像增强技术进行综述,目录如下:happy:: 6 | 7 | [TOC] 8 | 9 | ## 1. Point Operations 10 | 11 | ### 1.1 Image Negative 12 | 13 | 图像反转(Image Negative)在许多应用中都很有用,例如显示医学图像和用单色正片拍摄屏幕,其想法是将产生的负片用作投影片。 14 | 15 | 转换方程:$T: G(x, y) = L - F(x,y)​$,其中$L​$是最大强度值,灰度图像$L​$为255。 16 | 17 | 实验结果: 18 | 19 | ![Negative](assets/Negative.png) 20 | 21 | source code: 22 | 23 | ```matlab 24 | %% 图像反转 25 | L = 255; 26 | img_orig = imread('mammogram.png'); 27 | figure(); 28 | subplot(1, 2, 1); 29 | imshow(img_orig); 30 | title('Origin'); 31 | img_negative = L - img_orig; 32 | subplot(1, 2, 2); 33 | imshow(img_negative); 34 | title('Negative'); 35 | ``` 36 | 37 | ### 1.2 Contrast Stretching 38 | 39 | 低对比度的图像可能是由于光照不足,图像传感器缺乏动态范围,甚至在图像采集过程中透镜孔径设置错误。对比度拉伸(Contrast Stretching)背后的想法是增加图像处理中灰度的动态范围。 40 | 41 | 转换公式:$G(x, y) = g_1 + (g_2 - g_1)/ (f_2 - f_1)[F(x, y) - 1]$,其中这里$[f1, f2]$为灰度在新范围$[g1, g2]$上的映射,这里f1为图像的最小强度值,f2为图像的最大强度值。该函数增强了图像的对比度,显示了均匀的强度分布。 42 | 43 | 实验结果: 44 | 45 | ![ContrastStretch](assets/ContrastStretch.png) 46 | 47 | source code: 48 | 49 | ```matlab 50 | %% 对比度拉伸 51 | imgContrastStretch=imadjust(imgOrig, [0.1 0.4], [0.3 0.5 ]) 52 | figure(); 53 | subplot(1, 2, 1); 54 | imshow(imgOrig); 55 | title('Origin'); 56 | subplot(1, 2, 2); 57 | imshow(imgContrastStretch); 58 | title('ContrastStretch'); 59 | ``` 60 | 61 | ### 1.3 Compression of dynamic range 62 | 63 | 有时,处理后的图像的动态范围远远超过显示设备的能力,在这种情况下,只有图像最亮的部分在显示屏上可见. 则需要对图像进行动态范围压缩(Compression of dynamic range)。 64 | 65 | 转换公式:$s = c log(1 + |r|)​$, $c​$是度量常数,是对数函数执行所需的压缩。$r​$表示当前像素的灰度,$s​$为转换后该像素的灰度。例如将以下图像的$[0. 255]​$压缩到$[0, 150]​$,其中$c = \frac{150}{log(1 + 255)}​$. 66 | 67 | 实验结果: 68 | 69 | ![compression](assets/compression.png) 70 | 71 | source code: 72 | 73 | ```matlab 74 | %% 动态范围压缩 75 | img_orig1 = rgb2gray(imread('circle.png')); 76 | c = 150 / log(1 + 255); 77 | img_size = size(img_orig1); 78 | for i = 1:img_size(1) 79 | for j = 1:img_size(2) 80 | s(i, j) = c * log(double(1 + img_orig1(i, j))); 81 | end 82 | end 83 | figure(); 84 | subplot(1, 2, 1); 85 | imshow(img_orig1); 86 | title('Origin'); 87 | subplot(1, 2, 2); 88 | imshow(uint8(s)); 89 | title('Compression'); 90 | ``` 91 | 92 | ### 1.4 Grey level slicing 93 | 94 | 灰度切片(Grey level slicing)相当于带通滤波的空间域。灰度切片函数既可以强调一组灰度值而减少其他所有灰度值,也可以强调一组灰度值而不考虑其他灰度值。例如对图像中灰度值为[100, 180]的区域进行强调,对其他区域进行抑制。 95 | 96 | 实验结果: 97 | 98 | ![GraySlicing](assets/GraySlicing.png) 99 | 100 | source code: 101 | 102 | ```matlab 103 | %% 灰度切片 104 | img_orig2 = rgb2gray(imread('GLS.png')); 105 | figure(); 106 | subplot(1, 2, 1); 107 | imshow(img_orig2); 108 | title('Origin'); 109 | img_size = size(img_orig2); 110 | for i = 1:img_size(1) 111 | for j = 1:img_size(2) 112 | if img_orig2(i, j) > 100 || img_orig2(i, j) > 180 113 | img_orig2(i, j) = 150; 114 | else 115 | img_orig2(i, j) = 25; 116 | end 117 | end 118 | end 119 | subplot(1, 2, 2); 120 | imshow(img_orig2); 121 | title('Gray level slicing'); 122 | ``` 123 | 124 | ### 1.5 Image Subtraction 125 | 126 | 图像相减是从另一个图像中减去一个像素或整个图像的数字数值的过程。这主要是出于两个原因——调平图像的不均匀部分和检测两幅图像之间的变化。一个常用的方法是从场景中减去背景光照的变化,以便更容易地分析其中的前景对象.例如在捕获过程中光照很差的文本,以便在整个图像中有很强的光照梯度,如果我们希望将前景文本从背景页面中分离出来,也许我们不能调整光照,但是我们可以在场景中放入不同的东西。例如,显微镜成像通常就是这样。所以我们用一张白纸替换文本,在不改变任何东西的情况下,我们捕捉到一个新的图像。我们可以从原始图像中减去光场图像,试图消除背景强度的变化。 127 | 实验结果如下: 128 | 129 | ![sub](assets/sub.png) 130 | 131 | source code: 132 | 133 | ```matlab 134 | %% 图像相减 135 | img_orig3 = rgb2gray(imread('son1.png')); 136 | img_add = uint16(img_orig3) + 100; 137 | whitepaper = rgb2gray(imread('son2.png')); 138 | img_sub = uint8(img_add - uint16(whitepaper)); 139 | figure(); 140 | subplot(1, 3, 1); 141 | imshow(img_orig3); 142 | title('Origin'); 143 | subplot(1, 3, 2); 144 | imshow(whitepaper); 145 | title('whitepaper'); 146 | subplot(1, 3, 3); 147 | imshow(img_sub); 148 | title('Subtraction'); 149 | ``` 150 | 151 | ### 1.6 Image Averaging 152 | 153 | 图像平均是通过找到K个图像的平均值来获得的。应用于图像去噪。 154 | 转换公式:$\overline{g}(x, y)=\frac{1}{K} \sum_{i=1}^{K} g_{i}(x, y)​$,噪声图像定义为$g(x, y)=f(x, y)+\eta(x, y)​$, 假设噪声与零均值不相关。(下图只显示了一张噪声图片) 155 | 实验结果: 156 | 157 | ![cat](assets/cat.png) 158 | 159 | source code: 160 | 161 | ```matlab 162 | %% 图像平均 163 | img_orig4 = rgb2gray(imread('cat.jpg')); 164 | img_noise1 = imnoise(img_orig4, 'gaussian', 0, 0.01); 165 | img_noise2 = imnoise(img_orig4, 'gaussian', 0, 0.01); 166 | img_noise3 = imnoise(img_orig4, 'gaussian', 0, 0.01); 167 | img_noise4 = imnoise(img_orig4, 'gaussian', 0, 0.01); 168 | img_noise5 = imnoise(img_orig4, 'gaussian', 0, 0.01); 169 | img_average = imlincomb(0.2,img_noise1, 0.2,img_noise2, 0.2,img_noise3, 0.2,img_noise4, 0.2,img_noise5); 170 | figure(); 171 | subplot(1, 3, 1); 172 | imshow(img_orig4); 173 | title('Origin'); 174 | subplot(1, 3, 2); 175 | imshow(img_noise1); 176 | title('img_noise1'); 177 | subplot(1, 3, 3); 178 | imshow(img_average); 179 | title('img_average'); 180 | ``` 181 | 182 | ### 1.7 Histogram 183 | 184 | #### 1.7.1 Histogram Equalization 185 | 186 | 直方图均衡化是一种常用的图像增强技术。假设我们有一个主要是黑色的图像。然后它的直方图会向灰度的下端倾斜,所有的图像细节都被压缩到直方图的暗端。如果能将暗端的灰度“拉伸”,生成一个更均匀分布的直方图,那么图像就会清晰得多。 187 | 188 | 具体做法:1. 求出原图的直方图分布 2.计算原图直方图的累计概率分布 3. 映射,公式可以表示为$f\left(D_{A}\right)=\frac{L}{A_{0}} \sum_{u=0}^{D_{A}} H_{A}(u)$,$A$为原图,$H$为直方图,$L$为灰度级,$A_0$为像素点个数。 189 | 190 | ### 1.7.2 adaptive histogram equalization 191 | 192 | 直方图均衡化中,是直接对全局图像进行均衡化,是Global Histogram Equalization,而没有考虑到局部图像区域(Local Region),自适应直方图均衡化(AHE)就是在均衡化的过程中只利用局部区域窗口内的直方图分布来构建映射函数首先,最简单并且直接的想法,对A图像每个像素点进行遍历,用像素点周围W * W的窗口进行计算直方图变换的CDF(累计概率分布),然后对该像素点进行映射。[9] 193 | 194 | ### 1.7.3 Contrast Limited Adaptive Hitogram Equalization(CLAHE) 195 | 196 | CLAHE相对于AHE,提出了两个改进的地方。 197 | 198 | - 第一,提出一种限制直方图分布的方法。考虑图像A的直方图,设定一个阈值,假定直方图某个灰度级超过了阈值,就对 之进行裁剪,然后将超出阈值的部分平均分配到各个灰度级,这个过程可以用下图[10]来进行解释。图中左上图是原来的直方图分布,可以看出有两处峰值,其对应的CDF为左下图,可以看出有两段梯度比较大,变化剧烈。对于之前频率超过了阈值的灰度级,那么就把这些超过阈值的部分裁剪掉平均分配到各个灰度级上,如右上图,那么这会使得CDF变得较为平缓,如右下图。通常阈值的设定可以直接设定灰度级出现频数,也可以设定为占总像素比例,后者更容易使用。由于右下图所示的CDF不会有太大的剧烈变化,所以可以避免过度增强噪声点。[9] 199 | 200 | ![clahe1](assets/clahe1.png) 201 | 202 | - 第二,提出了一种插值的方法,加速直方图均衡化。首先,将图像分块,每块计算一个直方图CDF,其次,对于图像的每一个像素点,找到其邻近的四个窗口,分别计算四个窗口直方图CDF对该点像素点的映射值,记作$f_{u l}(D), f_{u r}(D), f_{d l}(D), f_{d r}(D)$, 然后进行双线性插值得到最终该像素点的映射值,双线性插值(BiLinear)公式为$f(D)=(1-\Delta y)\left((1-\Delta x) f_{u l}(D)+\Delta x f_{b l}(D)\right)+\Delta y\left((1-\Delta x) f_{u r}(D)+\Delta x f_{b r}(D)\right)$ 203 | 204 | 其中$\Delta x, \Delta y$是像素点相对于左上角窗口中心,即左上角黑色像素点的距离与窗口大小的比值。[9] 205 | 206 | 实验结果(从左往右依次是原图,HE,AHE,CLAHE): 207 | 208 | ![HE](assets/HE.png) 209 | 210 | source code(hw_1): 211 | 212 | ```python 213 | ![a](assets/a.png)//HE,AHE,CLAHE 214 | import numpy as np 215 | import argparse 216 | import cv2 217 | 218 | ap = argparse.ArgumentParser() 219 | ap.add_argument('--image', required=True) 220 | args = vars(ap.parse_args()) 221 | 222 | image = cv2.imread(args["image"]) 223 | image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) 224 | 225 | eh_image = cv2.equalizeHist(image) 226 | 227 | ahe = cv2.createCLAHE(clipLimit=0.0, tileGridSize=(8,8)) 228 | ahe_image = ahe.apply(image) 229 | 230 | clahe = cv2.createCLAHE(clipLimit=10.0, tileGridSize=(8,8)) 231 | clahe_image = clahe.apply(image) 232 | 233 | cv2.imshow("Histogram Equalization", np.hstack([image, eh_image, 234 | ahe_image, clahe_image])) 235 | cv2.waitKey(0) 236 | ``` 237 | 238 | ## 2. Mask Operations 239 | 240 | 掩模算子通过在图像上滑动掩模,将掩模值与落在它们下面的像素值相乘并获得总和,来执行掩模与图像的卷积。 241 | 242 | 可以表示为$g(x, y)=\sum_{s=-a}^{a} \sum_{t=-b}^{b} w(s, t) f(x+s, y+t)$,总和用作图像上掩模中心位置的值,$w(s, t)$即为掩模算子。 243 | 244 | ### 2.1 Smoothing operations 245 | 246 | 图像平滑是指用于突出图像的宽大区域、低频成分、主干部分或抑制图像噪声和干扰高频成分的图像处理方法,目的是使图像亮度平缓渐变,减小突变梯度,改善图像质量。$\begin{array}{|c|c|c|}\hline 1 & {1} & {1} \\ \hline 1 & {1} & {1} \\ \hline 1 & {1} & {1} \\ \hline\end{array}​$x$\frac{1}{9}​$就是一个用来平滑图像的掩模算子。 247 | 248 | 实验结果: 249 | 250 | ![a](assets/a.png) 251 | 252 | source code: 253 | 254 | ```matlab 255 | img_orig5 = imread('a.png'); 256 | H1 = fspecial('average', 3); 257 | img_smooth1 = imfilter(img_orig5, H1); 258 | H2 = fspecial('average', 7); 259 | img_smooth2 = imfilter(img_orig5, H2); 260 | H3 = fspecial('average', 11); 261 | img_smooth3 = imfilter(img_orig5, H3 ); 262 | figure(); 263 | subplot(2, 2, 1); 264 | imshow(img_orig5); 265 | title('Origin'); 266 | subplot(2, 2, 2); 267 | imshow(img_smooth1); 268 | title('kernel=3'); 269 | subplot(2, 2, 3); 270 | imshow(img_smooth2); 271 | title('kernel=7'); 272 | subplot(2, 2, 4); 273 | imshow(img_smooth3); 274 | title('kernel=11'); 275 | ``` 276 | 277 | ### 2.2 Median Filtering 278 | 279 | 中值滤波是基于排序统计理论的一种能有效抑制噪声的非线性信号处理技术,中值滤波的基本原理是把数字图像或数字序列中一点的值用该点的一个邻域中各点值的中值代替,让周围的像素值接近的真实值,从而消除孤立的噪声点。 280 | 281 | 实验结果: 282 | 283 | ![lena](assets/lena.png) 284 | 285 | source code: 286 | 287 | ```matlab 288 | %% 中值滤波 289 | img_orig6 = rgb2gray(imread('lena.png')); 290 | img_noise6=imnoise(img_orig6, 'salt & pepper', 0.02); 291 | img_recover = medfilt2(img_noise6); 292 | figure(); 293 | subplot(1, 3, 1); 294 | imshow(img_orig6); 295 | title('Origin'); 296 | subplot(1, 3, 2); 297 | imshow(img_noise6); 298 | title('img_salt & pepper'); 299 | subplot(1, 3, 3); 300 | imshow(img_recover); 301 | title('img_recover'); 302 | ``` 303 | 304 | ### 2.3 sharpening operations 305 | 306 | 图像锐化*(image sharpening)*是补偿图像的轮廓,增强图像的边缘及灰度跳变的部分,使图像变得清晰,分为空间域处理和频域处理两类。图像锐化是为了突出图像上地物的边缘、轮廓,或某些线性目标要素的特征。这种滤波方法提高了地物边缘与周围像元之间的反差,因此也被称为边缘增强。实验用的sobel算子对图像进行锐化。 307 | 308 | 实验结果: 309 | 310 | ![sharpen](assets/sharpen.png) 311 | 312 | source code: 313 | 314 | ```matlab 315 | %% 锐化 316 | img_orig7 = imread('t.png'); 317 | H5 = fspecial('sobel'); 318 | edge = imfilter(img_orig7, H5); 319 | sharpened = img_orig7 + edge; 320 | figure(); 321 | subplot(1, 3, 1); 322 | imshow(img_orig7); 323 | title('Origin'); 324 | subplot(1, 3, 2); 325 | imshow(edge); 326 | title('Edge'); 327 | subplot(1, 3, 3); 328 | imshow(sharpened); 329 | title('img_sharpened'); 330 | ``` 331 | 332 | ### 2.4 Derivative operations 333 | 334 | 常见的偏导算子有sobel算子和laplacian算子,sobel算子是一阶偏导算子,laplacian算子是二阶偏导算子。 335 | 336 | sobel算子有两个方向$Gx = \left[ \begin{array}{ccc}{-1} & {0} & {+1} \\ {-2} & {0} & {+2} \\ {-1} & {0} & {+1}\end{array}\right]$,$Gy = \left[ \begin{array}{ccc}{-1} & {-2} & {-1} \\ {0} & {0} & {0} \\ {+1} & {+2} & {+1}\end{array}\right]$,laplacian常见的算子有四邻域$\left[ \begin{array}{ccc}{ 0 } & { 1 } & { 0 } \\ { 1 } & { -4 } & { 1 } \\ { 0 } & { 1 } & { 0 }\end{array}\right]$, 八领域$\left[ \begin{array}{ccc}{ 1 } & { 1 } & { 1 } \\ { 1 } & { -8 } & { 1 } \\ { 1 } & { 1 } & { 1 }\end{array}\right]$. 337 | 338 | 实验结果: 339 | 340 | ![lena1](assets/lena1.png) 341 | 342 | ```matlab 343 | %% 偏导 344 | img_orig7 = rgb2gray(imread('lena.png')); 345 | H6 = fspecial('laplacian'); 346 | H7 = fspecial('sobel'); 347 | laplacian = imfilter(img_orig7, H6); 348 | sobel = imfilter(img_orig7, H7); 349 | figure(); 350 | subplot(1, 3, 1); 351 | imshow(img_orig7); 352 | title('Origin'); 353 | subplot(1, 3, 2); 354 | imshow(laplacian); 355 | title('laplacian'); 356 | subplot(1, 3, 3); 357 | imshow(sobel); 358 | title('sobel'); 359 | ``` 360 | 361 | ## 3. Transform operations 362 | 363 | 这一节是将图片从空间域转到频域,在频域进行操作,公式表示为$G(u, v)=F(u, v) H(u, v)$,$F(u, v)$是原图经过快速傅里叶变换转换(Fast Fourier Transform, 简称fft)到频域的频谱,$H(u, v)$是在频域执行的操作,$G(u,v)$是在频域处理后的频谱结果,最后$G(u, v)$可以通过快速傅里叶反变换(ifft)得到滤波的图像。 364 | 365 | ### 3.1 Low pass filtering 366 | 367 | 流程:1) 原始正常的图像,加噪处理,得到img_noise; 2) img_noise图像进行傅里叶变换,得到频谱; 3) 对得到的频谱进行理想低通滤波,低于截止频率$d_0​$的通过,高于的抑制; 4) 对滤波后的频谱进行反傅里叶变换,得到滤波后图像。[2] 368 | 369 | 实验结果: 370 | 371 | ![lena2](assets/lena2.png) 372 | 373 | source code: 374 | 375 | ```matlab 376 | %% 低通滤波, ref[2] 377 | img_origin=rgb2gray(imread('lena.png')); 378 | d0=50; %阈值 379 | img_noise=imnoise(img_origin,'salt'); % 加椒盐噪声 380 | img_f=fftshift(fft2(double(img_noise))); %傅里叶变换得到频谱 381 | [m n]=size(img_f); 382 | m_mid=fix(m/2); 383 | n_mid=fix(n/2); 384 | img_lpf=zeros(m,n); 385 | 386 | for i=1:m 387 | for j=1:n 388 | d=sqrt((i-m_mid)^2+(j-n_mid)^2); %理想低通滤波,求距离 389 | if d<=d0 390 | h(i,j)=1; 391 | else 392 | h(i,j)=0; 393 | end 394 | img_lpf(i,j)=h(i,j)*img_f(i,j); 395 | end 396 | end 397 | 398 | img_lpf=ifftshift(img_lpf); %反傅里叶变换 399 | img_lpf=uint8(real(ifft2(img_lpf))); %取实数部分 400 | 401 | subplot(1,3,1);imshow(img_origin);title('原图'); 402 | subplot(1,3,2);imshow(img_noise);title('噪声图'); 403 | subplot(1,3,3);imshow(img_lpf);title('理想低通滤波'); 404 | ``` 405 | 406 | ### 3.2 High pass filtering 407 | 408 | 高通滤波与低通滤波类似,区别在于低于截止频率的抑制,高于截止频率的通过。 409 | 410 | 实验结果: 411 | 412 | ![a1](assets/lena4.png) 413 | 414 | source code: 415 | 416 | ```matlab 417 | %% 高通滤波 418 | img_origin8 = rgb2gray(imread('lena.png')); 419 | g= fftshift(fft2(double(img_origin8))); 420 | [N1,N2]=size(g); 421 | n=2; 422 | d0=30; 423 | %d0是终止频率 424 | n1=fix(N1/2); 425 | n2=fix(N2/2); 426 | %n1,n2指中心点的坐标,fix()函数是往0取整 427 | for i=1:N1 428 | for j=1:N2 429 | d=sqrt((i-n1)^2+(j-n2)^2); 430 | if d>=d0 431 | h=1; 432 | else 433 | h=0; 434 | end 435 | result(i,j)=h*g(i,j); 436 | end 437 | end 438 | final=ifft2(ifftshift(result)); 439 | final=uint8(real(final)); 440 | figure(); 441 | subplot(2,2,1); imshow(img_origin8); title('原图'); 442 | subplot(2,2,2); imshow(abs(g),[]); title('原图频谱'); 443 | subplot(2,2,3); imshow(final); title('高通滤波后的图像'); 444 | subplot(2,2,4); imshow(abs(result), []); title('高通滤波后的频谱'); 445 | ``` 446 | 447 | ### 3.3 Band pass filtering 448 | 449 | 带通滤波有两个截止频率$d_0$, $d_1$,其中$d_0$是较低的频率,$d_1$是较高的频率,图像频谱在$[d_0, d_1]​$之间的通过,在区间之外的抑制。 450 | 451 | 实验结果: 452 | 453 | ![lena3](assets/lena3.png) 454 | 455 | source code: 456 | 457 | ```matlab 458 | %% 带通滤波 459 | img_origin9=rgb2gray(imread('lena.png')); 460 | g= fftshift(fft2(double(img_origin9))); 461 | [N1,N2]=size(g); 462 | n=2; 463 | d0=0; 464 | d1=200; 465 | n1=floor(N1/2); 466 | n2=floor(N2/2); 467 | for i=1:N1 468 | for j=1:N2 469 | d=sqrt((i-n1)^2+(j-n2)^2); 470 | if d>=d0 || d<=d1 471 | h=1; 472 | else 473 | h=0; 474 | end 475 | result(i,j)=h*g(i,j); 476 | end 477 | end 478 | final=ifft2(ifftshift(result)); 479 | final=uint8(real(final)); 480 | figure(); 481 | subplot(2,2,1); imshow(img_origin9); title('原图'); 482 | subplot(2,2,2); imshow(abs(g),[]); title('原图频谱'); 483 | subplot(2,2,3); imshow(final); title('带通滤波后的图像'); 484 | subplot(2,2,4); imshow(abs(result), []); title('带通滤波后的频谱'); 485 | ``` 486 | 487 | ### 3.4 Homomorphic filtering 488 | 489 | 同态滤波是把频率过滤和灰度变换结合起来的一种图像处理方法,它依靠图像的照度/ 反射率模型作为频域处理的基础,利用压缩亮度范围和增强对比度来改善图像的质量。使用这种方法可以使图像处理符合人眼对于亮度响应的非线性特性,避免了直接对图像进行傅立叶变换处理的失真。[8] 490 | 491 | 同态滤波的基本原理是:将像元灰度值看作是照度和反射率两个组份的产物。由于照度相对变化很小,可以看作是图像的低频成份,而反射率则是高频成份。通过分别处理照度和反射率对灰度值的影响,达到揭示阴影区细节特征的目的。[8] 492 | 493 | 流程:$S(x, y) ---> Log ---> FFT--->filter--->IFFT--->Exp--->T(x, y)​$[8] 494 | 495 | 实验结果: 496 | 497 | ![homo](assets/homo.png) 498 | 499 | ```matlab 500 | %% 同态滤波 ref[8] 501 | img_origin10 = rgb2gray(imread('water.png')); 502 | [M,N]=size(img_origin10); 503 | rL=0.5; 504 | rH=4.7; 505 | c=2; 506 | d0=10; 507 | log_img=log(double(img_origin10)+1); 508 | FI=fft2(log_img); 509 | n1=floor(M/2); 510 | n2=floor(N/2); 511 | for i=1:M 512 | for j=1:N 513 | D(i,j)=((i-n1).^2+(j-n2).^2); 514 | H(i,j)=(rH-rL).*(exp(c*(-D(i,j)./(d0^2))))+rL;%高斯同态滤波 515 | end 516 | end 517 | G = H.*FI; 518 | final=ifft2(G); 519 | final=real(exp(final)); 520 | figure(); 521 | subplot(2,2,1); imshow(img_origin10); title('原图'); 522 | subplot(2,2,2); imshow(abs(FI),[]); title('原图频谱'); 523 | subplot(2,2,3); imshow(final, []); title('同态滤波后的图像'); 524 | subplot(2,2,4); imshow(abs(G), []); title('同态滤波后的频谱'); 525 | ``` 526 | 527 | ## 4. Coloring Operations 528 | 529 | ### 4.1 False coloring 530 | 531 | 将彩色图像转换为灰度图像是一个不可逆的过程,灰度图像也不可能变换为原来的彩色图像。而某些场合需要将灰度图像转变为彩色图像;伪彩色处理主要是把黑白的灰度图像或者多波段图像转换为彩色图像的技术过程。其目的是提高图像内容的可辨识度。 532 | 533 | 伪彩色图像的含义是,每个像素的颜色不是由每个基色分量的数值直接决定,而是把像素值当作彩色查找表(事先做好的)的表项入口地址,去查找一个显示图像时使用的R,G,B强度值,用查找出的R,G,B强度值产生的彩色称为伪彩色。 534 | 535 | 实验结果: 536 | 537 | ![false](assets/false.png) 538 | 539 | source code: 540 | 541 | ```matlab 542 | %% 伪彩色 543 | img_origin11 = rgb2gray(imread('lena.png')); 544 | FalseRGB = label2rgb(gray2ind(img_origin11, 255),jet(255)); 545 | figure(); 546 | subplot(1,2,1); imshow(img_origin11); title('原图'); 547 | subplot(1,2,2); imshow(FalseRGB); title('伪彩色'); 548 | ``` 549 | 550 | ### 4.2 Full color processing 551 | 552 | 上面处理的都是灰度图像,如果要处理全彩色图像,则需要对彩色的每个通道分别处理,然后叠加在一起。下面以中值滤波为例,对彩色图像进行处理。 553 | 554 | 实验结果: 555 | 556 | ![lena5](assets/lena5.png) 557 | 558 | source code: 559 | 560 | ```matlab 561 | %% 全彩色处理,中值滤波为例 562 | img_orig6 = imread('lena.png'); 563 | for i = 1:3 564 | img_noise6(:, :, i) = imnoise(img_orig6(:, :, i), 'salt & pepper', 0.02); 565 | img_recover(:, :, i) = medfilt2(img_noise6(:, :, i)); 566 | end 567 | figure(); 568 | subplot(1, 3, 1); 569 | imshow(img_orig6); 570 | title('Origin'); 571 | subplot(1, 3, 2); 572 | imshow(img_noise6); 573 | title('img_salt & pepper'); 574 | subplot(1, 3, 3); 575 | imshow(img_recover); 576 | title('img_recover'); 577 | ``` 578 | 579 | ## 5. Retinex 580 | 581 | 视网膜-大脑皮层(Retinex)理论认为世界是无色的,人眼看到的世界是光与物质相互作用的结果,也就是说,映射到人眼中的图像和光的长波(R)、中波(G)、短波(B)以及物体的反射性质有关。基于这个理论,可以抽象下图中的公式$I(x, y)=R(x, y) \bullet L(x, y)$,$I(x, y)$代表观察到的图像,$R(x, y)$代表物体的反射属性,$L(x, y)$代表物体表面的光照。 582 | 583 | ![img](assets/75922-20180328175321961-461589862.png) 584 | 585 | ### 5.1 Single-Scale Retinex 586 | 587 | 在Retinex理论中,一个假定是光照$I(x, y)$是缓慢变化的,也就是低频的,要从$I(x, y)$中还原出$R(x, y)$,所以可以通过低通滤波器得到光照分量。 588 | 589 | 具体做法: 590 | 591 | - 对源公式两边同时取对数,得到$\log (R)=\log (I)-\log (L)​$ 592 | - 通过高斯模糊低通滤波器对原图进行滤波,公式为$L = F * I$ 593 | - 得到$L$后,利用第一步的公式得到$log(R)$,然后通过$exp$函数得到R 594 | 595 | ### 5.2 Multi-Scale Retinex 596 | 597 | 上面是单个尺度下的Retinex算法,当然也存在多尺度的Retinex算法,最为经典的就是3尺度的,大、中、小,既能实现图像动态范围的压缩,又能保持色感的一致性较好。[11] 598 | 599 | 具体做法: 对每个尺度分别进行单尺度的Retinex算法,将每个尺度的结果相加取平均得到最终结果(这里是简单地取权重相同,当然还可以设立权重不等). 600 | 601 | ### 5.3 Multi-Scale Retinex with Color Restoration 602 | 603 | 在前面的增强过程中,图像可能会因为增加了噪声,而使得图像的局部细节色彩失真,不能显现出物体的真正颜色,整体视觉效果变差。带色彩恢复因子C的多尺度算法是在多个固定尺度的基础上考虑色彩不失真恢复的结果,在多尺度Retinex算法过程中,通过引入一个色彩因子C来弥补由于图像局部区域对比度增强而导致的图像颜色失真的缺陷,通常情况下所引入的色彩恢复因子C的表达式为: 604 | $$ 605 | R_{M S R C R_{i}}(x, y)=C_{i}(x, y) R_{M S R_{i}}(x, y) 606 | $$ 607 | 608 | $$ 609 | C_{i}(x, y)=f\left[\frac{I_{i}(x, y)}{\sum_{j=1}^{N} I_{j}(x, y)}\right] 610 | $$ 611 | 612 | 其中,$C_i$表示为第$i$个颜色通道地色彩恢复系数,它的作用是调节3个通道颜色的比例,$f(\cdot)$表示颜色空间的映射函数,通常可以采用下面的形式: 613 | $$ 614 | C_{i}(x, y)=\beta \log \frac{\alpha I_{i}(x, y)}{\sum_{j=1}^{N} I_{j}(x, y)}=\beta\left\{\log \left[\alpha I_{i}\right]-\log \left[\sum_{j=1}^{N} I_{j}(x, y)\right]\right\} 615 | $$ 616 | 其中,$\beta$是增益常数,$\alpha$是受控制的非线性强度,带色彩恢复的多尺度Retinex算法通过色彩恢复因子C这个系数来调整原始图像中3个颜色通道之间的比例关系,从而把相对有点暗的区域的信息凸显出来,以达到消除图像色彩失真缺陷的目的。处理后的图像局域对比度得以提高,而且其亮度与真实的场景很相似,图像在人们的视觉感知下显得更为逼真。因此,MSRCR算法会具有比较好的颜色再现性、亮度恒常性与动态范围压缩等特性。[12] 617 | 618 | ### 5.4 Experiment 619 | 620 | source code: 621 | 622 | ```python 623 | #ref [11] 624 | import argparse 625 | import numpy as np 626 | import cv2 627 | 628 | 629 | def singleScaleRetinexProcess(img, sigma): 630 | temp = cv2.GaussianBlur(img, (0, 0), sigma) 631 | gaussian = np.where(temp == 0, 0.01, temp) 632 | retinex = np.log10(img + 0.01) - np.log10(gaussian) 633 | return retinex 634 | 635 | def multiScaleRetinexProcess(img, sigma_list): 636 | retinex = np.zeros_like(img * 1.0) 637 | for sigma in sigma_list: 638 | retinex = singleScaleRetinexProcess(img, sigma) 639 | retinex = retinex / len(sigma_list) 640 | return retinex 641 | 642 | def colorRestoration(img, alpha, beta): 643 | img_sum = np.sum(img, axis=2, keepdims=True) 644 | color_restoration = beta * (np.log10(alpha * img) - np.log10(img_sum)) 645 | return color_restoration 646 | 647 | def multiScaleRetinexWithColorRestorationProcess(img, sigma_list, G, b, alpha, beta): 648 | img = np.float64(img) + 1.0 649 | img_retinex = multiScaleRetinexProcess(img, sigma_list) 650 | img_color = colorRestoration(img, alpha, beta) 651 | img_msrcr = G * (img_retinex * img_color + b) 652 | return img_msrcr 653 | 654 | def simplestColorBalance(img, low_clip, high_clip): 655 | total = img.shape[0] * img.shape[1] 656 | for i in range(img.shape[2]): 657 | unique, counts = np.unique(img[:, :, i], return_counts=True) 658 | current = 0 659 | for u, c in zip(unique, counts): 660 | if float(current) / total < low_clip: 661 | low_val = u 662 | if float(current) / total < high_clip: 663 | high_val = u 664 | current += c 665 | img[:, :, i] = np.maximum(np.minimum(img[:, :, i], high_val), low_val) 666 | return img 667 | 668 | def touint8(img): 669 | for i in range(img.shape[2]): 670 | img[:, :, i] = (img[:, :, i] - np.min(img[:, :, i])) / \ 671 | (np.max(img[:, :, i]) - np.min(img[:, :, i])) * 255 672 | img = np.uint8(np.minimum(np.maximum(img, 0), 255)) 673 | return img 674 | 675 | def SSR(img, sigma=300): 676 | ssr = singleScaleRetinexProcess(img, sigma) 677 | ssr = touint8(ssr) 678 | return ssr 679 | 680 | def MSR(img, sigma_list=[15, 80, 250]): 681 | msr = multiScaleRetinexProcess(img, sigma_list) 682 | msr = touint8(msr) 683 | return msr 684 | 685 | def MSRCR(img, sigma_list=[15, 80, 250], G=5, b=25, alpha=125, beta=46, low_clip=0.01, high_clip=0.99): 686 | msrcr = multiScaleRetinexWithColorRestorationProcess(img, sigma_list, G, b, alpha, beta) 687 | msrcr = touint8(msrcr) 688 | msrcr = simplestColorBalance(msrcr, low_clip, high_clip) 689 | return msrcr 690 | 691 | def main(): 692 | ap = argparse.ArgumentParser() 693 | ap.add_argument('--image', required=True) 694 | args = vars(ap.parse_args()) 695 | 696 | image = cv2.imread(args["image"]) 697 | 698 | ssr = SSR(image) 699 | msr = MSR(image) 700 | msrcr = MSRCR(image) 701 | 702 | cv2.imshow("Retinex", np.hstack([image, ssr, msr, msrcr])) 703 | cv2.waitKey(0) 704 | 705 | 706 | if __name__ == "__main__": 707 | main() 708 | ``` 709 | 710 | 实验结果: 711 | 712 | ![1555581226588](assets/1555581226588.png) 713 | 714 | ## 6. Dark Channel Prior 715 | 716 | 暗通道先验(Dark Channel Prior)是说在绝大多数非天空的局部区域内,某一些像素至少一个颜色通道具有很低的值,这是何凯明等人基于5000多张自然图像的统计得到的定理。根据这一定理,何凯明等人提出了暗通道先验的去雾算法[13], 717 | 718 | 以自然图像和雾气图像为例[14](左边是原图,右边是暗通道): 719 | 720 | ![1555589295084](assets/1555589295084.png) 721 | 722 | ![1555589343997](assets/1555589343997.png) 723 | 724 | 暗通道先验公式如下所示: 725 | $$ 726 | J^{d a r k}(\mathbf{x})=\min _{c \in\{r, g, b\}}\left(\min _{\mathbf{y} \in \Omega(\mathbf{x})}\left(J^{c}(\mathbf{y})\right)\right) 727 | $$ 728 | 上述公式的意义用代码表达也很简单,首先求出每个像素RGB分量中的最小值,存入一副和原始图像大小相同的灰度图中,然后再对这幅灰度图进行最小值滤波,滤波的半径由窗口大小决定。暗通道先验的理论指出:$J^{\mathrm{dark}} \rightarrow 0​$. 729 | 730 | 去雾公认的模型为: 731 | $$ 732 | \mathbf{I}(\mathbf{x})=\mathbf{J}(\mathbf{x}) \mathrm{t}(\mathbf{x})+\mathbf{A}(1-\mathbf{t}(\mathbf{x})) 733 | $$ 734 | 其中$I$为观测强度,$J$为场景亮度,$A$为全球大气光,$t$为描述非散射到达相机的光部分的介质透射率。去雾的目的是从$I$中恢复无雾的$J$. 735 | 736 | 对上述公式进行变形,得到如下公式: 737 | $$ 738 | \frac{I^{c}(\mathbf{x})}{A^{c}}=t(\mathbf{x}) \frac{J^{c}(\mathbf{x})}{A^{c}}+1-t(\mathbf{x}) 739 | $$ 740 | 上标c表示RGB三个通道的意思,假设t在一个窗口下为常数,对上述公式两边同时取两次最小值,得到: 741 | $$ 742 | \min _{\mathbf{y} \in \Omega(\mathbf{x})}\left(\min _{c} \frac{I^{c}(\mathbf{y})}{A^{c}}\right)=\tilde{t}(\mathbf{x}) \min _{\mathbf{y} \in \Omega(\mathbf{x})}\left(\min _{c} \frac{J^{c}(\mathbf{y})}{A^{c}}\right)+1-\tilde{t}(\mathbf{x}) 743 | $$ 744 | 根据暗原色先验理论有: 745 | $$ 746 | J^{\operatorname{dark}}(\mathbf{x})=\min _{\mathbf{y} \in \Omega(\mathbf{x})}\left(\min _{c} J^{c}(\mathbf{y})\right)=0 747 | $$ 748 | 所以前述公式可以化简为: 749 | $$ 750 | \tilde{t}(\mathbf{x})=1-\min _{\mathbf{y} \in \Omega(\mathbf{x})}\left(\min _{c} \frac{I^{c}(\mathbf{y})}{A^{c}}\right) 751 | $$ 752 | 在现实生活中,即使是晴天白云,空气中也存在着一些颗粒,因此,看远处的物体还是能感觉到雾的影响,另外,雾的存在让人类感到景深的存在,因此,有必要在去雾的时候保留一定程度的雾,这可以通过在上述式子中引入一个在[0,1] 之间的因子,则上式修正为: 753 | $$ 754 | \tilde{t}(\mathbf{x})=1-\omega \min _{\mathbf{y} \in \Omega(\mathbf{x})}\left(\min _{c} \frac{I^{c}(\mathbf{y})}{A^{c}}\right) 755 | $$ 756 | 论文中给出的$\omega$等于0.95,对A,论文中给出了一个计算方法: 从暗通道图中按照亮度的大小取前0.1%的像素,在这些位置中,在原始有雾图像I中寻找对应的具有最高亮度的点的值,作为A值。这样A知道了,利用上述公式t也就知道了,在根据原始去雾公式,J也就可以计算了。公式为$\mathrm{J}=(\mathrm{I}-\mathrm{A}) / \mathrm{t}+\mathrm{A}​$。 757 | 758 | 当t 的值很小时,会导致J的值偏大,从而使得图像整体向白场过度,因此一般可设置一阈值t0,当t值小于t0时,令t=t0,论文中取t0=0.1。 759 | $$ 760 | \mathbf{J}(\mathbf{x})=\frac{\mathbf{I}(\mathbf{x})-\mathbf{A}}{\max \left(t(\mathbf{x}), t_{0}\right)}+\mathbf{A} 761 | $$ 762 | 763 | 下面实现了一个最简单的版本,简化了很多,没有取窗口,没有用导向滤波等等,更多复杂的操作参考原始论文[13]。 764 | 765 | 实验结果: 766 | 767 | ![haze](assets/haze.png) 768 | 769 | source code: 770 | 771 | ```python 772 | import cv2 773 | import argparse 774 | import numpy as np 775 | 776 | 777 | def hazeRemoval(img, w=0.7, t0=0.1): 778 | #求每个像素的暗通道 779 | darkChannel = img.min(axis=2) 780 | #取暗通道的最大值最为全球大气光 781 | A = darkChannel.max() 782 | darkChannel = darkChannel.astype(np.double) 783 | #利用公式求得透射率 784 | t = 1 - w * (darkChannel / A) 785 | #设定透射率的最小值 786 | t[t < t0] = t0 787 | 788 | J = img 789 | #对每个通道分别进行去雾 790 | J[:, :, 0] = (img[:, :, 0] - (1 - t) * A) / t 791 | J[:, :, 1] = (img[:, :, 1] - (1 - t) * A) / t 792 | J[:, :, 2] = (img[:, :, 2] - (1 - t) * A) / t 793 | return J 794 | 795 | def main(): 796 | ap = argparse.ArgumentParser() 797 | ap.add_argument('--image', required=True) 798 | args = vars(ap.parse_args()) 799 | 800 | hazeImage = cv2.imread(args["image"]) 801 | 802 | result = hazeRemoval(hazeImage.copy()) 803 | 804 | cv2.imshow("HazeRemoval", np.hstack([hazeImage, result])) 805 | cv2.waitKey(0) 806 | 807 | 808 | if __name__ == '__main__': 809 | main() 810 | ``` 811 | 812 | ## Reference 813 | 814 | [1] 815 | 816 | [2] 817 | 818 | [3] 819 | 820 | [4] 821 | 822 | [5] 823 | 824 | [6] 825 | 826 | [7] 827 | 828 | [8] 829 | 830 | [9] 831 | 832 | [10] 833 | 834 | [11] 835 | 836 | [12] 837 | 838 | [13] 839 | 840 | [14] -------------------------------------------------------------------------------- /DIP/assignment2/图像增强综述.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment2/图像增强综述.pdf -------------------------------------------------------------------------------- /DIP/assignment3/project6 Image Filtering and Hybrid Images.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment3/project6 Image Filtering and Hybrid Images.docx -------------------------------------------------------------------------------- /DIP/assignment3/project6/Hybrid Images Report.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment3/project6/Hybrid Images Report.pdf -------------------------------------------------------------------------------- /DIP/assignment3/project6/OlivaTorralb_Hybrid_Siggraph06.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment3/project6/OlivaTorralb_Hybrid_Siggraph06.pdf -------------------------------------------------------------------------------- /DIP/assignment3/project6/code/BicycleAndMotorcycle/high_frequencies.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment3/project6/code/BicycleAndMotorcycle/high_frequencies.jpg -------------------------------------------------------------------------------- /DIP/assignment3/project6/code/BicycleAndMotorcycle/hybrid_image.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment3/project6/code/BicycleAndMotorcycle/hybrid_image.jpg -------------------------------------------------------------------------------- /DIP/assignment3/project6/code/BicycleAndMotorcycle/hybrid_image_scales.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment3/project6/code/BicycleAndMotorcycle/hybrid_image_scales.jpg -------------------------------------------------------------------------------- /DIP/assignment3/project6/code/BicycleAndMotorcycle/low_frequencies.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment3/project6/code/BicycleAndMotorcycle/low_frequencies.jpg -------------------------------------------------------------------------------- /DIP/assignment3/project6/code/BirdAndPlane/high_frequencies.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment3/project6/code/BirdAndPlane/high_frequencies.jpg -------------------------------------------------------------------------------- /DIP/assignment3/project6/code/BirdAndPlane/hybrid_image.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment3/project6/code/BirdAndPlane/hybrid_image.jpg -------------------------------------------------------------------------------- /DIP/assignment3/project6/code/BirdAndPlane/hybrid_image_scales.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment3/project6/code/BirdAndPlane/hybrid_image_scales.jpg -------------------------------------------------------------------------------- /DIP/assignment3/project6/code/BirdAndPlane/low_frequencies.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment3/project6/code/BirdAndPlane/low_frequencies.jpg -------------------------------------------------------------------------------- /DIP/assignment3/project6/code/CatAndDog/high_frequencies.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment3/project6/code/CatAndDog/high_frequencies.jpg -------------------------------------------------------------------------------- /DIP/assignment3/project6/code/CatAndDog/hybrid_image.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment3/project6/code/CatAndDog/hybrid_image.jpg -------------------------------------------------------------------------------- /DIP/assignment3/project6/code/CatAndDog/hybrid_image_scales.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment3/project6/code/CatAndDog/hybrid_image_scales.jpg -------------------------------------------------------------------------------- /DIP/assignment3/project6/code/CatAndDog/low_frequencies.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment3/project6/code/CatAndDog/low_frequencies.jpg -------------------------------------------------------------------------------- /DIP/assignment3/project6/code/FIshAndSubmarine/high_frequencies.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment3/project6/code/FIshAndSubmarine/high_frequencies.jpg -------------------------------------------------------------------------------- /DIP/assignment3/project6/code/FIshAndSubmarine/hybrid_image.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment3/project6/code/FIshAndSubmarine/hybrid_image.jpg -------------------------------------------------------------------------------- /DIP/assignment3/project6/code/FIshAndSubmarine/hybrid_image_scales.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment3/project6/code/FIshAndSubmarine/hybrid_image_scales.jpg -------------------------------------------------------------------------------- /DIP/assignment3/project6/code/FIshAndSubmarine/low_frequencies.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment3/project6/code/FIshAndSubmarine/low_frequencies.jpg -------------------------------------------------------------------------------- /DIP/assignment3/project6/code/MarilynAndEinstein/high_frequencies.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment3/project6/code/MarilynAndEinstein/high_frequencies.jpg -------------------------------------------------------------------------------- /DIP/assignment3/project6/code/MarilynAndEinstein/hybrid_image.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment3/project6/code/MarilynAndEinstein/hybrid_image.jpg -------------------------------------------------------------------------------- /DIP/assignment3/project6/code/MarilynAndEinstein/hybrid_image_scales.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment3/project6/code/MarilynAndEinstein/hybrid_image_scales.jpg -------------------------------------------------------------------------------- /DIP/assignment3/project6/code/MarilynAndEinstein/low_frequencies.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment3/project6/code/MarilynAndEinstein/low_frequencies.jpg -------------------------------------------------------------------------------- /DIP/assignment3/project6/code/my_imfilter.m: -------------------------------------------------------------------------------- 1 | function output = my_imfilter(image, filter) 2 | % This function is intended to behave like the built in function imfilter() 3 | % See 'help imfilter' or 'help conv2'. While terms like "filtering" and 4 | % "convolution" might be used interchangeably, and they are indeed nearly 5 | % the same thing, there is a difference: 6 | % from 'help filter2' 7 | % 2-D correlation is related to 2-D convolution by a 180 degree rotation 8 | % of the filter matrix. 9 | 10 | % Your function should work for color images. Simply filter each color 11 | % channel independently. 12 | 13 | % Your function should work for filters of any width and height 14 | % combination, as long as the width and height are odd (e.g. 1, 7, 9). This 15 | % restriction makes it unambigious which pixel in the filter is the center 16 | % pixel. 17 | 18 | % Boundary handling can be tricky. The filter can't be centered on pixels 19 | % at the image boundary without parts of the filter being out of bounds. If 20 | % you look at 'help conv2' and 'help imfilter' you see that they have 21 | % several options to deal with boundaries. You should simply recreate the 22 | % default behavior of imfilter -- pad the input image with zeros, and 23 | % return a filtered image which matches the input resolution. A better 24 | % approach is to mirror the image content over the boundaries for padding. 25 | 26 | % % Uncomment if you want to simply call imfilter so you can see the desired 27 | % % behavior. When you write your actual solution, you can't use imfilter, 28 | % % filter2, conv2, etc. Simply loop over all the pixels and do the actual 29 | % % computation. It might be slow. 30 | % output = imfilter(image, filter); 31 | 32 | 33 | %%%%%%%%%%%%%%%% 34 | % Your code here 35 | %%%%%%%%%%%%%%%% 36 | intput_image = image; 37 | 38 | % Get the row & column size of input image and filter in order to admit 39 | % multi size picture 40 | [intput_row, intput_col] = size(intput_image(:,:,1)); 41 | [filter_row, filter_col] = size(filter); 42 | 43 | % Pad image with zeros (amount = minimum need of filter = half of row and 44 | % column 45 | pad_input_image = padarray(intput_image, [(filter_row - 1)/2, (filter_col - 1)/2]); 46 | 47 | output = []; 48 | 49 | for layer = 1:size(intput_image, 3) % ensure to be OK when input is gray image 50 | % make all filter_row*filter_col size patch of input image be columns 51 | columns = im2col(pad_input_image(:,:,layer), [filter_row, filter_col]); 52 | 53 | % transpose the filter in order to make it convolution (but not correlation) 54 | filter2 = transpose(filter(:)); 55 | 56 | % filter the image 57 | filterd_columns = filter2 * columns; 58 | 59 | % recover from columns to image form 60 | output(:,:,layer) = col2im(filterd_columns, [1, 1], [intput_row, intput_col]); 61 | end 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /DIP/assignment3/project6/code/proj1.m: -------------------------------------------------------------------------------- 1 | % Before trying to construct hybrid images, it is suggested that you 2 | % implement my_imfilter.m and then debug it using proj1_test_filtering.m 3 | 4 | % Debugging tip: You can split your MATLAB code into cells using "%%" 5 | % comments. The cell containing the cursor has a light yellow background, 6 | % and you can press Ctrl+Enter to run just the code in that cell. This is 7 | % useful when projects get more complex and slow to rerun from scratch 8 | 9 | close all; % closes all figures 10 | 11 | %% Setup 12 | % read images and convert to floating point format 13 | image1 = im2single(imread('../data/einstein.bmp')); 14 | image2 = im2single(imread('../data/marilyn.bmp')); 15 | 16 | % Several additional test cases are provided for you, but feel free to make 17 | % your own (you'll need to align the images in a photo editor such as 18 | % Photoshop). The hybrid images will differ depending on which image you 19 | % assign as image1 (which will provide the low frequencies) and which image 20 | % you asign as image2 (which will provide the high frequencies) 21 | 22 | %% Filtering and Hybrid Image construction 23 | cutoff_frequency = 12; %This is the standard deviation, in pixels, of the 24 | % Gaussian blur that will remove the high frequencies from one image and 25 | % remove the low frequencies from another image (by subtracting a blurred 26 | % version from the original version). You will want to tune this for every 27 | % image pair to get the best results. 28 | filter = fspecial('Gaussian', cutoff_frequency*4+1, cutoff_frequency); 29 | 30 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 31 | % YOUR CODE BELOW. Use my_imfilter create 'low_frequencies' and 32 | % 'high_frequencies' and then combine them to create 'hybrid_image' 33 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 34 | 35 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 36 | % Remove the high frequencies from image1 by blurring it. The amount of 37 | % blur that works best will vary with different image pairs 38 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 39 | 40 | low_frequencies = my_imfilter(my_imfilter(image1, filter), filter'); 41 | 42 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 43 | % Remove the low frequencies from image2. The easiest way to do this is to 44 | % subtract a blurred version of image2 from the original version of image2. 45 | % This will give you an image centered at zero with negative values. 46 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 47 | 48 | high_frequencies = image2 - my_imfilter(my_imfilter(image2, filter), filter'); 49 | 50 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 51 | % Combine the high frequencies and low frequencies 52 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 53 | 54 | hybrid_image = low_frequencies + high_frequencies; 55 | 56 | %% Visualize and save outputs 57 | figure(1); imshow(low_frequencies) 58 | figure(2); imshow(high_frequencies + 0.5); 59 | vis = vis_hybrid_image(hybrid_image); 60 | figure(3); imshow(vis); 61 | imwrite(low_frequencies, 'low_frequencies.jpg', 'quality', 95); 62 | imwrite(high_frequencies + 0.5, 'high_frequencies.jpg', 'quality', 95); 63 | imwrite(hybrid_image, 'hybrid_image.jpg', 'quality', 95); 64 | imwrite(vis, 'hybrid_image_scales.jpg', 'quality', 95); -------------------------------------------------------------------------------- /DIP/assignment3/project6/code/proj1_test_filtering.m: -------------------------------------------------------------------------------- 1 | % this script has test cases to help you test my_imfilter() which you will 2 | % write. You should verify that you get reasonable output here before using 3 | % your filtering to construct a hybrid image in proj1.m. The outputs are 4 | % all saved and you can include them in your writeup. You can add calls to 5 | % imfilter() if you want to check that my_imfilter() is doing something 6 | % similar. 7 | close all 8 | 9 | %% Setup 10 | test_image = im2single(imread('../data/cat.bmp')); 11 | test_image = imresize(test_image, 0.7, 'bilinear'); %resizing to speed up testing 12 | figure(1) 13 | imshow(test_image) 14 | 15 | %% Identify filter 16 | %This filter should do nothing regardless of the padding method you use. 17 | identity_filter = [0 0 0; 0 1 0; 0 0 0]; 18 | 19 | identity_image = my_imfilter(test_image, identity_filter); 20 | 21 | figure(2); imshow(identity_image); 22 | imwrite(identity_image, 'identity_image.jpg', 'quality', 95); 23 | 24 | %% Small blur with a box filter 25 | %This filter should remove some high frequencies 26 | blur_filter = [1 1 1; 1 1 1; 1 1 1]; 27 | blur_filter = blur_filter / sum(sum(blur_filter)); %making the filter sum to 1 28 | 29 | blur_image = my_imfilter(test_image, blur_filter); 30 | 31 | figure(3); imshow(blur_image); 32 | imwrite(blur_image, 'blur_image.jpg', 'quality', 95); 33 | 34 | %% Large blur 35 | %This blur would be slow to do directly, so we instead use the fact that 36 | %Gaussian blurs are separable and blur sequentially in each direction. 37 | large_1d_blur_filter = fspecial('Gaussian', [25 1], 10); 38 | 39 | large_blur_image = my_imfilter(test_image, large_1d_blur_filter); 40 | large_blur_image = my_imfilter(large_blur_image, large_1d_blur_filter'); %notice the ' operator which transposes the filter 41 | 42 | figure(4); imshow(large_blur_image); 43 | imwrite(large_blur_image, 'large_blur_image.jpg', 'quality', 95); 44 | 45 | % %If you want to see how slow this would be to do naively, try out this 46 | % %equivalent operation: 47 | % tic %tic and toc run a timer and then print the elapsted time 48 | % large_blur_filter = fspecial('Gaussian', [25 25], 10); 49 | % large_blur_image = my_imfilter(test_image, large_blur_filter); 50 | % toc 51 | 52 | %% Oriented filter (Sobel Operator) 53 | sobel_filter = [-1 0 1; -2 0 2; -1 0 1]; %should respond to horizontal gradients 54 | 55 | sobel_image = my_imfilter(test_image, sobel_filter); 56 | 57 | %0.5 added because the output image is centered around zero otherwise and mostly black 58 | figure(5); imshow(sobel_image + 0.5); 59 | imwrite(sobel_image + 0.5, 'sobel_image.jpg', 'quality', 95); 60 | 61 | 62 | %% High pass filter (Discrete Laplacian) 63 | laplacian_filter = [0 1 0; 1 -4 1; 0 1 0]; 64 | 65 | laplacian_image = my_imfilter(test_image, laplacian_filter); 66 | 67 | %0.5 added because the output image is centered around zero otherwise and mostly black 68 | figure(6); imshow(laplacian_image + 0.5); 69 | imwrite(laplacian_image + 0.5, 'laplacian_image.jpg', 'quality', 95); 70 | 71 | %% High pass "filter" alternative 72 | high_pass_image = test_image - blur_image; %simply subtract the low frequency content 73 | 74 | figure(7); imshow(high_pass_image + 0.5); 75 | imwrite(high_pass_image + 0.5, 'high_pass_image.jpg', 'quality', 95); 76 | 77 | -------------------------------------------------------------------------------- /DIP/assignment3/project6/code/vis_hybrid_image.m: -------------------------------------------------------------------------------- 1 | function output = vis_hybrid_image(hybrid_image) 2 | %visualize a hybrid image by progressively downsampling the image and 3 | %concatenating all of the images together. 4 | 5 | scales = 5; %how many downsampled versions to create 6 | scale_factor = 0.5; %how much to downsample each time 7 | padding = 5; %how many pixels to pad. 8 | 9 | original_height = size(hybrid_image,1); 10 | num_colors = size(hybrid_image,3); %counting how many color channels the input has 11 | output = hybrid_image; 12 | cur_image = hybrid_image; 13 | 14 | for i = 2:scales 15 | %add padding 16 | output = cat(2, output, ones(original_height, padding, num_colors)); 17 | 18 | %dowsample image; 19 | cur_image = imresize(cur_image, scale_factor, 'bilinear'); 20 | %pad the top and append to the output 21 | tmp = cat(1,ones(original_height - size(cur_image,1), size(cur_image,2), num_colors), cur_image); 22 | output = cat(2, output, tmp); 23 | end 24 | 25 | 26 | -------------------------------------------------------------------------------- /DIP/assignment3/project6/data/bicycle.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment3/project6/data/bicycle.bmp -------------------------------------------------------------------------------- /DIP/assignment3/project6/data/bird.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment3/project6/data/bird.bmp -------------------------------------------------------------------------------- /DIP/assignment3/project6/data/cat.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment3/project6/data/cat.bmp -------------------------------------------------------------------------------- /DIP/assignment3/project6/data/dog.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment3/project6/data/dog.bmp -------------------------------------------------------------------------------- /DIP/assignment3/project6/data/einstein.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment3/project6/data/einstein.bmp -------------------------------------------------------------------------------- /DIP/assignment3/project6/data/fish.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment3/project6/data/fish.bmp -------------------------------------------------------------------------------- /DIP/assignment3/project6/data/marilyn.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment3/project6/data/marilyn.bmp -------------------------------------------------------------------------------- /DIP/assignment3/project6/data/motorcycle.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment3/project6/data/motorcycle.bmp -------------------------------------------------------------------------------- /DIP/assignment3/project6/data/plane.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment3/project6/data/plane.bmp -------------------------------------------------------------------------------- /DIP/assignment3/project6/data/submarine.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment3/project6/data/submarine.bmp -------------------------------------------------------------------------------- /DIP/assignment3/project6/p2Hybrid.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/assignment3/project6/p2Hybrid.pdf -------------------------------------------------------------------------------- /DIP/some_slides/08076993.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/some_slides/08076993.pdf -------------------------------------------------------------------------------- /DIP/some_slides/1003.4053.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/some_slides/1003.4053.pdf -------------------------------------------------------------------------------- /DIP/some_slides/enhancement1.PDF: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/some_slides/enhancement1.PDF -------------------------------------------------------------------------------- /DIP/some_slides/imagee.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/some_slides/imagee.pdf -------------------------------------------------------------------------------- /DIP/some_slides/研究生DIPch5 图像增强(1).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/some_slides/研究生DIPch5 图像增强(1).pdf -------------------------------------------------------------------------------- /DIP/some_slides/研究生DIPch5 图像增强(2).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/some_slides/研究生DIPch5 图像增强(2).pdf -------------------------------------------------------------------------------- /DIP/some_slides/研究生DIPch5 图像增强(3).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/some_slides/研究生DIPch5 图像增强(3).pdf -------------------------------------------------------------------------------- /DIP/some_slides/研究生DIPch6 图像复原.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/some_slides/研究生DIPch6 图像复原.pdf -------------------------------------------------------------------------------- /DIP/some_slides/研究生DIPch7 图像分析(1)——图像分割.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/some_slides/研究生DIPch7 图像分析(1)——图像分割.pdf -------------------------------------------------------------------------------- /DIP/some_slides/研究生DIPch7 图像分析(2)——数学形态学.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/some_slides/研究生DIPch7 图像分析(2)——数学形态学.pdf -------------------------------------------------------------------------------- /DIP/some_slides/研究生DIPch7 图像分析(3)——表示与描述.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DIP/some_slides/研究生DIPch7 图像分析(3)——表示与描述.pdf -------------------------------------------------------------------------------- /DSP/README.md: -------------------------------------------------------------------------------- 1 | # DSP 2 | 运行hw5.m, 需要有安装[deep learning toolbox](https://github.com/rasmusbergpalm/DeepLearnToolbox) -------------------------------------------------------------------------------- /DSP/code/GUI.fig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DSP/code/GUI.fig -------------------------------------------------------------------------------- /DSP/code/GUI.m: -------------------------------------------------------------------------------- 1 | function varargout = GUI(varargin) 2 | % GUI MATLAB code for GUI.fig 3 | % GUI, by itself, creates a new GUI or raises the existing 4 | % singleton*. 5 | % 6 | % H = GUI returns the handle to a new GUI or the handle to 7 | % the existing singleton*. 8 | % 9 | % GUI('CALLBACK',hObject,eventData,handles,...) calls the local 10 | % function named CALLBACK in GUI.M with the given input arguments. 11 | % 12 | % GUI('Property','Value',...) creates a new GUI or raises the 13 | % existing singleton*. Starting from the left, property value pairs are 14 | % applied to the GUI before GUI_OpeningFcn gets called. An 15 | % unrecognized property name or invalid value makes property application 16 | % stop. All inputs are passed to GUI_OpeningFcn via varargin. 17 | % 18 | % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one 19 | % instance to run (singleton)". 20 | % 21 | % See also: GUIDE, GUIDATA, GUIHANDLES 22 | 23 | % Edit the above text to modify the response to help GUI 24 | 25 | % Last Modified by GUIDE v2.5 24-May-2019 19:20:14 26 | 27 | % Begin initialization code - DO NOT EDIT 28 | gui_Singleton = 1; 29 | gui_State = struct('gui_Name', mfilename, ... 30 | 'gui_Singleton', gui_Singleton, ... 31 | 'gui_OpeningFcn', @GUI_OpeningFcn, ... 32 | 'gui_OutputFcn', @GUI_OutputFcn, ... 33 | 'gui_LayoutFcn', [] , ... 34 | 'gui_Callback', []); 35 | if nargin && ischar(varargin{1}) 36 | gui_State.gui_Callback = str2func(varargin{1}); 37 | end 38 | 39 | if nargout 40 | [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); 41 | else 42 | gui_mainfcn(gui_State, varargin{:}); 43 | end 44 | % End initialization code - DO NOT EDIT 45 | 46 | 47 | % --- Executes just before GUI is made visible. 48 | function GUI_OpeningFcn(hObject, eventdata, handles, varargin) 49 | % This function has no output args, see OutputFcn. 50 | % hObject handle to figure 51 | % eventdata reserved - to be defined in a future version of MATLAB 52 | % handles structure with handles and user data (see GUIDATA) 53 | % varargin command line arguments to GUI (see VARARGIN) 54 | 55 | % Choose default command line output for GUI 56 | handles.output = hObject; 57 | [nn_1, nn_2, nn_3, test_x] = hw5(); 58 | handles.nn_1 = nn_1; 59 | handles.nn_2 = nn_2; 60 | handles.nn_3 = nn_3; 61 | handles.test_x = test_x; 62 | % Update handles structure 63 | guidata(hObject, handles); 64 | 65 | % UIWAIT makes GUI wait for user response (see UIRESUME) 66 | % uiwait(handles.figure1); 67 | 68 | 69 | % --- Outputs from this function are returned to the command line. 70 | function varargout = GUI_OutputFcn(hObject, eventdata, handles) 71 | % varargout cell array for returning output args (see VARARGOUT); 72 | % hObject handle to figure 73 | % eventdata reserved - to be defined in a future version of MATLAB 74 | % handles structure with handles and user data (see GUIDATA) 75 | 76 | % Get default command line output from handles structure 77 | varargout{1} = handles.output; 78 | 79 | 80 | % --- Executes on slider movement. 81 | function slider1_Callback(hObject, eventdata, handles) 82 | % hObject handle to slider1 (see GCBO) 83 | % eventdata reserved - to be defined in a future version of MATLAB 84 | % handles structure with handles and user data (see GUIDATA) 85 | 86 | % Hints: get(hObject,'Value') returns position of slider 87 | % get(hObject,'Min') and get(hObject,'Max') to determine range of slider 88 | k = get(hObject, 'value'); 89 | vector = handles.test_x(floor(k), :); 90 | mat = reshape(vector', 28, 28, 1); 91 | axes(handles.axes1); 92 | imshow(mat'); 93 | popup_sel_index = get(handles.popupmenu1, 'Value'); 94 | switch popup_sel_index 95 | case 1 96 | label = nnpredict(handles.nn_1, vector); 97 | case 2 98 | label = nnpredict(handles.nn_2, vector); 99 | case 3 100 | label = nnpredict(handles.nn_3, vector); 101 | otherwise 102 | label = nnpredict(handles.nn_2, vector); 103 | end 104 | set(handles.edit2, 'String', label-1); 105 | 106 | % --- Executes during object creation, after setting all properties. 107 | function slider1_CreateFcn(hObject, eventdata, handles) 108 | % hObject handle to slider1 (see GCBO) 109 | % eventdata reserved - to be defined in a future version of MATLAB 110 | % handles empty - handles not created until after all CreateFcns called 111 | 112 | % Hint: slider controls usually have a light gray background. 113 | if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 114 | set(hObject,'BackgroundColor',[.9 .9 .9]); 115 | end 116 | 117 | 118 | % --- Executes on selection change in popupmenu1. 119 | function popupmenu1_Callback(hObject, eventdata, handles) 120 | % hObject handle to popupmenu1 (see GCBO) 121 | % eventdata reserved - to be defined in a future version of MATLAB 122 | % handles structure with handles and user data (see GUIDATA) 123 | 124 | % Hints: contents = cellstr(get(hObject,'String')) returns popupmenu1 contents as cell array 125 | % contents{get(hObject,'Value')} returns selected item from popupmenu1 126 | popup_sel_index = get(handles.popupmenu1, 'Value'); 127 | 128 | % --- Executes during object creation, after setting all properties. 129 | function popupmenu1_CreateFcn(hObject, eventdata, handles) 130 | % hObject handle to popupmenu1 (see GCBO) 131 | % eventdata reserved - to be defined in a future version of MATLAB 132 | % handles empty - handles not created until after all CreateFcns called 133 | 134 | % Hint: popupmenu controls usually have a white background on Windows. 135 | % See ISPC and COMPUTER. 136 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 137 | set(hObject,'BackgroundColor','white'); 138 | end 139 | 140 | 141 | 142 | function edit2_Callback(hObject, eventdata, handles) 143 | % hObject handle to edit2 (see GCBO) 144 | % eventdata reserved - to be defined in a future version of MATLAB 145 | % handles structure with handles and user data (see GUIDATA) 146 | 147 | % Hints: get(hObject,'String') returns contents of edit2 as text 148 | % str2double(get(hObject,'String')) returns contents of edit2 as a double 149 | 150 | 151 | % --- Executes during object creation, after setting all properties. 152 | function edit2_CreateFcn(hObject, eventdata, handles) 153 | % hObject handle to edit2 (see GCBO) 154 | % eventdata reserved - to be defined in a future version of MATLAB 155 | % handles empty - handles not created until after all CreateFcns called 156 | 157 | % Hint: edit controls usually have a white background on Windows. 158 | % See ISPC and COMPUTER. 159 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 160 | set(hObject,'BackgroundColor','white'); 161 | end 162 | -------------------------------------------------------------------------------- /DSP/code/cameraman.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DSP/code/cameraman.tif -------------------------------------------------------------------------------- /DSP/code/hw1.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DSP/code/hw1.m -------------------------------------------------------------------------------- /DSP/code/hw2.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DSP/code/hw2.m -------------------------------------------------------------------------------- /DSP/code/hw3.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DSP/code/hw3.m -------------------------------------------------------------------------------- /DSP/code/hw4.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DSP/code/hw4.m -------------------------------------------------------------------------------- /DSP/code/hw5.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DSP/code/hw5.m -------------------------------------------------------------------------------- /DSP/fy.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DSP/fy.pdf -------------------------------------------------------------------------------- /DSP/ppt/MATLAB与信号处理(1).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DSP/ppt/MATLAB与信号处理(1).pdf -------------------------------------------------------------------------------- /DSP/ppt/MATLAB与信号处理(4).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DSP/ppt/MATLAB与信号处理(4).pdf -------------------------------------------------------------------------------- /DSP/ppt/MATLAB与信号处理(5) .pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DSP/ppt/MATLAB与信号处理(5) .pdf -------------------------------------------------------------------------------- /DSP/ppt/Matlab与信号处理(2).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DSP/ppt/Matlab与信号处理(2).pdf -------------------------------------------------------------------------------- /DSP/ppt/Matlab与信号处理(3).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/DSP/ppt/Matlab与信号处理(3).pdf -------------------------------------------------------------------------------- /ML/2019机器学习方法及应用试题.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/ML/2019机器学习方法及应用试题.pdf -------------------------------------------------------------------------------- /ML/ml.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/ML/ml.docx -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # homework 2 | 这个仓库用在存放硕士课程的一些课程作业,包括数字图像处理,基于matlab的数字信号处理以及机器学习。 3 | -------------------------------------------------------------------------------- /基于内容的视觉信息检索/基于内容的视觉信息检索试题_2017.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/基于内容的视觉信息检索/基于内容的视觉信息检索试题_2017.doc -------------------------------------------------------------------------------- /基于内容的视觉信息检索/基于内容的视觉信息检索试题_2017.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/基于内容的视觉信息检索/基于内容的视觉信息检索试题_2017.pdf -------------------------------------------------------------------------------- /基于内容的视觉信息检索/研究生课程考试命题_基于内容的视觉信息检索.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/基于内容的视觉信息检索/研究生课程考试命题_基于内容的视觉信息检索.doc -------------------------------------------------------------------------------- /有源网络/有源网络综合.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/有源网络/有源网络综合.pdf -------------------------------------------------------------------------------- /有源网络/研究生课程考试-网络综合(1).doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/有源网络/研究生课程考试-网络综合(1).doc -------------------------------------------------------------------------------- /有源网络/研究生课程考试-网络综合(1).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FangYang970206/homework/96b025b1e12bfeefe30ace672f17d77cfb217d9d/有源网络/研究生课程考试-网络综合(1).pdf --------------------------------------------------------------------------------