MATLAB Answers


How to implement the following equations in image encryption

Asked by Renjith V Ravi on 29 Dec 2016
Latest activity Commented on by Walter Roberson
on 29 Dec 2016
Upto finding D(i,j),I have found below
clear all
close all
im1 = imread('lena.bmp');% Read the input image
im2 = im1;
im2(10,10) = 255; % im2 is the image with one pixel difference
[M N] = size(im1);
r = uint8(randi([0,256],h,w)); % Generate a random matrix for encryption
C1 = bitxor(im1,r); % Encryption-1
% imdec = bitxor(xored,r);
C2 = bitxor(im2,r); % Encryption-2
% find D(i,j)
for i=1:M
for j=1:N
if C1(i,j)== C2(i,j)
D(i,j) =0;
D(i,j) =1;
D = uint8(D); % change D to uint8 format
how to find the NPCR and UCAI as shown below


Sign in to comment.

1 Answer

Answer by Walter Roberson
on 29 Dec 2016
 Accepted Answer


Yes,I have tried this already.But I got wrong answer
NPCR = mean(D(:)) * 100;
But watch out: your code expects the image to be grayscale, which might not be true for lena.bmp

Sign in to comment.