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

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.

 Accepted Answer

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!

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Asked:

En
on 18 Jul 2024

Answered:

En
on 18 Jul 2024

Community Treasure Hunt

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

Start Hunting!