简体   繁体   English

使用希尔伯特曲线分析图像

[英]Analyzing image using Hilbert-curve

I would like to visit each pixel of an image using the "path" of the Hilbert-curve.我想使用希尔伯特曲线的“路径”访问图像的每个像素。 I've found a recursive implementation of the Hilbert-cuve here , but I don't know how to apply this on an image.我发现一个递归实现希尔伯特CUVE的在这里,但我不知道如何在图像上应用此。 Is it important to have a picture which width and height are equal?拥有一张宽度和高度相等的图片重要吗?

No, but make sure the curve is adaptive or is bigger than the image.不,但要确保曲线是自适应的或大于图像。 Adaptive curve is very complicated.自适应曲线非常复杂。

Here is an algorithm that generates a Hilbert-like curve for a non-square array.这是一个为非方形数组生成类希尔伯特曲线的算法。

The idea is to recursively apply a Hilbert-like template but avoid odd sizes when halving the domain dimensions.这个想法是递归地应用类似 Hilbert 的模板,但在将域维度减半时避免奇数大小。 If the dimensions happen to be powers of two, the classic Hilbert curve is generated.如果维度恰好是 2 的幂,则会生成经典的 Hilbert 曲线。

def gilbert2d(x, y, ax, ay, bx, by):
    """
    Generalized Hilbert ('gilbert') space-filling curve for arbitrary-sized
    2D rectangular grids.
    """

    w = abs(ax + ay)
    h = abs(bx + by)

    (dax, day) = (sgn(ax), sgn(ay)) # unit major direction
    (dbx, dby) = (sgn(bx), sgn(by)) # unit orthogonal direction

    if h == 1:
        # trivial row fill
        for i in range(0, w):
            print x, y
            (x, y) = (x + dax, y + day)
        return

    if w == 1:
        # trivial column fill
        for i in range(0, h):
            print x, y
            (x, y) = (x + dbx, y + dby)
        return

    (ax2, ay2) = (ax/2, ay/2)
    (bx2, by2) = (bx/2, by/2)

    w2 = abs(ax2 + ay2)
    h2 = abs(bx2 + by2)

    if 2*w > 3*h:
        if (w2 % 2) and (w > 2):
            # prefer even steps
            (ax2, ay2) = (ax2 + dax, ay2 + day)

        # long case: split in two parts only
        gilbert2d(x, y, ax2, ay2, bx, by)
        gilbert2d(x+ax2, y+ay2, ax-ax2, ay-ay2, bx, by)

    else:
        if (h2 % 2) and (h > 2):
            # prefer even steps
            (bx2, by2) = (bx2 + dbx, by2 + dby)

        # standard case: one step up, one long horizontal, one step down
        gilbert2d(x, y, bx2, by2, ax2, ay2)
        gilbert2d(x+bx2, y+by2, ax, ay, bx-bx2, by-by2)
        gilbert2d(x+(ax-dax)+(bx2-dbx), y+(ay-day)+(by2-dby),
                 -bx2, -by2, -(ax-ax2), -(ay-ay2))

More information, examples, etc., available here: https://github.com/jakubcerveny/gilbert更多信息、示例等,可在此处获得: https : //github.com/jakubcerveny/gilbert

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM