Open/read multiple .tif images from multiple folders on different levels

just_learning

So, the scheme is that I have a folder, inside which there are other folders with .tif images. For instance I have something like that:

folder_1/folder_2/folder_3/image_1.tif
folder_1/folder_2/image_2.tif
folder_1/image_3.tif
folder_1/folder_2/folder_3/image_4.tif

I need to read all the .tif images from all folders. I tried this suggestion: Loading all images using imread from a given folder but it does not work for variable path folders, as my scheme. So, after searching I tried this suggestion: Loading multiple images from multiple folders in python but I get this error:

    raise UnidentifiedImageError(
PIL.UnidentifiedImageError: cannot identify image file(....)

Any idea how to read all .tif images from all folders, which vary in "folder distance" from the initial folder?

slothrop

The glob module helps with this.

from glob import glob
import os.path
parent_dir = "C:\\folder_1"  # Or wherever your parent folder is
all_tif_file_paths = glob(os.path.join(parent_dir, "**", "*.tif"), recursive=True)

The "**" there means 'any number (including zero) of intervening directories', and when you use it, you need to specify recursive=True.

Then you can loop over all_tif_file_paths and read each file in turn.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Insert multiple images from multiple folders in VBA

How to read Images from multiple folders?

Reading images in multiple folders

How to read multiple images from two different folders one by one using python?

How to read multiple images from multiple folders in python

HTML multiple file upload from different folders

Upload Multiple Files From DIfferent Folders

Select multiple fields at different levels

Combining images into video with ffmpeg, but from multiple folders into the same frames

Displaying random images from multiple folders using python

Matlab: Accessing images from multiple folders in single loop

Loading images from different folders

mv multiple files from different folders from specific date

Need help using php to upload multiple images to different folders and store file names in mysql datatbase

Using multiple predicates at different levels in XPath

Multiple APKs or single APK for different API levels?

logback: Two appenders, multiple loggers, different levels

Remove strings of different parts of levels in multiple columns

Names and links to images in multiple folders on Google Drive

Combining multiple images, in many folders in Python

How to setup gitignore to track specific folders/files multiple levels down?

Merging images from different source folders

Rsync from multiple folders to one

Load multiple files from multiple folders in spark

read multiple text files from multiple folders

Multiple Images upload with different titles

Improve the speed of this process of Converting multiple PDF to multiple tif images using GdPicture.NET

How to print multiple PDF files in different folders?

Copy same file to multiple different folders PowerShell