我正在使用某些像素的 Alpha 值来跟踪它们在旋转过程中的位置。我注意到在某些情况下我会丢失设置的 Alpha 值。显示问题的示例代码:
def showAlphas(rotation, img):
imgPixels = img.load()
foundAlpha = False
for w in range(0, img.width):
for h in range(0, img.height):
if imgPixels[w, h][3]==50:
print 'Found at {}, {} in Rotation {}'.format(w, h, rotation)
foundAlpha = True
if not foundAlpha:
print 'Alpha missing from rotation {}'.format(rotation)
img = Image.new('RGBA', (100, 50), color='black')
img.putpixel((10, 10), (255, 0, 0, 50))
for x in range(1, 360, 1):
rotated = img.rotate(x, expand=True)
showAlphas(x, rotated)
示例输出:
Found at 96, 41 in Rotation 194
Found at 96, 41 in Rotation 195
Alpha missing from rotation 196
Found at 98, 41 in Rotation 197
Found at 97, 41 in Rotation 198
Found at 98, 41 in Rotation 198
Alpha missing from rotation 199
Alpha missing from rotation 200
Found at 98, 41 in Rotation 201
Found at 97, 40 in Rotation 202
Found at 98, 40 in Rotation 202
使用 Pillow 5.3.0
我在轮换中做错了什么吗?据我所知, Expand=True 是我需要指定的唯一选项(以确保图像不会在某些方向上被剪裁)?
我不依赖于使用 Pillow,但需要一些东西来跟踪各种调整大小和旋转操作中的特定像素坐标,并认为使用 Pillow 和跟踪 Alpha 值可以做到这一点。我真的不想尝试通过 RGB 值进行跟踪,但担心这可能会遇到同样的问题。还有其他建议吗?
HUWWW
相关分类