How to save images from for loop to use for machine learning algorithm?

2 visualizaciones (últimos 30 días)
I have a for loop that generates a different image each time it loops.
I want to save each of these images to input them into a machine learning algorithm (without overriding the images). I know that I would use "imagedatastore" but am confused on how to use it.
Also, once I have my machine learning algorithm, how would I call these stored images into it?
Here's an example of my code:
for i=1:20
volume=randi([2 10], 1,1)
location=randi([10 100], 1, 1)
image=imagegenerator(volume,location)
end

Respuestas (1)

Subhadeep Koley
Subhadeep Koley el 6 de Nov. de 2020
imageDatastore can only create an image datastore from the collection of image data specified by their location. However, you're generating images using the custom imagegenerator function. In your case, saving them in a cell array might help. Refer the code below.
% Define empty cell array
imageStack = cell(1, 20);
% Generate images and save them in the cell array
for idx = 1:20
vol = randi([2 10], 1, 1);
loc = randi([10 100], 1, 1);
imageStack{idx} = imagegenerator(vol, loc); % Here each element of the cell array contains one image
end
  4 comentarios
Subhadeep Koley
Subhadeep Koley el 8 de Nov. de 2020
Editada: Subhadeep Koley el 8 de Nov. de 2020
@Rachel Dawn does the function imagegenerator producing a figure window for each run of the for-loop? If yes then the below code might help
for idx = 1:20
vol = randi([2 10], 1, 1);
loc = randi([10 100], 1, 1);
imagegenerator(vol, loc);
currentFrm = getframe(gcf);
currentImg = frame2im(currentFrm);
imwrite(currentImg, ['img_', num2str(1), '.png'])
end

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by