Reading images in a folder

Loading files from a directory is a common use case. This is done by identifying a list of files in a directory, filtering the necessary files, and then executing a set of operations for each and every one of them. 

We will be using the sample-images folder from the GitHub repository. You are required to have a functioning project folder when running the following example:

using Images

directory_path
= "sample-images";
directory_files = readdir(directory_path);
directory_images = filter(x -> ismatch(r"\.(jpg|png|gif){1}$"i, x), directory_files);

for
image_name in directory_images
image_path = joinpath(directory_path, image_name);
image = load(image_path);
# other operations
end

This example introduces a number of new functions and techniques, which are explained as follows:

Please be aware that readdir returns filenames. This is the reason for us using joinpath, which joins components into a full path.