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



Last Go to last post Unread Go to first unread post
#1 Posted : Friday, November 3, 2017 3:16:22 PM(UTC)


Groups: Registered, Tech Support, Administrators
Posts: 161

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

Just a quick note this is a follow-up to a previous forum post in which dropping a specific color from an image was covered.
Using CMYK plane separation to remove colors from an image

This post builds on that to demonstrate how other colours can be reduced to be removed in the same step by using the BalanceColorsCommand.

Here's the input image being processed, with text in various colours. The previous example demonstrated dropping the black text. Here, the red text at the bottom will be reduced to the black plane as well so it is also dropped as part of the operation.

This syntax applies the BalanceColorsCommand with the parameters for red to have no weight, but green and blue to have standard weight.


    RasterCodecs codecs = new RasterCodecs();
    RasterImage image = codecs.Load(imagePath);

    BalanceColorsCommand bcc = new BalanceColorsCommand(
       new BalanceColorCommandFactor(0, 0, 0), // red
       new BalanceColorCommandFactor(0, 1, 0), // green
       new BalanceColorCommandFactor(0, 0, 1)); // blue

Note effectively removing the red tints the remaining image cyan.

The same procedure can be used to separate the color planes, then using the AddCommand to recombine them. However, given the cyan plane is effectively an inverse of the black plane, it needs to be removed prior to performing the AddOperation.

    ColorSeparateCommand csc = new ColorSeparateCommand(ColorSeparateCommandType.Cmyk);

    csc.DestinationImage.RemovePageAt(4); // page 4 is black plane
    csc.DestinationImage.RemovePageAt(1); // page 1 is cyan plane

    AddCommand ac = new AddCommand(AddCommandType.Add);

    InvertCommand ic = new InvertCommand();
    AutoBinarizeCommand abc = new AutoBinarizeCommand();

Here's the output final output with the black text and red text subsequently removed programatically and ready for OCR.

Similar programming techniques can be used for other colours as well, however, ones which don't have a direct colour complement that gets split into its own plane may require additional processing.

Edited by user Friday, June 1, 2018 11:56:40 AM(UTC)  | Reason: Updating links to v20

Nick Crook
Developer Support Engineer
LEAD Technologies, Inc.

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.054 seconds.