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

4 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

En
En il 18 Lug 2024
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!

Più risposte (0)

Categorie

Scopri di più su Communications Toolbox in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by