How to save images from for loop to use for machine learning algorithm?
조회 수: 4 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (1개)
Subhadeep Koley
2020년 11월 6일
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
Subhadeep Koley
2020년 11월 8일
편집: Subhadeep Koley
2020년 11월 8일
@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
참고 항목
카테고리
Help Center 및 File Exchange에서 Big Data Processing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
