找回密码
 立即注册

QQ登录

只需一步,快速开始

zhuseeav

注册会员

9

主题

26

帖子

73

积分

注册会员

积分
73

活字格认证

zhuseeav
注册会员   /  发表于:2015-6-4 17:38  /   查看:10542  /  回复:15
管理员,请教leadtools有何方法去除图像的背景?如下图:

用ps去除的效果如下:

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x

15 个回复

倒序浏览
iceman
社区贡献组   /  发表于:2015-6-5 15:55:00
沙发
回复 1楼zhuseeav的帖子

可以通过 RasterImage 组件来做,大体思路是获取紫色背景区域,再创建一个透明通道覆盖该区域,参考代码:

  1. RasterImage main = _codecs.Load("DarkBG1.jpg");
  2. RasterImage alpha = main.Clone();
  3. GrayscaleCommand gray = new GrayscaleCommand(8);
  4. gray.Run(alpha);
  5. //create a region of all dark areas
  6. alpha.AddColorRgbRangeToRegion(new RasterColor(0, 0, 0), new RasterColor(40, 40, 40), RasterRegionCombineMode.Set);
  7. FillCommand fill = new FillCommand(RasterColor.FromKnownColor(RasterKnownColor.Black));
  8. //fill the dark areas with black
  9. fill.Run(alpha);
  10. //invert the region so that it covers the non-dark areas
  11. alpha.AddRectangleToRegion(null, new LeadRect(0, 0, alpha.Width, alpha.Height), RasterRegionCombineMode.Xor);
  12. fill.Color = RasterColor.FromKnownColor(RasterKnownColor.White);
  13. //fill the new regin with white
  14. fill.Run(alpha);
  15. //clear the region
  16. alpha.MakeRegionEmpty();
  17. //diffuse the edges to make the boundary smooth between black and white
  18. AverageCommand avg = new AverageCommand(8);
  19. avg.Run(alpha);
  20. main.SetAlphaImage(alpha);
  21. _codecs.Save(main, "DarkBG1withAlpha.png", RasterImageFormat.Png, 32);
复制代码
回复 使用道具 举报
zhuseeav
注册会员   /  发表于:2015-6-5 17:30:00
板凳
试了,调了多个RGB参数, 效果都不理想,
//clear the region
alpha.MakeRegionEmpty();
之后的黑白图 (算是最好的效果了)


还有,下面这两行代码不起作用。。。,保存后看图片还是最开始加载的图
AverageCommand avg = new AverageCommand(8);
avg.Run(alpha);

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2015-6-5 18:37:00
地板
回复 3楼zhuseeav的帖子

问题我们已经查收,这边测试后给您进一步反馈。
回复 使用道具 举报
zhuseeav
注册会员   /  发表于:2015-6-16 10:46:00
5#
还有没有更好的方案?
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2015-6-16 18:03:00
6#
回复 5楼zhuseeav的帖子

当前的调查进展是可以通过 FastMagicWandCommand 类来实现这个功能,其中 Tolerance 属性是设置颜色容差值,再进行替换。

我们正在验证可行性。明天我会通知您进一步进展。

另外,在 C++ 平台下我们通过demo验证了这个问题,操作步骤请参考截屏:


Demo 地址:[LEADTOOLS 19]Examples\CDLL\ImagePF
EXE:C:\LEADTOOLS 19\Shortcuts\Image Processing\C++ Class Library\Image Processing Features

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2015-6-25 16:38:00
7#
回复 5楼zhuseeav的帖子

你好,
能否把1#需要处理图片的原图发送到论坛,我们制作一个demo发送给您查看效果?
当前图片比较模糊无法展示出很好的效果。
回复 使用道具 举报
zhuseeav
注册会员   /  发表于:2015-7-7 04:24:00
8#
不好意思,前段时间没上线。
附件两张图,彩色和灰度,主要是对灰度处理。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2015-7-7 11:08:00
9#
回复 8楼zhuseeav的帖子

好的,图片我们已经查收,有任何进展及时通知您
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2015-7-15 15:05:00
10#
回复 8楼zhuseeav的帖子

你好,

替换背景图请参考附件Demo(VS2013 + C# + LeadTools V19):


操作步骤请参考视频:


谢谢

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复 使用道具 举报
12下一页
您需要登录后才可以回帖 登录 | 立即注册
返回顶部