【发布时间】:2012-05-22 04:19:27
【问题描述】:
我正在做一个关于使用 matlab 进行模式(男性/女性)分类的项目。我有一个问题,我需要你的帮助。
我的程序应该找到数据集的平均图像。第一个数据集是女性,第二个数据集是男性。所以第一个平均图像必须看起来像一个女人,第二个是一个男人。我有不同的数据集,它们都具有 jpeg 格式。我正在为我的程序尝试不同的数据集以检查它是否正常工作,但是当我使用不同的数据集时,我始终无法看到真实的平均图像,例如:
它们是来自数据集的平均图像:
但是当我使用另一个数据集时,我的平均图像是这样的,它们没有任何意义,我的意思是它们看起来不像脸:
这可能是什么原因?我应该使用不同的数据集。请帮忙。 `
filenamesA = dir(fullfile(pathfora, '*.jpg'));
Train_NumberA = numel(filenamesA);
%%%%%%%%%%%%%%%%%%%% Finding Image Vectors for A
imagesA= [];
for k = 1 : Train_NumberA
str = int2str(k);
str= strcat(str);
str = strcat('\',str,'b','.jpg');
str = strcat(pathfora,str);
imgA = imread(str);
imgA = rgb2gray(imgA);
[irowA icolA] = size(imgA);
tempA = reshape(imgA',irowA*icolA,1); % Reshaping 2D images into 1D image vectors
imagesA = [imagesA tempA]; % 'imagesA' grows after each turn
imagesA=double(imagesA);
end`
`%%%%%%%%%%%%%%%%%%%%%%%% Calculate the MEAN IMAGE VECTOR for A
mean_vectorA= mean(imagesA,2); % Computing the average vector m = (1/P)*sum(Tj's) (j = 1 : P)
mean_imageA= reshape(mean_vectorA,irowA,icolA); % Average matrix of training set A
meanimgA=mat2gray(mean_imageA);
figure(1);
imshow(rot90(meanimgA,3));`
-------------------------------------And same for dataset B (male)
【问题讨论】:
-
不可能说,因为你没有显示任何代码。
-
是的,你是对的,我现在已经展示了。
-
好的,你应该先自己调试一下。首先,您需要简化代码(例如,与创建文件名有关的所有事情都无关紧要)。然后,您应该检查中间变量,以确保它们符合您的预期。
-
我是 matlab 的新手。所以我需要你的意思更清楚。例如,为什么创建文件名是无关紧要的?什么是正确的方法?
-
str = strcat(str);的作用是什么?为什么不只是str = strcat(pathfora, '\', int2str(k), 'b.jpg');或sprintf('%s\%db.jpg', pathfora, k)?
标签: image matlab classification mean