How to open multiple folders for processing?

22 views (last 30 days)
hp
hp on 26 Mar 2018
Commented: Image Analyst on 12 Dec 2020
I need to process images in the folder, and each folder contains many images.. how can I process images which are in multiple folder, which has to be open one at a time, process folder of images and continue to open another folder to process set of images available in it...?like this it should open folders and continue to process until all the folder specified are done...

Answers (3)

Paul Shoemaker
Paul Shoemaker on 26 Mar 2018
Hema,
Since you don't provide more concrete details about your specific circumstances (code, examples, purpose, etc), I will give a fairly broad answer that hopefully points you in the right direction.
Feel free to respond back with more details if the below ideas miss the mark.
Consider using the Matlab "dir" function to scan for files, which you can have run recursively in newer versions of Matlab. Another newer feature you could use is the "datastore" approach. Type help for either dir or datastore and you should get some good info to help with what you need.
Paul Shoemaker
  4 Comments
hp
hp on 31 Mar 2018
Hi Paul, I tried this code but Iam not getting what I wanted.... I have a folder Named Database in which I have other sub-folders , each sub-folder contains s0me 100 images... it should open main folder,in which it gets many folders, open one by one folder and process the images in it...
hp
hp on 3 Apr 2018
Hi Paul... Thanks for your concern... I used Uigetdir to select the required folder...uigetfile for getting all the files of that folder.. but did not get to know how to open folders one after the other in for loop..
Dirname = uigetdir('G:\matlab2013\Crack\bin\DATABASES','Pick a Directory');
dir_in=(strcat(Dirname,('\')));
file_ext = 'jpg';
listing = dir(strcat(dir_in,'*.',file_ext));
file_names = {listing.name};
num_pages = length(file_names);
I guess I can use the similar to the above code to find the total folder in the main folder... thank you

Sign in to comment.


Image Analyst
Image Analyst on 27 Mar 2018
See my attached demo to go into folders and subfolders getting filenames.
  3 Comments
hp
hp on 3 Apr 2018
Hi Paul.. below is the code Iam trying ... to get features of images and store it in an excel sheet.. clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
Dirname = uigetdir('C:\matlab2013\Crack\bin\DATABASES','Pick a Directory');
dir_in=(strcat(Dirname,('\')));
file_ext = 'jpg';
listing = dir(strcat(dir_in,'*.',file_ext));
file_names = {listing.name};
num_pages = length(file_names);
numOfDirs=1;
for k=numOfDirs:numOfDirs
for i = 1:num_pages
fprintf('Processing page No: %d\n', i);
% load the image from the directory
I = double(rgb2gray(imresize((imread(strcat(dir_in,file_names{i}))),[256 256])));
% I = double(rgb2gray(imread(strcat(dir_in,file_names{i}))));
[m n]=size(I);
gf=graycomatrix(I);
glcm=graycoprops(gf);
%--------------
Features=zeros(2,4);
Features(2,:)=struct2array(glcm);
label=Dirname(35:end);
clear workspace
%clear(glcm);
filename='G:\matlab2013\Crack\bin\TESTFILE.xlsx';
xlswrite(filename,Features(2,:),['sheet' num2str(k)],['A' num2str(i) ':' 'D' num2str(i)]);
xlswrite(filename,label,['sheet' num2str(k)],['E' num2str(i)]);//this line for labeling the image that which class it belongs
%--------------------
end
%feature.mat=xlsread(filename); %converting features stored in Excel sheet into matrix i.e. .mat file
%display(feature.mat);
end
hp
hp on 3 Apr 2018
if I try to label the features... which are extracted for rose images ... that code is storing the label " ROSE" as 'R' in one column, 'O' in another column and so on as shown below... How to make it to get in one column that "E1" cell only plz suggest... thank you..

Sign in to comment.


Navyasree  K.S.
Navyasree K.S. on 12 Dec 2020
i need to read the images,they are in differents folders in a same file.the imaages are .jpg.please help me
  1 Comment
Image Analyst
Image Analyst on 12 Dec 2020
You can use imageDatastore(), or use dir('**/*.jpg');
See the FAQ for code samples.
Don't use JPG images for image analysis if you can possibly avoid it. They have bad compression artifacts. Use PNG.

Sign in to comment.

Categories

Find more on Image Processing and Computer Vision in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!