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, April 20, 2017 6:13:25 PM(UTC)

Amin  
Amin

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.
blendresult.png

Edited by moderator Monday, April 24, 2017 10:56:52 AM(UTC)  | Reason: Not specified

Amin Dodin

Senior 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-2024, Yet Another Forum.NET
This page was generated in 0.032 seconds.