imread with new name

2 vues (au cours des 30 derniers jours)
Jessica Yorzinski
Jessica Yorzinski le 22 Août 2022
Commenté : Jessica Yorzinski le 25 Août 2022
I want to pre-load images before displaying them later. In order to do so, I need to save them with different names. Here is the code to loop through the folder of images:
for i=1:50
Names=imageNames{i};
Number=num2str(i);
NewName=strcat('ImageID_','Number);
NewName=imread(Names);
end;
But, I'd like the images to be saved as a variable string (e.g., "ImageID_1", "ImageID_2", etc.) but it is instead saving the image as "NewName"
  1 commentaire
Stephen23
Stephen23 le 22 Août 2022
"I'd like the images to be saved as a variable string (e.g., "ImageID_1", "ImageID_2", etc.)"
And force yourself into writing slow, complex, inefficent code that you would need to access those variable names:
The simple, efficient, recommended solution is to use indexing into one array (e.g. a cell array), just as the documentation shows:

Connectez-vous pour commenter.

Réponse acceptée

Voss
Voss le 22 Août 2022
Instead of 50 different variables named ImageID_1, ImageID_2, etc., how about one variable (a cell array) that contains all 50 images?
n_images = numel(imageNames);
Images = cell(1,n_images);
for ii = 1:n_images
Images{ii} = imread(imageNames{ii});
end
Then you can access any image by indexing into Images. For example, to get the 10th image:
Images{10}
  1 commentaire
Jessica Yorzinski
Jessica Yorzinski le 25 Août 2022
This worked-- thanks!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Image Processing and Computer Vision dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by