gpt4 book ai didi

python - 在 Python 中旋转图像 - 提高质量 - Scipy

转载 作者:太空宇宙 更新时间:2023-11-04 06:02:53 25 4
gpt4 key购买 nike

正如标题所说,我正在尝试使用 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):

enter image description here

这些是我得到的一些输出 (128x128):

enter image description here enter image description here

如您所见,边缘非常糟糕,这对于我必须做的事情来说是 Not Acceptable 。我想知道为什么会发生这种情况以及是否有办法摆脱它。

提前谢谢你。

最佳答案

好的,我能够使用参数解决这个问题:

order : int, optional

The order of the spline interpolation, default is 3. The order has to be in the range 0-5.

enter image description here

感谢您的宝贵时间。 (:

关于python - 在 Python 中旋转图像 - 提高质量 - Scipy,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23830239/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com