how to read images form folders directory

2 visualizaciones (últimos 30 días)
Tulips
Tulips el 20 de Oct. de 2012
Comentada: Image Analyst el 21 de Abr. de 2016
hi, how to reasd images , say '*.png' images from folders in directory and produce output same as folder name.

Respuesta aceptada

Matt J
Matt J el 20 de Oct. de 2012
So each sub-folder contains only 1 file (a .png file)?
The code below puts the results in the structure Images.foldername
D = dir(directory_name);
D(1:2)=[];
D(~D.isdir)=[];
for i=1:length(D)
foldername=D(i).name;
pth=[directory_name pathsep foldername]);
files=dir(pth);
files(files.isdir)=[];
for j=1:length(files)
[p,n,e]=fileparts(files.name(j));
if strcmp(e,'.png')
Images.(foldername)=imread(files.name(j));
break;
end
end
end
  11 comentarios
Tulips
Tulips el 22 de Oct. de 2012
In a folder there have 24 images which in *.png extension with each of them consists of 20x20 dimensions. for the recognition part, it recognize, like this Input is apple.png The output is 2.png '2.png' is referred to as one of 24 images that have been recognized. The problem is how can I create folders and subfolders that represents different type of fruit that each of them consist of 5 images inside it. So that, when the sytem recoznize (2.png) it shows that the output is referred to apple from the folder of different fruits I created. Anyone?
Image Analyst
Image Analyst el 22 de Oct. de 2012
See comment in my answer.

Iniciar sesión para comentar.

Más respuestas (2)

Image Analyst
Image Analyst el 22 de Oct. de 2012
Editada: Image Analyst el 22 de Oct. de 2012
You may be interested in the FAQ http://matlab.wikia.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F which has several code examples.
OK, that's totally different. You need a function called "ClassifyFruit" that takes an image and then returns the class number 1-5 depending on whether it's an apple, banana, peach, etc. Then use sprintf() to create the folder name, and mkdir to create it if you don't have it. Then create the full filename with sprintf and use imwrite to copy the image to that folder.
  1 comentario
Tulips
Tulips el 29 de Oct. de 2012
how to create a ClassifyFruit function.can u give hint or idea on this?

Iniciar sesión para comentar.


sawsan mahmood
sawsan mahmood el 21 de Abr. de 2016
hi , please I need help I have database of iris segmentation a folder contain 241 subfolders (named from 1 to 241) each of them contain 5 images (named from Img_1_1_1 to Img_1_1_5)and second subfolder's image named (Img_2_1_1 to Img_2_1_5) and so on ,please I need code to read the first image only from each subfolder and make same processing to them thanks
  1 comentario
Image Analyst
Image Analyst el 21 de Abr. de 2016
See my attached code. Change the file pattern to Img_1_1_1 and it will work.

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by