Read and save multiple PNG images after inserting text on them (This text is the filename itself without any extensions)
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
I have around 400 PNG images on which I need to insert text. The text that I want to insert is the filename itself without any extension. After that, I want to save those files in a different folder.
The code for writing text on the file is:
I = imread('IRC338H_DTIFB01_pre_ACC.png');
text_str = ['IRC338H_DTIFB01_pre_ACC'];
position = [10,10];
Filename = insertText(I, position, text_str,'Fontsize',18,'TextColor','white');
figure
imshow(Filename)
I wanted help with forming the loop so that all the images in the folder are read, text is inserted and then the images are saved sequentially.
The format of file names is IRC338H_DTIFB01_pre_ACC.png. Where the characters that change are DTIFB01, DTIFB02, and so on. Similarly it the filename either ends with ACC or M1.
Just to make it clear, the file names are in the format:
IRC338H_DTIFB01_pre_ACC; IRC338H_DTIFB01_pre_M1; IRC338H_DTIFB02_pre_ACC; IRC338H_DTIFB02_pre_M1;
and so on.
0 Commenti
Risposta accettata
Akira Agata
il 10 Ott 2018
Assuming your original .png files are stored in 'folder1', the following example can generates images with file name and saves them to 'folder2'.
fileList = dir(fullfile(pwd,'folder1','*.png'));
position = [10,10];
for kk = 1:numel(fileList)
I = imread(fullfile(fileList(kk).folder,fileList(kk).name));
[~,fileName] = fileparts(fileList(kk).name);
I2 = insertText(I,position,fileName,'Fontsize',18,'TextColor','white');
imwrite(I2,fullfile(pwd,'folder2',fileList(kk).name));
end
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Convert Image Type 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!