页面图片如何被整理成看起来好像被扫描了? [英] How can picture of page be straightened out to look as if it was scanned?

查看:373
本文介绍了页面图片如何被整理成看起来好像被扫描了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我见过应用程序,并想知道如何以编程方式拍摄图像。定义它需要如何转换,使其看起来与相机平行,而不是倾斜的视角。



然后合并多张照片以创建pdf文件。例如,此应用可以执行此操作:


  1. 输入图片

  2. 查找主要轮廓



    理想情况下整个网格,但即使外部轮廓也足够(如果不存在网格)。您需要将轮廓分为水平(红色)和垂直(绿色)曲线(或一组点)。


  3. 样本轮廓曲线按4 等距点



    由于图像失真(不仅仅是旋转),我们需要至少使用双三次插值。为此,我们需要每个补丁16点(Aqua)。


  4. 添加镜像点以覆盖整个网格

    $ b图像上的
    $ b

    是镜像(黄色)点,仅适用于水平轮廓,对于垂直轮廓也应该这样做(不适合我在图像中,并且不想为此扩大分辨率)和还有角点,所以你得到 6x6 控制点。镜子可以线性完成(就像我一样)。


现在转换完成如下:


  1. 处理所有像素 dst(x0,y0)目标图像

  2. 处理 x,y 作为三次插值的参数



    如果 xs,ys 是目标图像分辨率,那么:

      u =(3.0 * x)/ xs 
    v =(3.0 * y)/ ys

    现在,立方插值通常在参数 t =< 0.0,1.0)上完成,所以

    如果 u =< 0.0,1.0> 使用 t = u 和控制点 0 ,1,2,3-

    如果 u =< 1.0,2.0)使用 t = u-1.0 并控制积分 1,2,3,4

    如果 u =< 2.0,3.0> 使用 t = u-2.0 和控制点 2,3,4,5



    纵向轮廓和 v 也是如此。计算 xi,yi 作为(u,v)的双三次插值。并复制像素:

      dst(x,y)= src(xi,yi); 

    这只是最近邻居,但你也可以使用双线性...作为立方曲线我会使用此多项式



    双三次插值背后的想法简单。在4个水平轮廓上对应于参数 u 的计算点。这将为您提供4个垂直方向的最终三次插值控制点和 v 作为参数。结果坐标是您的源像素位置。


有关详细信息,请参阅:





如果您没有网格,请使用可以作为一个网格使用的任何信息。例如,文本行可以被视为此轮廓...


I have seen apps, and wondered how can I programmatically take a picture of image. Define how it needs to be transformed so that it looks parallel to camera and not skewed perspective wise.

Then combine multiple photos to create a pdf file. For example this app does it: https://play.google.com/store/apps/details?id=com.appxy.tinyscan&hl=en

解决方案

I do not use books for such trivial things so sorry I can not recommend any (especially in English). What you need to do is this:

  1. input image
  2. find main contours

    ideally whole grid but even outer contour will suffice (in case no grid is present). You need to divide the contour into horizontal (Red) and vertical (Green) curves (or set of points).

  3. sample contour curves by 4 "equidistant" points

    as the image is distorted (not just rotated) then we need to use at least bi-cubic interpolation. For that we need 16 points (Aqua) per patch.

  4. add mirror points to cover whole grid

    on the image are mirrored (Yellow) points only for horizontal contours you should do this also for vertical contours (did not fit me in the image and did not want to enlarge resolution just for that) and also for the corner points so you got 6x6 control points. The mirror can be done linearly (like I did).

Now the transformation is done like this:

  1. Process all pixels dst(x0,y0) of target image
  2. Handle x,y as parameter for cubic interpolation

    if xs,ys is target image resolution then:

    u=(3.0*x)/xs
    v=(3.0*y)/ys
    

    Now cubic interpolation is usually done on parameter t=<0.0,1.0) so
    if u=<0.0,1.0> use t=u and control points 0,1,2,3.
    if u=<1.0,2.0) use t=u-1.0 and control points 1,2,3,4
    if u=<2.0,3.0> use t=u-2.0 and control points 2,3,4,5

    The same goes for vertical contours and v. Compute xi,yi as bi cubic interpolation of (u,v). And copy pixel:

    dst(x,y)=src(xi,yi);
    

    This is just nearest neighbor but you can also use bilinear for this ... As cubic curve I would use this polynomial.

    The idea behind bi-cubic interpolation is easy. compute point corresponding to parameter u on 4 horizontal contours. That will give you 4 control points for the final cubic interpolation in vertical direction and v as parameter. Resulting coordinate is your source pixel position.

For more info see:

In case you do not have a grid use any info that can be used as one. For example lines of text can be considered a contour for this ...

这篇关于页面图片如何被整理成看起来好像被扫描了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆