Image 我想为图像更正此代码,需要做什么更改。。?
目前我正在重新编码一张脸,这意味着我必须找到一张我们必须测试的脸是否在训练数据库中。。!所以,我必须决定是还是不是 是表示查找图像,否表示打印数据库中没有图像的消息。我有一个程序,目前这个程序正在正确地查找正确的图像,但即使没有图像,也会显示其他不匹配的图像。。实际上,它不应该打印数据库中的任何图像 那么,怎么办 这里是一个关于这个链接的测试和训练图像数据 我的程序是用不同的四个.m文件编写的,在这里,我们只需要运行第一个代码。。剩下的3个是函数,这里也给出了**Image 我想为图像更正此代码,需要做什么更改。。?,image,matlab,image-processing,Image,Matlab,Image Processing,目前我正在重新编码一张脸,这意味着我必须找到一张我们必须测试的脸是否在训练数据库中。。!所以,我必须决定是还是不是 是表示查找图像,否表示打印数据库中没有图像的消息。我有一个程序,目前这个程序正在正确地查找正确的图像,但即使没有图像,也会显示其他不匹配的图像。。实际上,它不应该打印数据库中的任何图像 那么,怎么办 这里是一个关于这个链接的测试和训练图像数据 我的程序是用不同的四个.m文件编写的,在这里,我们只需要运行第一个代码。。剩下的3个是函数,这里也给出了** clear all c
clear all
clc
close all
TrainDatabasePath = uigetdir('D:\Program Files\MATLAB\R2006a\work', 'Select training database path' );
TestDatabasePath = uigetdir('D:\Program Files\MATLAB\R2006a\work', 'Select test database path');
prompt = {'Enter test image name (a number between 1 to 10):'};
dlg_title = 'Input of PCA-Based Face Recognition System';
num_lines= 1;
def = {'1'};
TestImage = inputdlg(prompt,dlg_title,num_lines,def);
TestImage = strcat(TestDatabasePath,'\',char(TestImage),'.jpg');
im = imread(TestImage);
T = CreateDatabase(TrainDatabasePath);
[m, A, Eigenfaces] = EigenfaceCore(T);
OutputName = Recognition(TestImage, m, A, Eigenfaces);
SelectedImage = strcat(TrainDatabasePath,'\',OutputName);
SelectedImage = imread(SelectedImage);
imshow(im)
title('Test Image');
figure,imshow(SelectedImage);
title('Equivalent Image');
str = strcat('Matched image is : ',OutputName);
disp(str)
function T = CreateDatabase(TrainDatabasePath)
TrainFiles = dir(TrainDatabasePath);
Train_Number = 0;
for i = 1:size(TrainFiles,1)
if
not(strcmp(TrainFiles(i).name,'.')|strcmp(TrainFiles(i).name,'..')|strcmp(TrainFiles(i).name,'Thu mbs.db'))
Train_Number = Train_Number + 1; % Number of all images in the training database
end
end
T = [];
for i = 1 : Train_Number
str = int2str(i);
str = strcat('\',str,'.jpg');
str = strcat(TrainDatabasePath,str);
img = imread(str);
img = rgb2gray(img);
[irow icol] = size(img);
temp = reshape(img',irow*icol,1); % Reshaping 2D images into 1D image vectors
T = [T temp]; % 'T' grows after each turn
end
function [m, A, Eigenfaces] = EigenfaceCore(T)
m = mean(T,2); % Computing the average face image m = (1/P)*sum(Tj's) (j = 1 : P)
Train_Number = size(T,2);
A = [];
for i = 1 : Train_Number
temp = double(T(:,i)) - m;
Ai = Ti - m
A = [A temp]; % Merging all centered images
end
L = A'*A; % L is the surrogate of covariance matrix C=A*A'.
[V D] = eig(L); % Diagonal elements of D are the eigenvalues for both L=A'*A and C=A*A'.
L_eig_vec = [];
for i = 1 : size(V,2)
if( D(i,i)>1 )
L_eig_vec = [L_eig_vec V(:,i)];
end
end
Eigenfaces = A * L_eig_vec; % A: centered image vectors
function OutputName = Recognition(TestImage, m, A, Eigenfaces)
ProjectedImages = [];
Train_Number = size(Eigenfaces,2);
for i = 1 : Train_Number
temp = Eigenfaces'*A(:,i); % Projection of centered images into facespace
ProjectedImages = [ProjectedImages temp];
end
InputImage = imread(TestImage);
temp = InputImage(:,:,1);
[irow icol] = size(temp);
InImage = reshape(temp',irow*icol,1);
Difference = double(InImage)-m; % Centered test image
ProjectedTestImage = Eigenfaces'*Difference; % Test image feature vector
Euc_dist = [];
for i = 1 : Train_Number
q = ProjectedImages(:,i);
temp = ( norm( ProjectedTestImage - q ) )^2;
Euc_dist = [Euc_dist temp];
end
[Euc_dist_min , Recognized_index] = min(Euc_dist);
OutputName = strcat(int2str(Recognized_index),'.jpg');
那么,当没有图像匹配时,如何生成错误质量?目前,您的应用程序似乎找到了最相似的图像(在度量相似性时,您似乎使用了欧几里德距离),并返回它。对于图像是否“匹配”,似乎没有任何概念 定义相似性阈值,然后确定最相似的图像是否符合该阈值。如果返回,则返回,否则显示错误消息