How to loop through a folder and convert all the tiff to png?

7 次查看(过去 30 天)
So I have a folder full of tiff images, and I want to convert all of them into png. How can I acheive this? I imagine that I need to use a for loop to go through every single image, but I am not sure about the converting part.
Excuse me if this is a simple question, I am quite a rookie of Matlab and I have tried searching online but nothing works.

采纳的回答

En
En 2024-7-18
Ok I figured out by myself through this forum soon after I make the post lol
For any beginner who is wondering, here is what I have:
myDir = uigetdir
myFiles = dir(fullfile(myDir,'*.tiff'));
outputDirectory = 'C:\Users\Desktop\your folder';
mkdir(outputDirectory);
for k = 1:length(myFiles)
baseFileName = myFiles(k).name;
fullFileName = fullfile(myDir, baseFileName);
imageData = imread(fullFileName);
pngFileName =sprintf('pngFrame_%03d.png', k);
pngFilePath = fullfile(outputDirectory, pngFileName);
imwrite(imageData, pngFilePath);
end
For the experts, please let me know if there is a more efficient way to do it. Thank you so much!

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Communications Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by