Hi everyone,
I'm trying to read a picture file and get the size of the picture and print it to txt file. I want it like:
size img1.png
2448 3264 3
size img2.png
2458 3464 3
........
But i don't know how to do it, please help me with the code.
Here my code:
for k = 1: length(jpgFiles)
baseFileName = jpgFiles(k).name;
fullFileName = fullfile(Folder, baseFileName);
fprintf(1, 'Reading %s\n', fullFileName);
imageArray = imread(fullFileName);
E=size(imageArray);
fid=fopen('Result.txt','a');
fprintf(fid,'%.d\n',E);
fclose(fid);
Thank you very much!

 Respuesta aceptada

Jan
Jan el 30 de Ag. de 2021
Editada: Jan el 30 de Ag. de 2021
fprintf(fid,'%d %d %d\n', E);
It is much faster to open the file once only:
fid = fopen('Result.txt','a');
for k = 1:length(jpgFiles)
baseFileName = jpgFiles(k).name;
fullFileName = fullfile(Folder, baseFileName);
fprintf(1, 'Reading %s\n', fullFileName);
imageArray = imread(fullFileName);
E = size(imageArray)
fprintf(fid, 'size %s\n', baseFileName); % [EDITED]
fprintf(fid, '%d %d %d\n', E);
end
fclose(fid);

3 comentarios

Hong Thien Dang
Hong Thien Dang el 30 de Ag. de 2021
That nice! But do you know how to put the title for each data like this:
size img1.png
2448 3264 3
Thanks!!!
Hong Thien Dang
Hong Thien Dang el 30 de Ag. de 2021
Jan
Jan el 30 de Ag. de 2021
I've expanded the code in my answer.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Startup and Shutdown en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 30 de Ag. de 2021

Comentada:

Jan
el 30 de Ag. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by