LEADTOOLS Support
Imaging
Imaging SDK Examples
HOWTO: Highlight similar pixels in 2 bitmaps
#1
Posted
:
Thursday, October 27, 2016 5:49:03 PM(UTC)
Groups: Manager, Tech Support
Posts: 367
Was thanked: 1 time(s) in 1 post(s)
The code below takes 2 images as input and fills with green color every pixel in the first image that's identical to the corresponding pixel in the second image.
This C# code works with v19 of LEADTOOLS, as well as numerous other versions.
Code://load the 2 images
RasterImage bitmap1 = _codecs.Load("Image1.png");
RasterImage bitmap2 = _codecs.Load("Image2.png");
//pefrom XOR combining to convert similar pixels to black in image2. All non-similar pixels become non-black
LeadRect combineRect = new LeadRect(0, 0, bitmap1.Width, bitmap1.Height);
CombineFastCommand combineCmd = new CombineFastCommand(bitmap2, combineRect, new LeadPoint(0, 0), CombineFastCommandFlags.OperationXor);
combineCmd.Run(bitmap1);
//create a region in image2 with all the black pixels. Those pixels were the similar ones.
bitmap2.AddColorToRegion(RasterColor.Black, RasterRegionCombineMode.Set);
//fill the region with green
FillCommand fillGreen = new FillCommand(RasterColor.FromKnownColor(RasterKnownColor.Green));
fillGreen.Run(bitmap2);
//perfom copy combining to copy the green pixels to the first image
combineCmd.DestinationImage = bitmap1;
combineCmd.Flags = CombineFastCommandFlags.SourceCopy;
combineCmd.Run(bitmap2);
//Save the result
_codecs.Save(bitmap1, "Result.png", RasterImageFormat.Png, 24);
First image
Second image
Result
Edited by user Sunday, May 7, 2017 4:27:34 PM(UTC)
| Reason: Not specified
Amin Dodin
Senior Support Engineer
LEAD Technologies, Inc.
LEADTOOLS Support
Imaging
Imaging SDK Examples
HOWTO: Highlight similar pixels in 2 bitmaps
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.