算法与计算机科学mzucker.github.io
页面去扭曲:把弯曲书页扫描成平整图像
Page Dewarping
2016 — 2024,它一次次回到首页
黑点是上首页(≥ 50 分)的那次投稿,空心点是没冲上去的投稿,点越大分数越高。
导读
作者 Matt Zucker 展示了一个开源的页面去弯曲(dewarping)项目:把拍摄的书页照片中因纸张弯曲和透视造成的文字变形自动拉直。文章配有大量图解,介绍了如何用网格拟合和轮廓检测来建模弯曲页面并恢复平整图像,最终输出适合 OCR 或阅读的清晰扫描效果。
为什么经久不衰:它用清晰的图文把一个看似困难的计算机视觉问题讲得直观易懂,且代码开源、思路经久实用,八年后仍被顶上首页。
HN 评论精选
用 GIMP 手动流程几分钟也能达到类似效果,并详细分享了操作步骤
这话题让我很有共鸣,我用 GIMP 的交互式滤镜手工做过很多次,效果很好:把桌上弯曲书页的透视照片几乎完美地拉直,再二值化成干净黑白。我给文中同一个例子做了个快速粗糙的手工版(附链接),前后不到五分钟。步骤是:裁剪、复制图层、对上层高斯模糊(半径 50)、切换为 Divide 模式合并,这样能很好地均衡光照、几乎消除右侧阴影;然后用横向透视变换把弯曲大致变成水平(透视变换不仅能加透视,也能反透视!);最后用 Curve Bend 做补偿性弯曲。
kazinator查看英文原文
This strikes close to home for me, because I've done this "by hand" quite a number of times, using some interactive Gimp filters, with very good results. I've been able to take a perspective photo of a curved page lying on a desk, get it almost perfectly straight, and threshold it to clean black and white or sharp gray scale. Here is my very quick and dirty manual job of the same example page: http://www.kylheku.com/~kaz/dewarp.png Literally less than five minutes. First I cropped the image. Then duplicated the layer. Blurred the top layer (Gaussian, 50 radius). Then flipped to Divide mode and merged the visible layers. This leveled the lightness quite well, almost completely eliminating the shadow over he right side of the page and all other lighting differences. There is a hint of the edge of the shadow still present because it is such a sharp contrast; but that can be eliminated in an adjustment of the intensity curves. In such cases it may be helpful to experiment with smaller blur radii, too. I then did a perspective transform in the lateral direction, squeezing the left side top-bottom and expanding the right, resulting in the warp now being approximately horizontal. (The perspective transform is not just for adding a perspective effect; it is also useful reversing perspective!) Finally, I used the Curve Bend (with its horrible interactive interface and awful preview) to warp in a compensating way. Basically, the idea is to draw an upper and lower curve which is the opposite of the curve on the page. I made two attempts, keeping the results of the second. If the preview of this tool wasn't a ridiculous, inscrutable thumbnail, it would be possible to do an excellent job in one attempt, probably close to perfect. Because the page is evenly light thanks to the divide-by-blurred layer trick, it will nicely threshold to black and white, or a narrow grayscale range.
赞赏图文并茂的讲解方式,并好奇去弯曲后的图像处理细节
我喜欢这种配图充分的写作,即使不懂数学和编程的读者也能看懂作者的步骤。他的模型似乎比圆柱体更能真实地表示弯曲的纸面。希望他能多讲讲去弯曲之后的处理步骤——调 levels 能获得好对比度,但结果里居然没有欠曝光的阴影或过曝光的细节损失。不知道他之后有没有跑 OCR;说到 OCR,Leptonica 是 Tesseract 的依赖之一,应该也做了类似的预处理。(后记:细读后发现他提到用了 OpenCV 的自适应阈值。)
cooper12查看英文原文
I love well-illustrated writeups. Even a reader without mathematics or programming knowledge can understand what steps the author took. His model actually seems to better represent the warped paper than a cylinder would. (though I don't know the actual specifics of the CTM model) I wish he went into more details on the steps taken after dewarping. You can tweak the image levels to get good contrast, but surprisingly there aren't any shadows from underleveling or loss of detail from overleveling. I wonder if the author ran OCR on the scans after, and speaking of OCR, IIRC Leptonica is one of the dependencies of Tesseract so it must do some similar pre-processing. Edit: reading more carefully, he mentions that he used adaptive thresholding from OpenCV.
指出 Dropbox 此前也介绍过同类技术,而本项目开源
最近 Dropbox 写过一篇关于 OCR 前去弯曲的文章(附 HN 链接)。这份代码想法相同,而且是开源的!
niftich查看英文原文
Recently, Dropbox wrote about dewarping prior to OCR in their app: https://news.ycombinator.com/item?id=12297944 This code had the same idea, and is open-source!
日常工具 Office Lens 尚不支持去弯曲,期待此类功能普及
我在安卓手机上一直在用微软的 Office Lens,它像个智能相机,能自动把每张书页照片摆正并做白平衡(通常拍的是邮件或手填表格)。但它处理不了弯曲的页面,希望他们能加上类似这样的功能!
troymc查看英文原文
I use Microsoft's "Office Lens" app on my Android phone all the time, like a "smart camera" which automatically squares off and white-balances each photo of a page (usually mail or forms filled in by hand). It can't handle warped pages though, so I hope they add something like this!
历次讨论
同类还值得读
位运算技巧集
Bit Twiddling Hacks
斯坦福页面上的经典位运算技巧合集,收录了 popcount、前导/尾随零、位反转、交换、舍入等大量技巧,并附有解释和性能讨论。
算法与计算机科学上首页 8 次 · 2011–2024graphics.stanford.edu编辑精选如何不按平均评分排序
How Not To Sort By Average Rating
经典文章解释了为什么按平均评分排序不可靠:只有少量评价的条目(比如仅一条五星)会轻易排到最前,而评价数量的差异被忽略。
算法与计算机科学上首页 7 次 · 2009–2024evanmiller.org编辑精选数据结构可视化
Data Structure Visualizations
旧金山大学 David Galles 教授制作的数据结构与算法交互式可视化网站,涵盖 B 树、红黑树、排序、图算法等,可逐步操作观察其运行过程。
算法与计算机科学上首页 6 次 · 2011–2021cs.usfca.edu编辑精选1996 年以来的计算机科学最佳论文奖
Best Paper Awards in Computer Science since 1996
Jeff Huang 维护的一个汇总页面,收录了自 1996 年以来计算机科学各主要会议的“最佳论文奖”获奖名单,并按年份和会议整理,方便读者一站式浏览历届获奖论文。
算法与计算机科学上首页 6 次 · 2010–2018jeffhuang.com编辑精选算法(Jeff Erickson)
Algorithms, by Jeff Erickson
伊利诺伊大学 Jeff Erickson 教授的算法课教材,免费在线开放。
算法与计算机科学上首页 5 次 · 2018–2022jeffe.cs.illinois.edu编辑精选