# 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;
[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;
[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

• What's the question? Which part are you having trouble with? Is the function provided to you or do you need to create it? Do you already know which images are in each class? Applying a function to a bunch of inputs and putting the outputs in a table seems straightforward enough. Commented Apr 6, 2012 at 13:34
• @endolith.pleas can you see my edition? thanks a lot.
– ruaa
Commented Apr 6, 2012 at 14:41
• If this is just a matter of "how do I read filenames with a matlab script", it's probably a better fit on stackoverflow.com Commented Apr 6, 2012 at 15:43
• how can i transfer it to stackoverflow.com , and how i can know that this question must be posted at stackoverflow.com??.thanks
– ruaa
Commented Apr 6, 2012 at 23:50
• Is this your final year project perhaps?
– user24145
Commented Oct 12, 2016 at 15:19

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.