How do I save a series of Output images in a folder (that is inside a for loop)?

3 vues (au cours des 30 derniers jours)
Jason Prakash
Jason Prakash le 10 Déc 2021
imshow(img)
hold on
plot([xLeftY, xRightY], [yLeftY, yRightY], 'LineWidth',5,'Color','Yellow');
plot([xLeftW, xRightW], [yLeftW, yRightW], 'LineWidth',5,'Color','White');
hold off
The above code shows a series of images that is inside a for loop and plots lines on the image
I need to save the output images (251 images)

Réponses (3)

Image Analyst
Image Analyst le 10 Déc 2021
Use sprintf() to create a filename, like
folder = 'C:/Jasons images'; % Whatever...
for loopCounter = 1 : whatever...
filename = fullfile(folder, sprintf('Image %2.2d', loopCounter));
% Plot to an axes... Then save to a disk file with exportgraphics():
exportgraphics(gca, filename);
end

M.B
M.B le 10 Déc 2021

yanqi liu
yanqi liu le 10 Déc 2021
for i = 1:251
imshow(img)
hold on
plot([xLeftY, xRightY], [yLeftY, yRightY], 'LineWidth',5,'Color','Yellow');
plot([xLeftW, xRightW], [yLeftW, yRightW], 'LineWidth',5,'Color','White');
hold off
% get figure snap and save to png file
f = getframe(gcf);
f = frame2im(f);
if ~exist('./fd', 'dir')
mkdir('./fd');
end
imwrite(f, sprintf('./fd/%03d.png', i));
end

Catégories

En savoir plus sur Image Processing Toolbox dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by