LEADTOOLS Support
Imaging
Imaging SDK Examples
HOW TO: Using Image Processing to Create an Antique Photograph
#1
Posted
:
Thursday, June 27, 2019 12:58:08 PM(UTC)
Groups: Registered, Tech Support, Administrators
Posts: 163
Was thanked: 9 time(s) in 9 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.
CombineCommandThen, the AgingCommand is used to apply artifacts such as dust, scratches, and pits.
AgingCommandFinally, the ConvertToColoredGrayCommand uses specific color factors to wash out the image to a have a sepia tone.
ConvertToColoredGrayCommandHere'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.
Nick Crook
Developer Support Engineer
LEAD Technologies, Inc.
LEADTOOLS Support
Imaging
Imaging SDK Examples
HOW TO: Using Image Processing to Create an Antique Photograph
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.