how to fed all the images to an array from a folder and from that array fed one by one image to a function?

function [features]=feature_extractor_2d(im2)
%this function zones the input image and extracts features for each zone.
srcFiles = dir('C:\Users\Omm\Desktop\thesis\multicharacterrec\*.png'); % the folder in which ur images exists
for i = 1 : length(srcFiles)
filename = strcat('C:\Users\Omm\Desktop\thesis\multicharacterrec\',srcFiles(i).name);
im = imread(filename);
%selecting the universe of discourse
im2=discourser(im);
end
this function is replacing all the previous images to a new image and taking last one as a input but i want to get the features of all the image one by one please guide me how to do it in matlab?

6 Comments

Don't use image as the name of your variable. image is the name of a built-in function so you should not use that name. I don't know what "universe of discourse" is, nor do I know what your discourser() function does. Anyway, you get an image from imread(), then do something with with it in discourser() to get a new image, but then what do you mean by the "outputs of all the image"? The image is an image. What do you mean by the output of that image? The image doesn't output anything - it just is.
here by the image output i means the features vectors of the each image
Please do not use image as the name of a variable, as it is the name of the important MATLAB graphics routine to display images.
Remember, even if you can keep it straight in your mind, that other people need to be able to read the code, and they are going to get confused about your use of image as a variable name.
But sir it's already shown in code that we are taking a image inside image variable so that the feature of the image will be return to the function. now i have changed the name of variable please guide me what to do with the code so that it will be able to work as i want it to work. from the code i have learnt that there is a need to make an array so that the images will store one by one to that array and from that array this function will take the inputs and then the output will be shown as the calculated features on the command window of all the images that are in the folder.but the problem is as i am a learner i am unable to make changes in such way.
image = imread(filename);
is still using "image" as the name of a variable.

Sign in to comment.

 Accepted Answer

Also please use fullfile() instead of strcat() to build your names.
projectdir = 'C:\Users\Omm\Desktop\thesis\multicharacterrec';
srcFiles = dir(projectdir, '*.png');
numfiles = length(srcFiles);
outputs = cell(numfiles, 1);
for i = 1 : numfiles
filename = fullfile(projectdir, srcFiles(i).name);
thisimage = imread(filename);
%selecting the universe of discourse
outputs{i} = discourser(thisimage);
end

1 Comment

projectdir = 'C:\Users\Omm\Desktop\thesis\multicharacterrec';
srcFiles = dir(projectdir, '*.png');
numfiles = length(srcFiles);
outputs = cell(numfiles, 1);
saved_images = cell(numfiles, 1);
for i = 1 : numfiles
filename = fullfile(projectdir, srcFiles(i).name);
thisimage = imread(filename);
saved_images{i} = thisimage;
%selecting the universe of discourse
outputs{i} = discourser(thisimage);
end

Sign in to comment.

More Answers (0)

Categories

Find more on Data Import and Analysis 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!