学习DIP第71天
转载请标明本文出处:http://blog.csdn.net/tonyshengtan ,出于尊重文章作者的劳动,转载请标明出处!文章代码已托管,欢迎共同开发:https://github.com/Tony-Tan/DIPpro
开篇废话
最近博客数量变多,访问量也一路上升,虽然目的并不是要多少访问量,但看着知识一点点的积累,而且有人认可,心情相当不错的。
算法原理
对灰度图像进行平滑的文章:
这些算法在彩色图像中应用有两种,一种是对RGB全部分量进行分别处理,然后将个处理过的分量进行合并,得到彩色图像。另一种是对HSI的I分量进行处理,同样能得到平滑效果,对彩色图像的平滑这里只是最简单的介绍,如果想写个美图秀秀,需要在找几篇论文来学下。
代码
/*********************************************************************************************************************/
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中值滤波:
总结
因为是从灰度图像移植过来的算法,所以具体原理不用废话了。
待续。。
时间: 2024-10-15 12:47:50