MATLAB: Reading different images in a folder when they have similar extensions

directoryMATLABreading similar file names seperatelysimilar file names

Hi,
Let's say I have 6 images in a folder. Three images are named SOU_123_001.tif , SOU_123_002.tif, SOU_123_003.tif, S and the other three images are labelled SOU_123_001_bin.tif, SOU_123_002_bin.tif, SOU_123_003_bin.tif. So the difference between the two sets of images files is the bin in the file name, I am able to use bin to specify only the bin images… code below
image_folder_binary = 'SAME_PATH_WITH_BOTH_FILE_TYPES';
filenames_bin = dir(fullfile(image_folder_binary, '*bin.tif')); % read all images with a sppecified extention, its tif in our case
binary_images = numel(filenames_bin);
I am not sure how to specify the non bin tif images.
Any help?

Best Answer

Hi,
You can list the total number of files and subtract the '_bin.tif' files from them.
This can try this workaround.
clc;
clear all;
image_folder_binary = 'SAME_PATH_WITH_BOTH_FILE_TYPES';
filenames_bin = dir(fullfile(image_folder_binary,'*bin.tif'));
filenames_bin_2 = dir(fullfile(image_folder_binary,'*.tif'));
x = {filenames_bin.name}
y = {filenames_bin_2.name}
C = setdiff(y,x)
non_binary_images = numel(C)
binary_images = numel(x)