MATLAB Answers

display image similarity using pie and bar chart

4 views (last 30 days)
Hi guys, i want to know whether it is possible to display the similarities between 2 or more images using pie chart and bar chart in percentages.

  0 Comments

Sign in to comment.

Accepted Answer

Subhadeep Koley
Subhadeep Koley on 28 May 2020
I have used the ssim function to measure the similarity between to images. ssim metric value lies in the range of [0, 1]. Higher ssim value represents higher similarity. Therefore, I have used 1-ssimVal to caculate the dissimilarity. Refer the code below,
close all; clc;
% Read the original image
img = imread('cameraman.tif');
% Adding noise in the original image for demo
noisyImg = imnoise(img, 'gaussian', 0, 0.05);
% Calculate Structural Similarity Index (SSIM)
ssimVal = ssim(img,noisyImg);
% (1-ssimVal) will give the dissimilarity
values = [ssimVal, (1-ssimVal)];
% Display results
figure('units', 'normalized', 'outerposition', [0 0 1 1])
subplot(2, 2, 1)
imshow(img)
title('Original image')
subplot(2, 2, 2)
imshow(noisyImg)
title('Noisy image')
subplot(2, 2, 3)
pie(values)
labels = {'Similarity(%)', 'Dissimilarity(%)'};
legend(labels, 'Location', 'bestoutside')
title('Similarity pie chart')
subplot(2, 2, 4)
xValues = categorical({'Similarity(%)', 'Dissimilarity(%)'});
yValues = [ssimVal (1-ssimVal)].*100;
han = bar(xValues, yValues);
xtips1 = han(1).XEndPoints;
ytips1 = han(1).YEndPoints;
labels1 = string(han(1).YData);
text(xtips1, ytips1, labels1, 'HorizontalAlignment', 'center',...
'VerticalAlignment', 'bottom')
title('Similarity bar chart')
Hope this helps!

  2 Comments

Subhadeep Koley
Subhadeep Koley on 28 May 2020
@ nat larsey It is not clear what you exactly meant by 'compare'. SSIM compare how visually similar two images are. You want something like Cross Correlation metric between those images?

Sign in to comment.

More Answers (0)


Translated by