请选择 进入手机版 | 继续访问电脑版
 找回密码
 立即注册

QQ登录

只需一步,快速开始

本篇讲述如何使用ColorSeparateCommand与AddCommand一起从图像中删除特定的颜色。 这个特定的代码块显示了如何从图像中删除黑色,只留下彩色文本的1位图像。 这可以随后用于掩盖文本或OCR目的。

请注意,ColorSeparateCommand在输出光栅图像中生成四个页面,每个页面以青色,品红色,黄色和黑色顺序排列。 通过在调用AddCommand之前删除最后一个(黑色)页面,只有CMY平面被加在一起。 这可以修改以保持或删除不同的颜色组合。 由于ColorSeparateCommand基于强度返回平面,所得到的图像是黑白色的,因此在保存输出之前使用InvertCommand创建黑白。

这里是相关的RasterCommands。
ColorSeparateCommand
AddCommand
InvertCommand

  1. private static void DoColorPlaneSeparation(string input)
  2.       {
  3.          string outPath = Path.GetDirectoryName(input);
  4.          string outFile = Path.GetFileName(input);

  5.          using (RasterCodecs codecs = new RasterCodecs())
  6.          {
  7.             RasterImage image = codecs.Load(input);
  8.             ColorSeparateCommand csc = new ColorSeparateCommand(ColorSeparateCommandType.Cmyk);

  9.             csc.Run(image);

  10.             csc.DestinationImage.RemovePageAt(4);

  11.             AddCommand ac = new AddCommand(AddCommandType.Add);
  12.             ac.Run(csc.DestinationImage);

  13.             InvertCommand ic = new InvertCommand();
  14.             ic.Run(ac.DestinationImage);

  15.             AutoBinarizeCommand abc = new AutoBinarizeCommand();
  16.             abc.Run(ac.DestinationImage);

  17.             string outputFile = Path.Combine(outPath, "output_" + outFile);
  18.             codecs.Save(ac.DestinationImage, outputFile, image.OriginalFormat, image.BitsPerPixel);
  19.          }
  20.       }
复制代码


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x

0 个回复

您需要登录后才可以回帖 登录 | 立即注册
返回顶部