With Python 3.7.7, I want to get the list of all the images that don't end with *_mask.tif
.
In the path there are images that end with *.tif
and with *_mask.tif
. But the following code returns all of them.
# Read all the brain images (those that don't end with _mask.tif).
def brain_images_list(path):
if not isinstance(path, str):
raise TypeError('path must be a string')
if not os.path.exists(path):
raise ValueError('path must exist: ', path)
if not os.path.isdir(path):
raise ValueError('path must be a directory: ', path)
# Save current directory.
current_dir = os.getcwd()
# Change current directory to the one we want to look for.
os.chdir(path)
# Get brain images list
brain_images_lst = glob.glob('*.tif')
# Restore directory
os.chdir(current_dir)
return brain_images_lst
How can I do it?