LEADTOOLS Support
Imaging
Imaging SDK Examples
Using CMYK plane separation to remove colors from an image
#1
Posted
:
Friday, February 24, 2017 12:07:52 PM(UTC)
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.
ColorSeparateCommandAddCommandInvertCommandCode:
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);
}
}
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.
LEADTOOLS Support
Imaging
Imaging SDK Examples
Using CMYK plane separation to remove colors from an image
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.