AForge学习笔记(8):AForge.Imaging.ColorReduction

13 篇文章 0 订阅
6 篇文章 2 订阅

BurkesColorDithering:用于实现伴有巴克斯误差扩散的色彩抖动。所谓色彩抖动即是根据调色板中的最匹配色替换原始图像颜色,在此过程中由于匹配色与原始色存在差值,因此产生误差,这些误差会进行扩散,通常通过邻近的七个像素基于协因子进行扩散。色彩抖动程序实现如下:

            Bitmap bt = new Bitmap(@"C:\Users\GAOXIANG\Desktop\0.jpg");
            // 创建彩色图像量化器
            ColorImageQuantizer ciq = new ColorImageQuantizer(new MedianCutQuantizer());
            // 创建像素深度8位的色彩板
            Color[] colorTable = ciq.CalculatePalette(bt, 8);
            // 彩色波动
            AForge.Imaging.ColorReduction.BurkesColorDithering dithering = new AForge.Imaging.ColorReduction.BurkesColorDithering();
            dithering.ColorTable = colorTable;
            // apply the dithering routine
            Bitmap newImage = dithering.Apply(bt);

运行结果:

            


ColorErrorDiffusionToAdjacentNeighbors:该类使用设定的协因素矩阵对邻近像素误差扩散模式进行设定。协因素矩阵:第一行处理右站像素,其他行处理底站像素,除第一行外,其他行数组成员个数必须是奇数个。示例如下:

            Bitmap bt = new Bitmap(@"C:\Users\GAOXIANG\Desktop\2.jpg");
            // 邻域色彩抖动
            AForge.Imaging.ColorReduction.ColorErrorDiffusionToAdjacentNeighbors dithering = new  

            AForge.Imaging.ColorReduction.ColorErrorDiffusionToAdjacentNeighbors(new int[3][] {new int[2] { 5, 3 },new int[5] { 2, 4, 5, 4, 2 }, new int[3] { 2, 3, 2 } });

            Bitmap newImage = dithering.Apply(bt);

运行结果:

            


FloydSteinbergColorDithering:基于弗洛伊德·斯坦伯格误差扩散的色彩抖动,实现如下:

            Bitmap bt = new Bitmap(@"C:\Users\GAOXIANG\Desktop\2.jpg");
            ColorImageQuantizer ciq = new ColorImageQuantizer(new MedianCutQuantizer());
            Color[] colorTable = ciq.CalculatePalette(bt, 16);
            AForge.Imaging.ColorReduction.FloydSteinbergColorDithering dithering = new AForge.Imaging.ColorReduction.FloydSteinbergColorDithering();
            dithering.ColorTable = colorTable;
            Bitmap newImage = dithering.Apply(bt);

运行结果:

           


JarvisJudiceNinkeColorDithering:基于Jarvis-Judice-Ninke 矩阵的图像抖动算法,实现方法完全相同:

            Bitmap bt = new Bitmap(@"C:\Users\GAOXIANG\Desktop\0.jpg");
            ColorImageQuantizer ciq = new ColorImageQuantizer(new MedianCutQuantizer());
            Color[] colorTable = ciq.CalculatePalette(bt, 32);
            AForge.Imaging.ColorReduction.JarvisJudiceNinkeColorDithering dithering = new AForge.Imaging.ColorReduction.JarvisJudiceNinkeColorDithering();
            dithering.ColorTable = colorTable;
            Bitmap newImage = dithering.Apply(bt);

运行结果:

            


在AForge中还提供了:OrderedColorDithering,SierraColorDithering,StuckiColorDithering,使用方法完全相同,在此不再叙述。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值