How to convert image file name "1.jpg" into a string or # in a list, list= [1]

5 次查看(过去 30 天)
SIMPLE QUESTION: How to convert a image file name "1.jpg" into a string or # "1"?
Ignore what's below (unless you have the time to answer it), but ^ this is mainly what I need
So, I created images using a function called imagegenerator & data inputs such as "volume" and "location."
I saved each image generated as a # (i.e. 1.jpg, 2.jpg, 3.jpg.....).
I also saved the input data/variables used for each image (volume & location) as files (i.e. 1.jmat, 2.jmat, 3.jmat....)
Then, using machine learning, I clustered the images into three groups and saved each group of images into three separate folders (cluster0, clsuter1, cluster2)
Now, I want to choose one of these folders (i.e. cluster0) and save the image files as variables in a list. So, say that cluster 0 has these images in it: "1.jpg, 23.jpg, and 52.jpg". I want to make a list called imagenumbers= [1, 23, 52]
Then, I want to use these numbers to retrieve the data/variables that match to these numbers (1.jmat, 23.jmat, 52.jmat) so that I can input similar volume & location values through the imagegenerator function & create similar images to 1.jpg, 23.jpg, and 52.jpg.
I'm just not sure how I can save the image files as #s in a list & then use these #s to call in the variables from the matching jmat files (i.e. volume & location stored in 1.jmat, 23.jmat, and 52.jmat) -- one by one in a for loop

回答(1 个)

Mathieu NOE
Mathieu NOE 2020-11-9
hello
my suggestion here - not really tested the mat file loading
files = dir('*.jpg'); % list all jpeg files in current directory
% main loop
for ck = 1:length(files)
Filename = files(ck).name;
H{ck} = imread(Filename);
% plot (just to check)
figure(ck), imagesc(H{ck});
% load mat file
Filename_mat = [Filename(1:length(Filename)-4) '.mat'];
S = load(Filename_mat);
% insert your own code here
end

类别

Help CenterFile Exchange 中查找有关 File Operations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by