2

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.

Dima
39.6k14 gold badges80 silver badges116 bronze badges
asked Jun 17, 2010 at 15:55

2 Answers 2

3

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
answered Jun 17, 2010 at 16:01
Sign up to request clarification or add additional context in comments.

Comments

3

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
answered Jun 17, 2010 at 18:43

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.