【数字图像处理】10.2:彩色图像-图像增强 图像平滑

Abstract: 数字图像处理:第71天
Keywords: 高斯滤波,均值滤波,双边滤波,中值滤波

本文最初发表于csdn,于2018年2月17日迁移至此

彩色图像-图像增强 图像平滑

最近博客数量变多,访问量也一路上升,虽然目的并不是要多少访问量,但看着知识一点点的积累,而且有人认可,心情相当不错的。

算法原理

对灰度图像进行平滑的文章:
1、均值,高斯平滑
2、双边滤波
3、中值滤波

这些算法在彩色图像中应用有两种,一种是对RGB全部分量进行分别处理,然后将个处理过的分量进行合并,得到彩色图像。另一种是对HSI的I分量进行处理,同样能得到平滑效果,对彩色图像的平滑这里只是最简单的介绍,如果想写个美图秀秀,需要在找几篇论文来学下。

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81

void SmoothRGB(RGB *src,RGB *dst,int width,int height,int m_width,int m_height,double param1,double param2,int Smooth_type){
double *chanel_r=(double*)malloc(sizeof(double)*width*height);
double *chanel_g=(double*)malloc(sizeof(double)*width*height);
double *chanel_b=(double*)malloc(sizeof(double)*width*height);
double *chanel_r_dst=(double*)malloc(sizeof(double)*width*height);
double *chanel_g_dst=(double*)malloc(sizeof(double)*width*height);
double *chanel_b_dst=(double*)malloc(sizeof(double)*width*height);
Split(src, chanel_r, chanel_g, chanel_b, width, height);
switch (Smooth_type) {
case SMOOTH_GAUSSIAN:{
GaussianFilter(chanel_r, chanel_r_dst, width, height, m_width, m_height, param1);
GaussianFilter(chanel_g, chanel_g_dst, width, height, m_width, m_height, param1);
GaussianFilter(chanel_b, chanel_b_dst, width, height, m_width, m_height, param1);
break;
}
case SMOOTH_MEDIAN:{
MedianFilter(chanel_r, chanel_r_dst, width, height, m_width, m_height);
MedianFilter(chanel_g, chanel_g_dst, width, height, m_width, m_height);
MedianFilter(chanel_b, chanel_b_dst, width, height, m_width, m_height);
break;
}
case SMOOTH_BILATERAL:{
BilateralFilter(chanel_r, chanel_r_dst, width, height, m_width, m_height, param1, param2);
BilateralFilter(chanel_g, chanel_g_dst, width, height, m_width, m_height, param1, param2);
BilateralFilter(chanel_b, chanel_b_dst, width, height, m_width, m_height, param1, param2);
break;
}
case SMOOTH_MEAN:{
MeanFilter(chanel_r, chanel_r_dst, width, height, m_width, m_height);
MeanFilter(chanel_g, chanel_g_dst, width, height, m_width, m_height);
MeanFilter(chanel_b, chanel_b_dst, width, height, m_width, m_height);
break;

}
default:
break;
}

Merge(chanel_r_dst, chanel_g_dst, chanel_b_dst, dst, width, height);
free(chanel_r);
free(chanel_g);
free(chanel_b);
free(chanel_r_dst);
free(chanel_g_dst);
free(chanel_b_dst);
}


void SmoothHSI(HSI *src,HSI *dst,int width,int height,int m_width,int m_height,double param1,double param2,int Smooth_type){
double *chanel_i=(double*)malloc(sizeof(double)*width*height);
double *chanel_i_dst=(double*)malloc(sizeof(double)*width*height);
Split(src, NULL, NULL, chanel_i, width, height);
switch (Smooth_type) {
case SMOOTH_GAUSSIAN:{
GaussianFilter(chanel_i, chanel_i_dst, width, height, m_width, m_height, param1);
break;
}
case SMOOTH_MEDIAN:{
MedianFilter(chanel_i, chanel_i_dst, width, height, m_width, m_height);
break;
}
case SMOOTH_BILATERAL:{
BilateralFilter(chanel_i, chanel_i_dst, width, height, m_width, m_height, param1, param2);
break;
}
case SMOOTH_MEAN:{
MeanFilter(chanel_i, chanel_i_dst, width, height, m_width, m_height);
break;
}
default:
break;
}
for(int i=0;i<width*height;i++){
dst[i].c1=src[i].c1;
dst[i].c2=src[i].c2;
dst[i].c3=chanel_i_dst[i];
}
free(chanel_i);
free(chanel_i_dst);
}

处理效果

原图:

RGB三通道5x5均值滤波:

RGB三通道5x5高斯滤波:

RGB三通道5x5双边滤波:

RGB三通道5x5中值滤波:

HSI色彩空间 I 通道5x5均值滤波:

HSI色彩空间 I 通道5x5高斯滤波:

HSI色彩空间 I 通道5x5双边滤波:

HSI色彩空间 I 通道5x5中值滤波:

总结

因为是从灰度图像移植过来的算法,所以具体原理不用废话了。
待续。。

0%