去除图像周围的黑色边框
我有几张 JPG 图片。 其中一些可能在一侧或多侧有黑色边框,我想将其删除。 黑色边框可能不会围绕实际图像 - 有些可能只在底部有边框(实际图像在顶部),而有些可能会居中(这意味着两侧都有黑色边框,但不相连)。 更糟糕的是,图像是 JPG 压缩的,因此它们可能不再是精确的 0,0,0 黑色。
在绘画程序中,我会“简单地”使用容差较低的魔棒工具,但我需要在 ASP.net 上用 C# 来完成此操作,而且我不知道最好的方法是什么。
我应该“扫描”每一行,然后每一列(两个嵌套的 for 循环)来查找黑色区域吗? 从性能和 CPU 负载角度来看,这样做听起来有点愚蠢。 或者 GDI+ 是否已经内置了一些魔杖工具?
图像不是那么大(最大 474x474 像素)并随后缓存,但我需要保持服务器负载尽可能低。
有什么暗示最不愚蠢的做法是什么吗?
I have a few JPG Images. Some of them may have a black border on one or more sides, and I'd like to remove them. The black border may not go around the actual image - some may only have the border at the bottom (with the actual image at the top), while some could be centered (which means black borders on two sides, but not connected). Worse, the images are JPG Compressed, so they may not be exactly 0,0,0 black anymore.
In a Paint Program, I would "simply" use the Magic Wand tool with a low tolerance, but I need to do it in C# on ASP.net, and I don't know what the best way of doing this is.
Should I "scan" each line and then each column (two nested for-loops) to find black areas? Sounds somewhat stupid to do, performance and CPU-Load-wise. Or does GDI+ have some magic wand tool build in already?
The images are not that big (474x474 pixels maximum) and cached afterwards, but I need to keep the server load as low as possible.
Any hints what the least stupid way of doing it would be?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
似乎对于每个边缘你都可以做这样的事情:
It seems like for each edge you could do something like this: