Checks and auto-corrects an inverted image.
public class InvertedPageCommand : Leadtools.Imageprocessing.Leadtools.ImageProcessing.RasterCommand, Leadtools.Imageprocessing.Leadtools.ImageProcessing.IRasterCommandPublic Class InvertedPageCommandInherits Leadtools.Imageprocessing.Leadtools.ImageProcessing.RasterCommandImplements Leadtools.Imageprocessing.Leadtools.ImageProcessing.IRasterCommand
public sealed class InvertedPageCommand : Leadtools.Imageprocessing.Leadtools.ImageProcessing.IRasterCommand@interface LTInvertedPageCommand : LTRasterCommandpublic class InvertedPageCommand extends RasterCommandfunction Leadtools.ImageProcessing.Core.InvertedPageCommand()public ref class InvertedPageCommand : public Leadtools.Imageprocessing.Leadtools.ImageProcessing.RasterCommand, Leadtools.Imageprocessing.Leadtools.ImageProcessing.IRasterCommandAn inverted RasterImage is an image that has text or other objects in high contrast color on a low contrast background, for example white text on black background. This command can determine whether an image is inverted and correct it automatically.
This command can only detect an entire image. To search for and correct specific inverted areas or regions in an image, use the InvertedTextCommand.
A common source of inverted images are black and white images saved with a non-standard palette by some applications.
This command does not support signed data images.
For more information, refer to Cleaning Up 1-Bit Images.
In Silverlight versions of LEADTOOLS, this image processing command will fail if the image data for the RasterImage object is stored internally using a Silverlight WriteableBitmap object. For more information, refer to Image Processing Command Limitations in Silverlight.
This example will show how to use the InvertedPageCommand class to check and auto-correct inverted images.
Imports LeadtoolsImports Leadtools.CodecsImports Leadtools.ImageProcessing.CoreImports Leadtools.ImageProcessing.ColorPublic Sub InvertedPageCommandExample()Dim codecs As New RasterCodecs()' Get an imageDim tifFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "ocr1.tif")Dim invertedImageFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "ocr1_Inverted.tif")Dim nonInvertedImageFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "ocr1_NonInverted.tif")Dim image As RasterImage = codecs.Load(tifFileName)' The images should be non-inverted at the beginning, checkDim invertedPage As New InvertedPageCommand(InvertedPageCommandFlags.NoProcess)invertedPage.Run(image)Console.WriteLine("Original image, inverted = {0}", invertedPage.IsInverted)' Invert the imageDim invert As New InvertCommand()invert.Run(image)codecs.Save(image, invertedImageFileName, image.OriginalFormat, image.BitsPerPixel)' Check againinvertedPage.Run(image)Console.WriteLine("After running InvertCommand, inverted = {0}", invertedPage.IsInverted)' Now run the command to un-invert the imageinvertedPage.Flags = InvertedPageCommandFlags.ProcessinvertedPage.Run(image)' Now check the image againinvertedPage.Flags = InvertedPageCommandFlags.NoProcessinvertedPage.Run(image)Console.WriteLine("After running InvertedPageCommand, inverted = {0}", invertedPage.IsInverted)codecs.Save(image, nonInvertedImageFileName, image.OriginalFormat, image.BitsPerPixel)image.Dispose()codecs.Dispose()End SubPublic NotInheritable Class LEAD_VARSPublic Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"End Class
using Leadtools;using Leadtools.Codecs;using Leadtools.ImageProcessing.Core;using Leadtools.ImageProcessing.Color;public void InvertedPageCommandExample(){RasterCodecs codecs = new RasterCodecs();// Get an imagestring tifFileName = Path.Combine(LEAD_VARS.ImagesDir, "ocr1.tif");string invertedImageFileName = Path.Combine(LEAD_VARS.ImagesDir, "ocr1_Inverted.tif");string nonInvertedImageFileName = Path.Combine(LEAD_VARS.ImagesDir, "ocr1_NonInverted.tif");RasterImage image = codecs.Load(tifFileName);// The images should be non-inverted at the beginning, checkInvertedPageCommand invertedPage = new InvertedPageCommand(InvertedPageCommandFlags.NoProcess);invertedPage.Run(image);Console.WriteLine("Original image, inverted = {0}", invertedPage.IsInverted);// Invert the imageInvertCommand invert = new InvertCommand();invert.Run(image);codecs.Save(image, invertedImageFileName, image.OriginalFormat, image.BitsPerPixel);// Check againinvertedPage.Run(image);Console.WriteLine("After running InvertCommand, inverted = {0}", invertedPage.IsInverted);// Now run the command to un-invert the imageinvertedPage.Flags = InvertedPageCommandFlags.Process;invertedPage.Run(image);// Now check the image againinvertedPage.Flags = InvertedPageCommandFlags.NoProcess;invertedPage.Run(image);Console.WriteLine("After running InvertedPageCommand, inverted = {0}", invertedPage.IsInverted);codecs.Save(image, nonInvertedImageFileName, image.OriginalFormat, image.BitsPerPixel);image.Dispose();codecs.Dispose();}static class LEAD_VARS{public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";}
using Leadtools;using Leadtools.Codecs;using Leadtools.ImageProcessing.Core;using Leadtools.ImageProcessing.Color;public async Task InvertedPageCommandExample(){RasterCodecs codecs = new RasterCodecs();// Load the imagestring srcFileName = @"Assets\ocr1.tif";StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName);RasterImage image = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile));// The images should be non-inverted at the beginning, checkInvertedPageCommand invertedPage = new InvertedPageCommand(InvertedPageCommandFlags.NoProcess);invertedPage.Run(image);Debug.WriteLine("Original image, inverted = {0}", invertedPage.IsInverted);// Invert the imageInvertCommand invert = new InvertCommand();invert.Run(image);string destFileName = @"ocr1_Inverted.tif";StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(destFileName);await codecs.SaveAsync(image, LeadStreamFactory.Create(saveFile), image.OriginalFormat, image.BitsPerPixel);// Check againinvertedPage.Run(image);Debug.WriteLine("After running InvertCommand, inverted = {0}", invertedPage.IsInverted);// Now run the command to un-invert the imageinvertedPage.Flags = InvertedPageCommandFlags.Process;invertedPage.Run(image);// Now check the image againinvertedPage.Flags = InvertedPageCommandFlags.NoProcess;invertedPage.Run(image);Debug.WriteLine("After running InvertedPageCommand, inverted = {0}", invertedPage.IsInverted);destFileName = @"ocr1_NonInverted.tif";saveFile = await Tools.AppLocalFolder.CreateFileAsync(destFileName);await codecs.SaveAsync(image, LeadStreamFactory.Create(saveFile), image.OriginalFormat, image.BitsPerPixel);image.Dispose();codecs.Dispose();}
using Leadtools;using Leadtools.ImageProcessing;using Leadtools.Examples;using Leadtools.Codecs;using Leadtools.ImageProcessing.Core;using Leadtools.ImageProcessing.Color;public void InvertedPageCommandExample(RasterImage image, Stream outStream1, Stream outStream2){// The images should be non-inverted at the beginning, checkInvertedPageCommand invertedPage = new InvertedPageCommand(InvertedPageCommandFlags.NoProcess);invertedPage.Run(image);Debug.WriteLine("Original image, inverted = {0}", invertedPage.IsInverted);// Invert the imageInvertCommand invert = new InvertCommand();invert.Run(image);RasterCodecs codecs = new RasterCodecs();// save image to "ocr1_Inverted.tif";codecs.Save(image, outStream1, image.OriginalFormat, image.BitsPerPixel);// Check againinvertedPage.Run(image);Debug.WriteLine("After running InvertCommand, inverted = {0}", invertedPage.IsInverted);// Now run the command to un-invert the imageinvertedPage.Flags = InvertedPageCommandFlags.Process;invertedPage.Run(image);// Now check the image againinvertedPage.Flags = InvertedPageCommandFlags.NoProcess;invertedPage.Run(image);Debug.WriteLine("After running InvertedPageCommand, inverted = {0}", invertedPage.IsInverted);// save result image to "ocr1_NonInverted.tif"codecs.Save(image, outStream2, RasterImageFormat.CcittGroup4, 1);image.Dispose();}
Imports LeadtoolsImports Leadtools.ImageProcessingImports Leadtools.CodecsImports Leadtools.ImageProcessing.CoreImports Leadtools.ImageProcessing.ColorPublic Sub InvertedPageCommandExample(ByVal image As RasterImage, ByVal outStream1 As Stream, ByVal outStream2 As Stream)' The images should be non-inverted at the beginning, checkDim invertedPage As InvertedPageCommand = New InvertedPageCommand(InvertedPageCommandFlags.NoProcess)invertedPage.Run(image)Debug.WriteLine("Original image, inverted = {0}", invertedPage.IsInverted)' Invert the imageDim invert As InvertCommand = New InvertCommand()invert.Run(image)Dim codecs As RasterCodecs = New RasterCodecs()' save image to "ocr1_Inverted.tif";codecs.Save(image, outStream1, image.OriginalFormat, image.BitsPerPixel)' Check againinvertedPage.Run(image)Debug.WriteLine("After running InvertCommand, inverted = {0}", invertedPage.IsInverted)' Now run the command to un-invert the imageinvertedPage.Flags = InvertedPageCommandFlags.ProcessinvertedPage.Run(image)' Now check the image againinvertedPage.Flags = InvertedPageCommandFlags.NoProcessinvertedPage.Run(image)Debug.WriteLine("After running InvertedPageCommand, inverted = {0}", invertedPage.IsInverted)' save result image to "ocr1_NonInverted.tif"codecs.Save(image, outStream2, RasterImageFormat.CcittGroup4, 1)image.Dispose()End Sub
Leadtools.ImageProcessing.Core Namespace
HighQualityRotateCommand Class
|
Products |
Support |
Feedback: InvertedPageCommand Class - Leadtools.ImageProcessing.Core |
Introduction |
Help Version 19.0.2017.3.21
|

Raster .NET | C API | C++ Class Library | JavaScript HTML5
Document .NET | C API | C++ Class Library | JavaScript HTML5
Medical .NET | C API | C++ Class Library | JavaScript HTML5
Medical Web Viewer .NET
Your email has been sent to support! Someone should be in touch! If your matter is urgent please come back into chat.
Chat Hours:
Monday - Friday, 8:30am to 6pm ET
Thank you for your feedback!
Please fill out the form again to start a new chat.
All agents are currently offline.
Chat Hours:
Monday - Friday
8:30AM - 6PM EST
To contact us please fill out this form and we will contact you via email.