Skip to content

Commit

Permalink
matlabファイル整理
Browse files Browse the repository at this point in the history
  • Loading branch information
reo11 committed Jan 13, 2019
1 parent c7b1157 commit 2ddfb2f
Show file tree
Hide file tree
Showing 26 changed files with 99 additions and 99 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 12 additions & 0 deletions mFile/New Folder/dbgen.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
faceClass = 20;
number = 10;

path = '../facedata/DB/jpeg/'

for i=1:faceClass
for j=1:number
str = strcat(path,num2str(number*(i-1)+j-1, '%03d'),'.jpg');
img = imread(str);
DB(:,:,number*(i-1)+j) = img;
end
end
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
number = 10;
r=30;

%DBの作成
for i=1:faceClass
for j=1:number
normDB(:,:,j,i) = double(DB(:,:,number*(i-1)+j))./norm(double(DB(:,:,number*(i-1)+j)));
Expand All @@ -15,24 +14,21 @@
end
end
end

%各クラスで部分空間を求める
[picX, picY] = size(DB(:,:,1));
W = zeros(picX*picY,100,faceClass);
W=zeros(picX*picY,100,faceClass);
for i=1:faceClass
X = zeros(picX*picY, 1);
for j=1:number
X = vertcat(X,arrangedDB(:,(i-1)+j)) %行列の列方向の連結
X = vertcat(X,arrangedDB(:,(i-1)+j))
end
C = X*X.'; %自己相関行列を計算
% eigenvalues 窶銀?and eigenvectors of C
[eig_vec, eig_val] = eig(C); %固有ベクトル、固有値を計算
[value index] = sort(-diag(eig_val)); %固有値のソート
W(:,:,j+1) = eig_vec(:,index(1:100)); %固有値の大きい上位100本に対応する固有ベクトルを格納
C = X*X.';
% eigenvalues ​​and eigenvectors of C
[eig_vec, eig_val]=eig(C);
[value index]=sort(-diag(eig_val));
W(:,:,j+1)=eig_vec(:,index(1:100));
fprintf('Face Class %d ... OK\n',i);
end

%QueryのDBの作成
querySize = size(Query)
for j=1:querySize(3)
normQuery(:,:,j,i) = double(Query(:,:,j))./norm(double(Query(:,:,j)));
Expand All @@ -45,8 +41,8 @@
end

for i = 1 : querySize(3)
for j = 0 : 9, S(j+1)=sum((transpose(W(:,1:r,j+1))*arrangedQuery(:,i)).^2);, end %部分空間法による計算
[value index]=max(S);%各列の最大値(value)とそれがある行(index)
for j = 0 : 9, S(j+1)=sum((transpose(W(:,1:r,j+1))*arrangedQuery(:,i)).^2);, end
[value index]=max(S);
CONF(test_label(i)+1,index)=CONF(test_label(i)+1,index)+1;
fprintf('test data %d\n',i);
end
Expand Down
12 changes: 12 additions & 0 deletions mFile/New Folder/matching.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function number = matching(DB, X)
dblX = double(X);
for i=1:200
A = DB(:,:,i);
dblA = double(A);
D = (dblX - dblA).^2;
distance(i) = sum(sum(D));
end
[minimum, index] = min(distance);
number = ceil(index/10);
% sprintf('X is Person %d.',number)
end
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
45 changes: 36 additions & 9 deletions mFile/dbgen.m
Original file line number Diff line number Diff line change
@@ -1,12 +1,39 @@
faceClass = 20;
number = 10;
% MATLAB上にDBを実装するためのスクリプトMファイル
clc
clear
c = 20; % クラス総数
n = 10; % 1クラス当たりの学習パターン数

path = '../facedata/DB/jpeg/'
% DBの画像ファイル場所
path = 'M:\project\dataset2\DB\jpeg\';

for i=1:faceClass
for j=1:number
str = strcat(path,num2str(number*(i-1)+j-1, '%03d'),'.jpg');
img = imread(str);
DB(:,:,number*(i-1)+j) = img;
end
%H = fspecial('disk', 20); %フィルターの作成(ぼかし)
for i=1:c
for j=1:n
str = strcat(path, num2str(n*(i-1)+j-1, '%03d'), '.jpg');
img = imread(str);

%img = edge(img, 'Canny');
%img = imfilter(img, H, 'replicate');

DB(:,:,n*(i-1)+j) = img; % 3次元配列の場合
end
end

%% クエリのDB
%クエリDBの画像場所
Qpath = 'M:\project\dataset2\Query\jpeg\*.jpg';
path = 'M:\project\dataset2\Query\jpeg\';

%Qpathの中身
D = dir(Qpath);

for i=1:length(D)
name = strcat(path, D(i).name);
img = imread(name);

%img = edge(img, 'Canny');
%img = imfilter(img, H, 'replicate');

Query(:,:,i) = img;
end
File renamed without changes.
39 changes: 0 additions & 39 deletions mFile/final/dbgen.m

This file was deleted.

18 changes: 0 additions & 18 deletions mFile/final/matching.m

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
22 changes: 13 additions & 9 deletions mFile/makeSubspaceModel.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
number = 10;
r=30;

%DBの作成
for i=1:faceClass
for j=1:number
normDB(:,:,j,i) = double(DB(:,:,number*(i-1)+j))./norm(double(DB(:,:,number*(i-1)+j)));
Expand All @@ -14,21 +15,24 @@
end
end
end

%各クラスで部分空間を求める
[picX, picY] = size(DB(:,:,1));
W=zeros(picX*picY,100,faceClass);
W = zeros(picX*picY,100,faceClass);
for i=1:faceClass
X = zeros(picX*picY, 1);
for j=1:number
X = vertcat(X,arrangedDB(:,(i-1)+j))
X = vertcat(X,arrangedDB(:,(i-1)+j)) %行列の列方向の連結
end
C = X*X.';
% eigenvalues ​​and eigenvectors of C
[eig_vec, eig_val]=eig(C);
[value index]=sort(-diag(eig_val));
W(:,:,j+1)=eig_vec(:,index(1:100));
C = X*X.'; %自己相関行列を計算
% eigenvalues 窶銀?and eigenvectors of C
[eig_vec, eig_val] = eig(C); %固有ベクトル、固有値を計算
[value index] = sort(-diag(eig_val)); %固有値のソート
W(:,:,j+1) = eig_vec(:,index(1:100)); %固有値の大きい上位100本に対応する固有ベクトルを格納
fprintf('Face Class %d ... OK\n',i);
end

%QueryのDBの作成
querySize = size(Query)
for j=1:querySize(3)
normQuery(:,:,j,i) = double(Query(:,:,j))./norm(double(Query(:,:,j)));
Expand All @@ -41,8 +45,8 @@
end

for i = 1 : querySize(3)
for j = 0 : 9, S(j+1)=sum((transpose(W(:,1:r,j+1))*arrangedQuery(:,i)).^2);, end
[value index]=max(S);
for j = 0 : 9, S(j+1)=sum((transpose(W(:,1:r,j+1))*arrangedQuery(:,i)).^2);, end %部分空間法による計算
[value index]=max(S);%各列の最大値(value)とそれがある行(index)
CONF(test_label(i)+1,index)=CONF(test_label(i)+1,index)+1;
fprintf('test data %d\n',i);
end
Expand Down
28 changes: 17 additions & 11 deletions mFile/matching.m
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
function number = matching(DB, X)
dblX = double(X);
for i=1:200
A = DB(:,:,i);
dblA = double(A);
D = (dblX - dblA).^2;
distance(i) = sum(sum(D));
end
[minimum, index] = min(distance);
number = ceil(index/10);
% sprintf('X is Person %d.',number)
function number = matching(DB,Query,q)
%単純マッチング関数(関数Mファイル)
%クエリ画像XとDBの画像をピクセル毎に比較し、二乗誤差が最も小さい人物を出力する
X = Query(:,:,q);
dblX = double(X);
for i=1:200
A = DB(:,:,i);
dblA = double(A);
D = (dblX-dblA).^2;
distance(i) = sum(sum(D));
end

[minimum, index] = min(distance);

number = ceil(index/10)-1;
%sprintf('X is Person %d.',number)
end

File renamed without changes.
File renamed without changes.

0 comments on commit 2ddfb2f

Please sign in to comment.