11

Basically I'm trying to be able to rotate images via user interface, however I've noticed that the image quality severely decreases upon each rotation. Does anyone know how to fix that? Also when the image is rotated it crops off parts of the image each time.

here are some pictures of before and after: http://imgur.com/a/QESKs

And here's the code:

def onRotate(self):
    tanTheta = float(hh)/float(ww) 
    theta = math.atan(tanTheta) * 57.2957795 # convert to degrees
    if theta > 0:
        angle = (90 - theta) * -1
        clockwise = True
    elif theta < 0:
        angle = (270 - theta) * -1
        clockwise = False
    else:
        tkMessageBox('Angle not okay', 'Try again!')
    rotated_small = photo_small.rotate(angle) 
    rotated_small.save('small_rotate.jpg')
    self.load_imgfile('small_rotate.jpg')
4

2 回答 2

16
rotated_small = photo_small.rotate(angle, resample=Image.BICUBIC, expand=True)

这告诉它使用它可用的最高质量的插值算法,并扩展图像以包含完整的旋转尺寸而不是裁剪。文档没有说明背景将填充什么颜色。

于 2013-07-23T22:28:55.657 回答
7

图像是像素网格。如果您旋转它(并且角度不是 90 的倍数),则必须将旋转的网格重新匹配到新的非旋转网格以显示图像。在这个过程中,有些损失是无法避免的。

唯一的选择是将未旋转的图像保留在某处并总结多次旋转的角度,并始终从最初的未旋转图像构建旋转图像。

于 2013-07-23T22:29:40.550 回答