程序波纹管运行得很好,但是在计算矩阵的每一列的平均值并从行中减去它们之后的某个时刻。我确实得到一些NAN值(矩阵补丁的最后600行)我无法弄清问题在哪里。谢谢你的提示。
nPatchSize = 9;
%%
fprintf('Loading data ...')
if(~exist('imagedata.mat','file'))
filePattern = 'C:\File\my_file';
category_list = dir(filePattern);
numbClasses = 0;
numImagesPerScene = 100;
numPatchesPerImage = 20;
patch = nan(15*numImagesPerScene*numPatchesPerImage, nPatchSize*nPatchSize);
counter = 1;
for tempCounter = (1:length(category_list))
if(category_list(tempCounter).isdir)
switch(category_list(tempCounter).name)
case {'.','..'}
otherwise
numbClasses = numbClasses + 1;
imageList = dir(strcat(filePattern,'\', category_list(tempCounter).name));
% for tempCounter1 = (1:length(imageList));
for tempCounter1 = (1:numImagesPerScene);
if(~imageList(tempCounter1).isdir)
imageName = strcat(filePattern,'\', category_list(tempCounter).name, '\', imageList(tempCounter1).name);
myImage = imread(imageName);
if(size(myImage,3)==3)
myImage = rgb2gray(myImage);
end
myImage = double(myImage)/255;
%myImage = imresize (myImage, S);
for temp = 1:numPatchesPerImage
randStaCol = randi([1 size(myImage,1)-nPatchSize+1]);% extracting random patches from image (colum)
randStaRow = randi([1 size(myImage,2)-nPatchSize+1]);% extracting random patches from image (row)
tmp = myImage(randStaCol:randStaCol+nPatchSize-1, randStaRow:randStaRow+nPatchSize-1);
patch(counter, :) = tmp(:)';
counter = counter + 1;
end
%bmTrainXbin = [bmTrainXbin; myImage(:)'];
% label = [label;numbClasses];
end
end
end
end
end
save('imagedata.mat','patch')
else
load('imagedata.mat')
end
fprintf('done\n')
%%
patch = bsxfun(@minus, patch, mean(patch,1));
在检查作为我的最终矩阵的补丁时,它只给出了我的NAN值。