Apply changes to all the images in given folder – Using Python PILReadDiscussCoursesPracticeImprove Article ImproveSave Article SaveLike Article LikeGiven a dataset of raw images, which usually need some pre-processing, which one person has to do physically. It is generally a task that requires some repetitive operation to perform for each image. Well, we can easily automate this process using some simple Python code and some libraries with it. So without further adieu, let’s see how to apply changes to all the images in given folder and save it to some destination folder using Python PIL.Let’s install all the required modules –pip3 install pillow pip3 install os-sysWe will be parsing all the images in the folder to apply changes/operations to all of them simultaneously.# Code to apply operations on all the images# present in a folder one by one# operations such as rotating, cropping, from PIL import Imagefrom PIL import ImageFilterimport os def main(): # path of the folder containing the raw images inPath ="E:\\GeeksforGeeks\\images" # path of the folder that will contain the modified image outPath ="E:\\GeeksforGeeks\\images_rotated" for imagePath in os.listdir(inPath): # imagePath contains name of the image inputPath = os.path.join(inPath, imagePath) # inputPath contains the full directory name img = Image.open(inputPath) fullOutPath = os.path.join(outPath, 'invert_'+imagePath) # fullOutPath contains the path of the output # image that needs to be generated img.rotate(90).save(fullOutPath) print(fullOutPath) # Driver Functionif __name__ == '__main__': main()Sample images from the folder –Input :image_sample1Output :invert_image_sample1Last Updated : 21 Nov, 2019Like Article Save Article Please Login to comment...Similar ReadsPython | OCR on All the Images present in a Folder SimultaneouslyHow to compress images using Python and PIL?Loading Images in Tkinter using PILFinding Difference between Images using PILRename a folder of images using TkinterHow to iterate through images in a folder Python?Arithmetic Operations on Images using OpenCV | Set-2 (Bitwise Operations on Binary Images)How to Merge all excel files in a folder using Python?Python - Move all files from subfolders to main folderRemove all empty files within a folder and subfolders in PythonRelated TutorialsOpenAI Python API - Complete GuidePandas AI: The Generative AI Python LibraryPython for Kids - Fun Tutorial to Learn Python ProgrammingData Analysis TutorialFlask Tutorial LikePreviousDifference between Lossy Compression and Lossless CompressionNext How to manipulate the pixel values of an image using Python ?Article Contributed By :Aamankrsharma3amankrsharma3 FollowVote for difficultyEasy Normal Medium Hard ExpertArticle Tags :Image-ProcessingPython-pilPythonPractice Tags :pythonReport Issue