i have a project that can detect a object from picture.it used backpropagation scale conjugate gradient for training. i used 10 component for input. r,g,b, standard deviation, entropy, threshold( Onsu method), glcm that contains contrast, homogeneity,correlation and energy. i manually extract them. i have 100 input. 50 are object, 50 are not object.it's difficult to still maintain manually method. so i want to use loop and array. i use 2 folder for file object and not object. how to extract file in 2 folder? First folder: C:\Documents and Settings\User\My Documents\MATLAB\object second folder:C:\Documents and Settings\User\My Documents\non object
this is my coding. i manually write them until 100. can u help me to group them in array and looping them?
kl=imread('1.jpg');
g=rgb2gray(kl);
rgb=mean(mean(kl));
r1=rgb(:,:,1);
g1=rgb(:,:,2);
b1=rgb(:,:,3);
std1=std2(g);
entropy1=entropy(g);
tres=graythresh(g);
glcm=graycomatrix(g);
F=graycoprops(glcm,{'Contrast','Homogeneity','Correlation','Energy'});
i hope u can give solution. pls help me.
2 Answers 2
If all your files are named 1.jpg, 2.jpg, ..., then you can do the following:
for i = 1:50
fileName = sprintf('%d.jpg', i);
kl = imread(fileName);
... the rest of your code...
end
Comments
If, in addition to looping over the images in each directory using @Dima's solution, you also want to loop over the two directories, you can do the following:
dirNames = {'C:\Documents and Settings\User\My Documents\MATLAB\object','C:\Documents and Settings\User\My Documents\non object'};
for directory = dirNames %# loops directly over the elements of the cell array dirNames
fileList = dir(fullfile(directory{1},'*.jpg')); %# list all jpgs in the directory
for iFile = 1:length(fileList)
%# read the ith file
kl = imread(fullfile(directory{1},fileList(iFile).name));
%# do the calculations here
end
end