如标题所示,我正在尝试使用Scipy包在Python中旋转图像。
我收到一个具有特定尺寸(例如512 x 512)的图像作为输入,我必须对其进行一些旋转并裁剪一定比例。
所以,这是我到目前为止的代码:
for i in range(0, 90, 10):
image_base = Dt.Data(open_image=True, rotation=i)
Dv.DataVisualization.plot_data(image_base, '../Visualizations/ProcessedImages/'+str(i))
def plot_data(data, file_path):
"""
Plot the data
:param data : the data to be plotted
:param file_path : the name of the file
"""
output = Image.fromarray(numpy.uint8(data.data * 255))
output.save(file_path + '.png', 'PNG')
class Data(object):
def __init__(self, open_image=False, rotation=None):
"""
The Data constructor
"""
self.data = misc.imread('../TestImages/board.jpg', flatten=True)
self.data /= 255.0
x, y = self.data.shape
if rotation != 0:
self.data = ndimage.rotate(self.data, rotation, reshape=False)
self.data = self.data[x / 4: - x / 4, y / 4: - y / 4]
这是我的原始图片(256x256):
这些是我得到的一些输出(128x128):
如您所见,边缘非常糟糕,这对于我要做的事情是不可接受的。我想知道为什么会这样,是否有办法摆脱它。
先感谢您。
最佳答案
好的,我能够使用参数解决此问题:
顺序:int,可选
样条插值的顺序(默认为3)。顺序必须在0-5的范围内。
感谢您的时间。 (:
关于python - 用Python旋转图像-提高质量-Scipy,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23830239/