Richard.Ma 发表于 2017-7-17 10:24:52

使用CMYK平面分离从图像中删除颜色 - 根据颜色以程序方式删除图像的特定部分

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

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

这里是相关的RasterCommands。
ColorSeparateCommand
AddCommand
InvertCommand

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

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

            csc.Run(image);

            csc.DestinationImage.RemovePageAt(4);

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

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

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

            string outputFile = Path.Combine(outPath, "output_" + outFile);
            codecs.Save(ac.DestinationImage, outputFile, image.OriginalFormat, image.BitsPerPixel);
         }
      }

页: [1]
查看完整版本: 使用CMYK平面分离从图像中删除颜色 - 根据颜色以程序方式删除图像的特定部分