使用LEADTOOLS的CMYK功能根据颜色从图像中去除特定部分

发布时间:2017/11/08 00:11 发布者:Richard.Ma

返回博客中心

这篇博客讲述如何使用与AddCommand结合ColorSeparateCommand从图像去除一个特定的颜色。示例中的代码块能让黑色的表单以及文字从图像中删除,只留下图像的彩色文本。随后可用于屏蔽文本或用于OCR目的。

注意ColorSeparateCommand产生输出RasterImage四页,依次为青、洋红、黄、黑。通过调用AddCommand除去最后(黑色)一页,只有其他几个颜色被添加,这个也可以被修改为不同的组合以保持或删除特定颜色。由于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);
         }
      }

 

下面是处理前后的图像对比

label

output_label


关于葡萄城

赋能开发者!葡萄城是专业的集开发工具、商业智能解决方案、低代码开发平台于一身的软件和服务提供商,为超过 75% 的全球财富 500 强企业提供服务。葡萄城专注控件软件领域30年,希望通过模块化的开发控件、灵活的低代码应用开发平台等一系列开发工具、解决方案和服务,帮助开发者快速响应复杂多变的业务需求,最大程度地发挥开发者的才智和潜能,让开发者的 IT 人生更从容更美好。

了解详情,请访问葡萄城官网