Borrar filtros
Borrar filtros

How to read input images from the folder sequentially

2 visualizaciones (últimos 30 días)
S.A
S.A el 9 de Abr. de 2018
Comentada: Jan el 19 de Mzo. de 2022
Hello, In my work I'm giving input as a folder of facial photos which consists of 10 images. The output enhanced images are getting stored in separate folder But the problem is, it is not getting stored in the same order as that of the images passed through input folder. The images are read randomly.

Respuestas (2)

KALYAN ACHARJYA
KALYAN ACHARJYA el 9 de Abr. de 2018
Editada: KALYAN ACHARJYA el 9 de Abr. de 2018
% Save all images name in a sequence manner before doing the operation
% names for example im1,im2,im3...
%Save the folder of images in the current directory
path_directory='folder_name'; % 'Folder name'
original_files=dir([path_directory '/*.jpg']);
for k=1:length(original_files)
filename=[path_directory '/' original_files(k).name];
image_orginal=imread(filename);
% Image read is done
%%Image Operation as per your work
end
  5 comentarios
Halee Scott
Halee Scott el 18 de Mzo. de 2022
Where would fullfile be used in the script then? Sorry I am new to coding and adapting this to create a for loop that changes file types (.oib to .tiff) and saves the new files in a different folder.

Iniciar sesión para comentar.


Stephen23
Stephen23 el 15 de Ag. de 2018
Editada: Stephen23 el 23 de Abr. de 2020
Presumably the filenames have numbers in them, and you are getting them listed not in numeric order...One solution is to download my FEX submission natsortfiles, which was written to solve that exact problem:
There are plenty of examples in the Mfile, in the online description, and in the HTML documentation, so you should not have any problems using it. You will probably want something like this:
D = 'path of the folder where the files are';
S = dir(fullfile(D,'*.txt'));
F = natsortfiles({S.name});
for k = 1:numel(F)
im = imread(fullfile(D,F{k}))
...
end
  5 comentarios
Manuella Juwita
Manuella Juwita el 29 de Jun. de 2020
Hello,
I want to ask, how to use natsortfiles to sort alphanumerically overlaying plots in one figure? I find it difficult to match one plot to another because they have different directories and names.
Jan
Jan el 19 de Mzo. de 2022
@Manuella Juwita: What are "alphanumerically overlaying plots in one figure"? Plots do not have directories.

Iniciar sesión para comentar.

Categorías

Más información sobre File Operations en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by