How to calculate Nearest neighbor of Image after applying PCA on Image.

4 次查看(过去 30 天)
Hi all, I am working on yale face data set till now what I have done is below. I am taking only 15 images ( all are different, just for testing) . What steps I have follow are as follows -
  1. apply PCA on an Image
  2. find nerest neighbour of image after applying PCA.
  3. find diagonal matrix
  4. find laplacian matrix
  5. find (Diagonal^-1 * laplacian matrix)
  6. find eigen value.
Only issue am facing is how to find nearest neighbour of image after PCA.
D = 'Happy';
S = dir(fullfile(D,'*.jpg')); % pattern to match filenames.
%%
for n=1:numel(S)
im = imread(S(n).name); %read image
[rows, columns, numberOfColorBands] = size(im);
im = im2double(rgb2gray(im)); % convert image to gray scale and then to double precision
[r,c] = size(im); % get number of rows and columns in image
I(:,n) = im(:); % convert image to vector and store as column in matrix I
end
%%
% I=imread('subject01 happy.jpg');
% b=double(rgb2gray(I));
%%
[rows, columns, numberOfColorBands] = size(I);
X = double(reshape(I, rows * columns,1));
%%
coeff = pca(I);
%%
Itransformed = I * coeff;
%%
uyt={};
for i=1:15
pca1Image = reshape(Itransformed(:,1), rows, columns);
uyt{i}=pca1Image;
end
After this( Itransformed = I * coeff) I have a matrix of (50176x15 double) and a structure uyt with 224*224 image regenrated .
Now I have to calculate nearest neighbour of image after this PCA image . For finding nearest neighbour we need a query data in knn function but what will the quest data for image in PCA matrix.
Or I may be wrong in my approch .
Please help me .

采纳的回答

KALYAN ACHARJYA
KALYAN ACHARJYA 2019-8-21
编辑:KALYAN ACHARJYA 2019-8-21
"Only issue am facing is how to find nearest neighbour of image after PCA"
Please consider above ia a portion of the entire image, when you considering nearest neighbours,
  1. Red is the centre pixels.
  2. If 4 Connectivity: You have consider yellow pixels only.
  3. If 8 Connectivity: You have consider yellow and green pixels both.
Suppose you are considering 4 connectivity, then the pixels are [5 5 10 2], is a one dimentional vector. Now you can do any sort of matimatical operation in this vector, say, mean,median, deviation, multiplication with any other vector, or addition....The mathematical operation is based on target application.
When you can culated any operation, the value of the centre pixel is replaced by result from the operation......
.....and the process is going on for entire image (mask processing / Batch Processing/Convolution). The next iterartion 9 will be centre pixel and 5 20 10 are LHS neighbours.
Now you have to decide, what you want >> nearest neighbour of image,
or is it any single pixel?
Hope it gives you the clarification!

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Dimensionality Reduction and Feature Extraction 的更多信息

产品


版本

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by