Read and save multiple PNG images after inserting text on them (This text is the filename itself without any extensions)
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Akira Agata
2018 年 10 月 10 日
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
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Text Analytics Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!