Reading different images in a folder when they have similar extensions

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?

 채택된 답변

Sourav Ghai
Sourav Ghai 2019년 10월 23일
편집: Sourav Ghai 2019년 10월 23일
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)

댓글 수: 3

Hi,
This works great but when I go to read the file in, it will still end up reading the bin files.
for j = 1:non_binary_images
original_Images=fullfile(image_folder_binary, filenames_bin_2(j).name) ; % its will specify images names with full path and extension
OG_images{j} = imread(original_Images); % read images
end
I assume its the filenames_bin_2(j).name that will end up reading the images in order of the file number, 001.tif, 001_bin.tif and then 002.tif.
Any idea how to do this? maybe without fullfile?
You can use 'C' instead of 'filenames_bin_2'.
original_Images=fullfile(image_folder_binary, C(j)) ;
This will give you the list of non-bin files in the folder.
Hey, for anyone else reading this... C ends up being a cell array and you can't use full file with a cell array, you either need to change to a character to vector or string scalar. I couldn't figure out how to chage it into a struct, but instead turned it into a string using...
C = string(C)
and it worked!
If anyone knows how to properly convert this into a struct, I would love to know too!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Convert Image Type에 대해 자세히 알아보기

제품

릴리스

R2019a

질문:

2019년 10월 20일

댓글:

2019년 10월 28일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by