LEADTOOLS Support
Imaging
Imaging SDK Examples
HOWTO: Simple change to alpha mask to produce smooth blending
#1
Posted
:
Thursday, April 20, 2017 6:13:25 PM(UTC)
Groups: Manager, Tech Support
Posts: 367
Was thanked: 1 time(s) in 1 post(s)
The FeatherAlphaBlendCommand class and equivalent L_FeatherAlphaBlendBitmap() function are used for combining a foreground image on top of a background image using a grayscale mask.
If the mask has abrupt jumps from black to white, the blended pixels at these jumps could have some noise. To reduce that effect, a simple averaging of the mask image before blending will case the edges to become gradual changes, which in turn will produce smoother transitions at the corresponding blended pixels.
The following code was executed twice, the first without averaging the mask and the second with the averaging:
Code:RasterCodecs rasterCodecs = new RasterCodecs();
//load foreground image
RasterImage imgBlended = rasterCodecs.Load("Blended.bmp");
//load background image
RasterImage imgBackground = rasterCodecs.Load("BackgroundDoc.tif");
//create blending mask
RasterImage imgMask = imgBlended.Clone();
//fill non-white in mask with pure black
imgMask.AddColorToRegion(RasterColor.White, RasterRegionCombineMode.SetNot);
FillCommand cmdFill = new FillCommand(RasterColor.Black);
cmdFill.Run(imgMask);
imgMask.MakeRegionEmpty();
GrayscaleCommand cmdGray = new GrayscaleCommand(8);
cmdGray.Run(imgMask);
InvertCommand cmdInvert = new InvertCommand();
cmdInvert.Run(imgMask);
var DoTheAveraging = MessageBox.Show("Perform averaging of the mask?", "Test Blending", MessageBoxButtons.YesNo);
if (DoTheAveraging == System.Windows.Forms.DialogResult.Yes)
{
//smooth the mask
AverageCommand cmdAvg = new AverageCommand(4);
cmdAvg.Run(imgMask);
}
LeadRect rect = new LeadRect(500, 500, imgBlended.Width, imgBlended.Height);
FeatherAlphaBlendCommand cmdFeather = new FeatherAlphaBlendCommand(imgBlended, LeadPoint.Empty, rect, imgMask);
cmdFeather.Run(imgBackground);
The attached image shows the result in both cases.
Edited by moderator Monday, April 24, 2017 10:56:52 AM(UTC)
| Reason: Not specified
Amin Dodin
Senior Support Engineer
LEAD Technologies, Inc.
LEADTOOLS Support
Imaging
Imaging SDK Examples
HOWTO: Simple change to alpha mask to produce smooth blending
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.