"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,
- Red is the centre pixels.
- If 4 Connectivity: You have consider yellow pixels only.
- 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!