码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-03-17 15:53:33      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:彩色图像平滑   高斯滤波   均值滤波   双边滤波   中值滤波   

学习DIP第71天
转载请标明本文出处:http://blog.csdn.net/tonyshengtan ,出于尊重文章作者的劳动,转载请标明出处!文章代码已托管,欢迎共同开发:https://github.com/Tony-Tan/DIPpro

开篇废话

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

算法原理

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

这些算法在彩色图像中应用有两种,一种是对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中值滤波:

技术分享

总结

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

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

标签:彩色图像平滑   高斯滤波   均值滤波   双边滤波   中值滤波   

原文地址:http://blog.csdn.net/tonyshengtan/article/details/44342313

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!