[英]Fast way to save Image Files Python
I have a folder of 10 000 images and I am iterating one by one in a for loop and every time after processing I am saving the modified image in a file. 我有一个包含10 000张图像的文件夹,并且在for循环中一个接一个地迭代,每次处理后,我都将修改后的图像保存在文件中。 Problem with the execution is it is taking long time to process even 500 images and I see CPU Usage in Windows Task Manager are going up to 80%.
执行的问题是处理500个图像需要花费很长时间,而且我看到Windows Task Manager中的CPU使用率上升了80%。
How to speed up below code? 如何加速以下代码? Anything like save all processed image in memory and write it at single shot?
像将所有处理过的图像保存在内存中并一次性写入一样吗?
from PIL import Image
from resizeimage import resizeimage
for imgnm in range(0, samples):
start = time.time()
filename=filenames[imgnm]
img = Image.open(os.path.join(imagedir,filename))
img=resizeimage.resize_crop(img, [700, 700])
(img.resize((700,700),Image.ANTIALIAS)).save(os.path.join(subdir,filename),quality=40)
img.close()
How to speed up below code?
如何加速以下代码?
Image.BICUBIC
or even Image.BILINEAR
Image.BICUBIC
甚至Image.BILINEAR
resizeimage
and img.resize
. resizeimage
和img.resize
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.