Compute Mean Value of Train and Test Dataset of Caltech-256 dataset in matlab code

 

Compute Mean Value of Train and Test Dataset of Caltech-256 dataset in matlab code 

 

clc;
imPath = '/home/wangxiao/Downloads/Link to caltech_256_dataset/image_/ori_total_im_/';
imageFiles = dir(imPath);

train_txtFile = '/home/wangxiao/Downloads/caltech256_whole_data_/train_caltech_label.txt';
test_txtFile = '/home/wangxiao/Downloads/caltech256_whole_data_/test_caltech_label.txt';
train_list = importdata(train_txtFile);
test_list = importdata(test_txtFile);

train_R = 0; train_G = 0; train_B = 0;
test_R = 0; test_G = 0; test_B = 0;

for i = 1:size(train_list, 1)
train_im_name = train_list.textdata{i, 1} ;
train_image = imread([imPath, train_im_name]);
train_image = double(train_image);

train_R = train_R + mean(mean( train_image(:, :, 1) ));
train_G = train_G +mean(mean( train_image(:, :, 2) ));
train_B = train_B + mean(mean( train_image(:, :, 3) ));

end

for i = 1:size(test_list, 1)
test_im_name = test_list.textdata{i, 1} ;
test_image = imread([imPath, test_im_name]);
% imshow(test_image);
test_image = double(test_image);

test_R = test_R +mean(mean( test_image(:, :, 1) )) ;
test_G = test_G +mean(mean( test_image(:, :, 2) )) ;
test_B = test_B +mean(mean( test_image(:, :, 3) )) ;

end

 

mean_train_R = train_R / size(train_list, 1);
mean_train_G = train_G / size(train_list, 1);
mean_train_B = train_B / size(train_list, 1);

mean_test_R = test_R / size(test_list, 1);
mean_test_G = test_G / size(test_list, 1);
mean_test_B = test_B / size(test_list, 1);

 

 

 

 

 

 

 

posted @ 2016-05-13 10:00  AHU-WangXiao  阅读(486)  评论(0编辑  收藏  举报