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 : Thursday, June 27, 2019 1:03:08 PM(UTC)

Nick  
Nick

Groups: Registered, Tech Support, Administrators
Posts: 73

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

This code tip demonstrates how multiple image processing functions can be used in succession to take an input image and convert it so has an "antique photograph" look. This code tip uses cannon.jpg located in the LEADTOOLS images folder.

First, a new RasterImage is created slightly larger than the source image. The CombineCommand merges the source image with this one to give the image a border. The new RasterImage is LightGray so the effects on the border will be more pronounced.
CombineCommand

Then, the AgingCommand is used to apply artifacts such as dust, scratches, and pits.
AgingCommand

Finally, the ConvertToColoredGrayCommand uses specific color factors to wash out the image to a have a sepia tone.
ConvertToColoredGrayCommand

Here's the code that performs all this.

Code:

      public static void AntiquatePicture()
      {
         string inputFilepath = @"C:\Users\Public\Documents\LEADTOOLS Images\cannon.jpg";
         string outputImage = @"C:\Users\Public\Documents\LEADTOOLS Images\cannon-antique-photo.jpg";
         int border = 25;

         using (RasterCodecs codecs = new RasterCodecs())
         {
            RasterImage inputImage = codecs.Load(inputFilepath);
            RasterImage image = RasterImage.Create(inputImage.Width + border * 2, inputImage.Height + border * 2, inputImage.BitsPerPixel, inputImage.XResolution, RasterColor.FromKnownColor(RasterKnownColor.LightGray));

            CombineCommand cc = new CombineCommand();
            cc.SourceImage = inputImage;
            cc.SourcePoint = new LeadPoint(0, 0);
            cc.Flags = CombineCommandFlags.SourceCopy;
            cc.DestinationRectangle = new LeadRect(border, border, inputImage.Width, inputImage.Height);
            cc.Run(image);

            AgingCommand ac = new AgingCommand();
            ac.HorizontalScratchCount = 10;
            ac.VerticalScratchCount = 2;
            ac.MaximumScratchLength = 50;
            ac.DustDensity = 2;
            ac.PitsDensity = 5;
            ac.MaximumPitSize = 16;
            ac.ScratchColor = new RasterColor(255, 255, 0);
            ac.DustColor = new RasterColor(0, 0, 0);
            ac.PitsColor = new RasterColor(0, 0, 255);
            ac.Flags = AgingCommandFlags.AddNothing | AgingCommandFlags.AddVerticalScratch | AgingCommandFlags.AddPits | AgingCommandFlags.ScratchInverse | AgingCommandFlags.PitsColor;
            ac.Run(image);

            ConvertToColoredGrayCommand ctcgc = new ConvertToColoredGrayCommand();
            ctcgc.RedFactor = 300;
            ctcgc.GreenFactor = 590;
            ctcgc.BlueFactor = 110;
            ctcgc.RedGrayFactor = 500;
            ctcgc.GreenGrayFactor = 300;
            ctcgc.BlueGrayFactor = 200;
            ctcgc.Run(image);

            codecs.Save(image, outputImage, inputImage.OriginalFormat, image.BitsPerPixel);
         }
      }


Note the parameters can be adjusted to change the border size, artifact density, and output tone. Here's the output image.
File Attachment(s):
cannon-antique-photo.jpg (305kb) downloaded 25 time(s).
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-2019, Yet Another Forum.NET
This page was generated in 0.064 seconds.