图像处理(三)直方图匹配

直方图匹配是一种非线性点运算,用于使图像具有类似色调和反差。通过均衡化和逆运算,将原始图像的直方图转换为规定形式。本文介绍了直方图匹配的原理,并提供了C#实现,展示了处理效果。
摘要由CSDN通过智能技术生成

       直方图匹配,又称直方图规定化,即变换原图的直方图为规定的某种形式的直方图,从而使两幅图像具有类似的色调和反差。直方图匹配属于非线性点运算。

       直方图规定化的原理:对两个直方图都做均衡化,变成相同的归一化的均匀直方图,以此均匀直方图为媒介,再对参考图像做均衡化的逆运算

       以下是算法实现(C#)

    /// <summary>
    /// 直方图匹配
    /// </summary>
    /// <param name="srcBmp">原始图像</param>
    /// <param name="matchingBmp">匹配图像</param>
    /// <param name="dstBmp">处理后图像</param>
    /// <returns>处理成功 true 失败 false</returns>
    public static bool HistogramMatching(Bitmap srcBmp, Bitmap matchingBmp, out Bitmap dstBmp) {
        if (srcBmp == null || matchingBmp == null) {
            dstBmp = null;
            return false;
        }
        dstBmp = new Bitmap(srcBmp);
        Bitmap tempSrcBmp = new Bitmap(srcBmp);
        Bitmap tempMatchingBmp = new Bitmap(matchingBmp);
        double[] srcCpR = null;
        double[] srcCpG = null;
        double[] srcCpB = null;
        double[] matchCpB = null;
        double[] matchCpG = null;
        double[] matchCpR = null;
        //分别计算两幅图像的累计概率分布
        getCumulativeProbabilityRGB(tempSrcBmp, out srcCpR, out srcCpG, out srcCpB);
        getCumulativeProbabilityRGB(tempMatchingBmp, out matchCpR, out matchCpG, out matchCpB);

        double diffAR = 0, diffBR = 0, diffAG = 0, diffBG = 0, diffAB = 0, diffBB = 0;
        byte kR = 0, kG = 0, kB = 0;
        //逆映射函数
        byte[] mapPixelR = new byte[256];
        byte[] mapPixelG = new byte[256];
        byte[] mapPixelB = new byte[256];
        //分别计算RGB三个分量的逆映射函数
        //R
        for (int i &#
  • 8
    点赞
  • 33
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值