以编程方式在图像上用黑色边框填充白色边框的最佳方法
我有超过 10 万张图像,这些图像曾经被裁剪并应用了白色边框。我正在寻找以编程方式处理每个图像的最佳方法,以便我可以检测白色边框并裁剪边框或用黑色填充边框。我需要使用 OpenCV 之类的东西还是只是普通的旧 GDI?我附上了一张图片供参考。
我必须处理的内容(白色边框在那里,相信我):
I have over 100k in images that at one time were cropped and had a white border applied to them. I'm looking for the best way to programmaticly process each image so that I can detect the white borders and either crop the border or fill in the border with black instead. Would I need to use something like OpenCV or just plain old GDI? I've attached an image for reference.
What I have to work with (White borders are there, trust me):
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
普通的旧 GDI 应该可以正常工作,除了一件事 - 我不知道如何使 GDI 将图像保存回文件。过去,当我不得不这样做时,我会分段编写一个 .BMP 文件,这对于 JPEG 不起作用。是时候提出新问题了吗?
您将需要一个两步过程 - 首先测量白色边框,然后将图像复制到新图像以消除它们。
从 JPEG 图像开始会带来两个小问题。首先,图像将包含一些解码伪影,并且白色并不总是 RGB 值 (255,255,255)。您需要建立一个阈值,例如 (250,250,250) 并看看它是如何工作的;如果它没有捕获所有边界,您需要尝试较低的阈值。其次,将图像重新保存为 JPEG 会引入额外的伪影,从而降低图像质量。希望这在可接受的范围内,但只有你才能对此做出判断。
抱歉,这并不是一个真正的答案,也许更像是答案的 1/4。我希望你觉得它有用。
Plain old GDI should work just fine, except for one thing - I don't know how to make GDI save an image back to a file. When I've had to do it in the past I've written a .BMP file in pieces, which wouldn't work for a JPEG. Time for a new question?
You're going to need a two step process - first measure the white borders, then copy the image to a new image to get rid of them.
Starting with a JPEG image introduces two small problems. First is that the image will contain some decoding artifacts, and white won't always be an RGB value of (255,255,255). You'll need to establish a threshold, such as (250,250,250) and see how that works; if it doesn't catch all of the borders, you'll need to try a lower threshold. Second is that resaving the image as a JPEG will introduce additional artifacts, lowering the quality of the image. Hopefully this will be within acceptable limits, but only you can be the judge of that.
I'm sorry that this isn't really an answer, perhaps more like 1/4 of an answer. I hope you find it useful.