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

3 Ansichten (letzte 30 Tage)
En
En am 18 Jul. 2024
Beantwortet: En am 18 Jul. 2024
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.

Akzeptierte Antwort

En
En am 18 Jul. 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!

Weitere Antworten (0)

Kategorien

Mehr zu Communications Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by