【问题标题】:How to iterate over columns of an image?如何遍历图像的列?
【发布时间】:2009-10-12 16:02:37
【问题描述】:

我想像这样转换图像以在 django 中为图片添加效果described here

我决定将其实现为伟大的django-imagekit/photologue 的过程

我对 PIL 的了解不是很好,所以我的问题是

如何在 PIL 中通过 sinus-offset 来设计一列像素?

欢迎任何提示(代码、lins、一般想法)

【问题讨论】:

    标签: django python-imaging-library imagekit django-imagekit photologue


    【解决方案1】:

    这里有一个快速的例子,它应该带你到正确的方向:

    from PIL import Image, ImageOps
    import math
    
    src = Image.open('arched.jpg')
    
    ampl = step = 10
    
    img = ImageOps.expand(src, border=ampl*4, fill='white')
    size = img.size
    
    straight_mesh = {}
    distorted_mesh = {}
    for y in range(size[1]//step-1):
        py = step*(y+1)
        dx = -int(round(ampl*math.sin(py*math.pi/size[1])))
        print dx 
        for x in range(size[0]//step-1):
            px = step*(x+1)
            straight_mesh[x, y] = (px, py)
            distorted_mesh[x, y] = (px+dx, py)
    transform = []
    for x in range(size[0]//step-2):
        for y in range(size[1]//step-2):
            transform.append((
                map(int, straight_mesh[x, y] + straight_mesh[x+1, y+1]),
                map(int, distorted_mesh[x, y] + distorted_mesh[x, y+1] + \
                        distorted_mesh[x+1, y+1] + distorted_mesh[x+1, y])
            ))
    img = img.transform(size, Image.MESH, transform, Image.BICUBIC)
    img = ImageOps.crop(img, border=ampl*2)
    img.save('result.jpg')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-19
      • 2019-11-26
      • 1970-01-01
      • 2013-10-10
      • 2016-07-07
      • 2016-10-30
      • 1970-01-01
      • 2019-12-04
      相关资源
      最近更新 更多