Skip to main content
 首页 » 编程设计

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

2025年05月04日8TianFang

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

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

提前谢谢你。

请您参考如下方法:

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

order : int, optional

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

感谢您的宝贵时间。 (: