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

来源:互联网 发布:生死狙击刷金币软件 编辑:程序博客网 时间:2024/05/18 02:54

作者:GAO-XIANG

转自:http://blog.csdn.net/xiang__jiangsu/article/details/8141870


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 0
原创粉丝点击