image - 使用 Matlab 进行男性/女性分类 - 关于寻找平均图像

标签 image matlab classification mean

我正在开发一个关于使用 matlab 进行模式(男性/女性)分类的项目。我有一个问题,请帮助我。

我的程序应该找到数据集的平均图像。第一个数据集是女性,第二个数据集是男性。因此,第一个平均图像必须看起来像一个女人,第二个图像必须看起来像一个男人。我有不同的数据集,它们都具有 jpeg 格式。我正在为我的程序尝试不同的数据集来检查它是否正常工作,但是当我使用不同的数据集时,我无法始终看到真正的平均图像,例如:

它们是来自数据集的平均图像:

enter image description here

但是当我使用另一个数据集时,我的平均图像是这样的,它们没有任何意义,我的意思是它们看起来不像脸:

enter image description here

这可能是什么原因?我应该使用不同的数据集。请帮忙。 `

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)

最佳答案

您可以使用 3D 矩阵来存储图像。我还清理了一些代码。未测试。

filenamesA = dir(fullfile(pathfora, '*.jpg'));
Train_NumberA = numel(filenamesA);

imagesA = [];

for k = 1:Train_NumberA
    imgA = imread(strcat(pathfora, '\', int2str(k), 'b', '.jpg'));
    imgA = rgb2gray(imgA);

    imagesA = cat(3, imagesA, imgA);
end

double 命令移出循环。

imagesA = double(imagesA);

计算 imagesA 矩阵第 3 维的平均值以获得平均 2D 图像。

meanimage_A = mean(imagesA, 3);

转换为灰度图像。

meanimgA = mat2gray(meanimage_A);

我认为这里不需要rot90...

figure(1);
imshow(meanimgA, 3);

关于image - 使用 Matlab 进行男性/女性分类 - 关于寻找平均图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10587443/

相关文章:

opencv - 使用隐马尔可夫模型进行手形分析

R:调整 SVM 参数 - {e1071} 包中的 class.weights

python - 如何在 scikit-learn 中使用 tf idf 计算函数?

ios - iOS中的图像裁剪问题

php - 添加黑条以创建 16x9 图像

java - Java中读取和处理.mat文件(邻接矩阵)

matlab - 将8位音频信号转换为较低的编码

c++ - OpenCV 3.0 中的主动轮廓模型

javascript - 如何用javascript做到这一点?它就像一个开关,但我似乎没有找到开关功能

c++ - 将 C 中的图像加载到 unsigned char