필터 지우기
필터 지우기

consider preallocating for speed

조회 수: 1 (최근 30일)
chitra s
chitra s 2012년 5월 5일
sir, i worked out the following code, at that time i got the error message as "consider for preallocation of speed "for the variable IMGDB. for this error normally we clear by using cell,zeros,ones method but even though i got error message. i don't know how to clear this error plz help me
function IMGDB = loadimages
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
face_folder = 'face/'; %LOCATION OF FACE IMAGES
non_face_folder = 'non-face/'; %LOCATION OF NON-FACE IMAGES
file_ext = '.png';
out_max = 1; % DESIRED OUTPUT FOR DETECTING A FACE
out_min = 0; % DESIRED OUTPUT FOR NOT DETECTING A FACE
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if exist('imgdb.mat','file')
load imgdb;
else
IMGDB = cell(3,[ ]);
end
fprintf ('Loading Faces ');
folder_content = dir ([face_folder,'*',file_ext]);
nface = size (folder_content,1);
for k=1:nface
string = [face_folder,folder_content(k,1).name];
image = imread(string);
[m n] = size(image);
if (m~=27 || n~=18)
continue;
end
f=0;
for i=1:length(IMGDB)
if strcmp(IMGDB{1,i},string)
f=1;
end
end
if f==1
continue;
end
fprintf ('.');
IM=zeros();
IM {1} = im2vec (image); % ORIGINAL FACE IMAGE
IM {2} = im2vec (fliplr(image)); % MIRROR OF THE FACE
IM {3} = im2vec (circshift(image,1));
IM {4} = im2vec (circshift(image,-1));
IM {5} = im2vec (circshift(image,[0 1]));
IM {6} = im2vec (circshift(image,[0 -1]));
IM {7} = im2vec (circshift(fliplr(image),1));
IM {8} = im2vec (circshift(fliplr(image),-1));
IM {9} = im2vec (circshift(fliplr(image),[0 1]));
IM {10} = im2vec (circshift(fliplr(image),[0 -1]));
IMGDB=zeros(1,10);
for i=1:10
IMGDB {1,end+1}= string;
IMGDB {2,end} = out_max;
IMGDB (3,end) = {IM{i}};
end
end
fprintf ('\nLoading non-faces ');
folder_content = dir ([non_face_folder,'*',file_ext]);
nnface = size (folder_content,1);
for k=1:nnface
string = [non_face_folder,folder_content(k,1).name];
image = imread(string);
[m n] = size(image);
if (m~=27 || n~=18)
continue;
end
f=0;
for i=1:length(IMGDB)
if strcmp(IMGDB{1,i},string)
f=1;
end
end
if f==1
continue;
end
fprintf ('.');
IM {1} = im2vec (image);
IM {2} = im2vec (fliplr(image));
IM {3} = im2vec (flipud(image));
IM {4} = im2vec (flipud(fliplr(image)));
IMGDB=zeros(1,4);
for i=1:4
IMGDB {1,end+1}= string;
IMGDB {2,end} = out_min;
IMGDB (3,end) = {IM{i}};
end
end
fprintf('\n');
save imgdb IMGDB;

답변 (1개)

per isakson
per isakson 2012년 5월 5일
Try replacing
IMGDB = cell(3,[ ]);
by
IMGDB = cell(3,nface);
or something or set
s = warning( 'off', .... );
see the documentation on WARNING

카테고리

Help CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by