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

1 visualización (últimos 30 días)
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 .

Respuesta aceptada

KALYAN ACHARJYA
KALYAN ACHARJYA el 21 de Ag. de 2019
Editada: KALYAN ACHARJYA el 21 de Ag. de 2019
"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!

Más respuestas (0)

Categorías

Más información sobre Dimensionality Reduction and Feature Extraction en Help Center y File Exchange.

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by