0

I'm sure something for this already exists so I figure why reinvent the wheel.

Does anyone know of an algorithm that will iterate through pixels in an image from the top left towards the bottom right.

So first it will check: (0, 0)

Then: (1, 0), (1, 1), (0, 1)

Then (2, 0), (2, 1), (2, 2), (1, 2), (0, 2)

... and so on....

Looking for the most efficient algorithm for this problem.

Thanks.

4

1 回答 1

3

您似乎想以这种方式进行迭代:

1 4 9
  ↑ ↑
2→3 8
    ↑
5→6→7

...

这只是一个 for 循环:

for radius in range(squareImage.width):
    for col in range(radius):
        yield (radius, col)
    for row in range(radius):
        yield (radius-row, radius)
    yield (0, radius)

效率在这里不是问题。不可能比线性像素数(像这样)做得更好,因为您必须访问每个像素。

于 2012-05-04T23:11:51.973 回答