How to convert image file name "1.jpg" into a string or # in a list, list= [1]
5 views (last 30 days)
Show older comments
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
0 Comments
Answers (1)
Mathieu NOE
on 9 Nov 2020
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
0 Comments
See Also
Categories
Find more on File Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!