Calculating UACI, NPCR for 2 images

31 次查看(过去 30 天)
Presently I have a problem in implementing the UACI and PSNR code for 2 images which are respectively Original & Cipher Images. I need the code for calculating it......
What would the Code? I don't have much idea about it.. Do I need to find UACI between 2 images or only 1 image will be sufficient

采纳的回答

Image Analyst
Image Analyst 2012-4-22
See my demo:
% Demo to calculate PSNR of a gray scale image.
% http://en.wikipedia.org/wiki/PSNR
% by ImageAnalyst
clc;
close all;
clearvars;
workspace;
% Read in standard MATLAB demo image.
grayImage = imread('cameraman.tif');
[rows columns] = size(grayImage);
subplot(2, 2, 1);
imshow(grayImage, []);
title('Original Grey Scale Image');
set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.
% Add noise to it.
noisyImage = imnoise(grayImage, 'gaussian', 0, 0.003);
subplot(2, 2, 2);
imshow(noisyImage, []);
title('Noisy Image');
% Calculate mean square error.
mseImage = (double(grayImage) - double(noisyImage)) .^ 2;
subplot(2, 2, 3);
imshow(mseImage, []);
title('MSE Image');
mse = sum(sum(mseImage)) / (rows * columns);
% Calculate PSNR (Peak Signal to noise ratio).
PSNR = 10 * log10( 256^2 / mse);
message = sprintf('The mean square error is %.2f\nThe PSNR = %.2f', ...
mse, PSNR);
msgbox(message);
% set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.
After this example you should be able to use similar code to easily calculate NPCR and UACI, according to http://www.cyberjournals.com/Papers/Apr2011/05.pdf. You need both images to calculate them since they are a measure of the differences between the two images.
  2 个评论
Komeil
Komeil 2016-10-20
The NPCR is different from the PSNR.
Walter Roberson
Walter Roberson 2016-10-20
Image Analyst says "After this example you should be able to use similar code to easily calculate NPCR" -- in other words, he has not given the code here, but he has given a framework that can be adapted to calculate NPCR by anyone who looks up the formula for NPCR.

请先登录,再进行评论。

更多回答(1 个)

Hyderkkk
Hyderkkk 2020-8-31
How do i get the NPCR and UACI of an original speech and encryption in matlab code ?
  12 个评论
Image Analyst
Image Analyst 2021-5-25
I have no idea. Who said uaci should always be about 33?
Walter Roberson
Walter Roberson 2021-5-25
This file give the relation between two encrypted images of same size and type but I need the relation between original speech and encrypted speech
Are you familiar with the encryption technique that is often called ROT13? It is a caeser cypher in which each letter in the first half of the alphabet is replaced with the letter in the corresponding position in the second half of the alphabet, and vice versa, so 'A' gets replaced with the character 13 further on (which is 'N'), and 'p' would get replaced with the character 13 earlier (which is 'c')
Now take the original image, and apply ROT13 to it. Then take the result, and apply ROT13 to that, for even stronger encryption.
Now take the relationship between that double-ROT13 encrypted image and the encryption you found using a different method. As they are both encrypted image, there should be no problem comparing the two using an algorithm that compares encrypted images, right?
... But it turns out that applying ROT13 twice always gets you back exactly the original data. Therefore the original data is itself an encrypted version of the original data... just encrypted with a very weak encryption. And so you can use your algorithm that compares two encrypted images in order to compare the original image to the version of it you encrypted some other way than double-ROT13.

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by