Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Friday, February 24, 2017 12:07:52 PM(UTC)

Nick  
Nick

Groups: Registered, Tech Support, Administrators
Posts: 163

Was thanked: 9 time(s) in 9 post(s)

This shows how to use the ColorSeparateCommand in conjunction with the AddCommand to drop a specific color from an image. This particular code block shows how the black form can be removed from the image, leaving only a 1-bit image of the colored text. This can subsequently be used to mask out the text or for OCR purposes.

Note the ColorSeparateCommand produces four pages in the output rasterimage, one each for cyan, magenta, yellow, and black, in that order. By removing the last (black) page prior to calling AddCommand, only the CMY planes are added together. This can be modified to keep or drop different combinations of colors. As the ColorSeparateCommand returns planes based on intensity, the resultant images are white-on-black, hence using the InvertCommand to create black-on-white before saving the output.

Here's links to the RasterCommands of interest used here.
ColorSeparateCommand
AddCommand
InvertCommand

Code:

      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);
         }
      }


File Attachment(s):
output_label.tif (12kb) downloaded 282 time(s).


File Attachment(s):
label.tif (176kb) downloaded 274 time(s).

Edited by user Friday, June 1, 2018 10:37:51 AM(UTC)  | Reason: Updating links to v20

Nick Crook
Developer Support Engineer
LEAD Technologies, Inc.
LEAD Logo
 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.049 seconds.