calculating similarity scores between similar and different classes? I have images for 99 person for each person i have 5 images .
i have this function 

[similarity] = ssim(img1, img2, K, window, L);where K,window ,L are previously determined with their values.

now , i need to use this function to measure intra-class similarities and inter-class similarities .

i mean i need to measure the similaity within and outside the class and put the results in 2 matrices , one contains the results of similarities within the same classes , and the other contains the results of similarities among the determined class and all other classes.

i wrote this in matlab :

%%%%for intraclass 

K = [0.05 0.05];
window = ones(8);
L = 100;
img1=imread('E:\matlab\images\0001hv1.bmp');
img2=imread('E:\matlab\images\0001hv2.bmp');
img3=imread('E:\matlab\images\0001hv3.bmp');
img4=imread('E:\matlab\images\0001hv4.bmp');
img5=imread('E:\matlab\images\0001hv5.bmp');
[s1] = ssim(img1, img2, K, window, L);
[s2] = ssim(img1, img3, K, window, L);
[s2] = ssim(img1, img4, K, window, L);
[s3] = ssim(img1, img4, K, window, L);
[s4] = ssim(img1, img5, K, window, L);
intra_class=[s1 s2 s3 s4];
histintra_class=hist(intra_class);
plot(histintra_class);title('intra_class');



%%%%for interclass 


K = [0.05 0.05];
window = ones(8);
L = 100;
img1=imread('E:\matlab\images\0001hv1.bmp');
img2=imread('E:\matlab\images\0002hv1.bmp');
img3=imread('E:\matlab\images\0003hv1.bmp');
img4=imread('E:\matlab\images\0004hv1.bmp');
img5=imread('E:\matlab\images\0005hv1.bmp');
[s1] = ssim(img1, img2, K, window, L);
[s2] = ssim(img1, img3, K, window, L);
[s3] = ssim(img1, img4, K, window, L);
[s4] = ssim(img1, img5, K, window, L);
inter_class=[s1 s2 s3 s4];
histinter_class=hist(inter_class);
plot(histinter_class);title)'interclass');


now how can i implement this on all my images automatically , i mean how can i read all images and finding intra and inter class similarities and get automatically the 2 matrices which are inter class and intra class

regards
From a general perspective, you are trying to take SSIM - which is image difference measure. But it is probably a bad idea if you are looking for measure the intraclass, distance. 

You can look at distance measures like Euclidean distance, Mahalonbis distance (if you have co-variance metrics) or others. 

As a very simple example : To compute Euclidean distance $L_2$, which is computed between the centroid of the Clusters - as $ Distance = \sqrt{(x_a- x_b)^2 + (y_a- y_b)^2 }$

NOTE: here the dimension are NOT image dimension but are rather the dimension of the feature vector. 


  I WILL EXPAND THIS ANSWER WITH YOUR SPECIFIC NEEDS.