python - PIL粘贴图像不模糊

标签 python python-imaging-library

我想使用 PIL 将图像粘贴到单色背景中,但粘贴的照片周围出现一些模糊和噪点,如下所示:

enter image description here

(缩放照片以查看噪音。我认为这是由于抗锯齿造成的)但我想粘贴清晰的边界,如下所示:

enter image description here

我使用此代码进行粘贴:

my_image.convert('RGBA')
background = Image.new("RGBA", (background_size), background_color)
background.paste( my_image, (coordinates), my_image )
background.save("result.jpg")

粘贴边界清晰时应该怎么做? 谢谢。

最佳答案

jpg 是一种有损格式,因此它可能会模糊图像或添加噪音,以节省内存。请改用 png 等无损格式:

background.save("result.png")

关于python - PIL粘贴图像不模糊,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18538189/

相关文章:

python - 如何对标量矩阵与向量矩阵进行逐元素乘法?

python - 加入列表由多个列表组成,这些列表在 python 中具有相同的值

python - 如何将 Armadillo 矩阵转换为立方体?

python - Python 中耗时的 REST 服务出错

python - 将图像从 8 位转换为 10 位的问题

python - 在python中将大图像文件读取为数组

docker - 在 Docker 中使用 Pillow

python - 将python中生成的图像存储到Django数据库(MySQL)

python - Django 图片上传和调整大小

python - 将图像旋转 90° 时,如何阻止 PIL 交换高度/宽度?