correlation analysis of two adjacent pixels
11 views (last 30 days)
Show older comments
I had an color image and an encrypted version of the same. I need to find the horizontal vertical and diagonal correlation coefficient of each channels R G and B of both plain image and cipher image. Help me with code for the same.
1 Comment
Answers (2)
KSSV
on 11 Jul 2020
Read about corr2.
1 Comment
omar A.alghafoor
on 11 Jul 2020
I have this code
% Finding correlation analysis of an image
% ----------------------------------------------
function corr(a,b)
a=imresize(a,[512,512]);
% Decompose in to R,G,B
%---------------------------------------
R=a(:,:,1);
G=a(:,:,2);
B=a(:,:,3);
%---------------------------------------
% Finding the correlation of adjacent pixels-------------Red
%----------------------------------------
A=double(R);
% Horizontal
x1 = A(:,1:end-1);
y1 = A(:,2:end);
fprintf(sprintf('%s Red:',b));
horizontal_values=corrcoef(x1,y1);
pause(1);
% Vertical
x2 = A(1:end-1,:);
y2 = A(2:end,:);
fprintf(sprintf('%s Red:',b));
vertical_vlaues=corrcoef(x2,y2)
pause(1);
% Diagonal,
x3 = A(1:end-1,1:end-1);
y3 = A(2:end,2:end);
fprintf(sprintf('%s Red:',b));
Diagonal_values=corrcoef(x3,y3)
%----------------------------------------
pause(4);
%----------------------------------------
% Correlation Figures
figure;
% plot(1,1),cor_figure(x1,y1,1),title(sprintf('%s Horizontal Red',b));
% plot(1,1),cor_figure(x2,y2,1),title(sprintf('%s Vertical Red',b));
% plot(1,1),cor_figure(x3,y3,1),title(sprintf('%s Diagonal Red',b));
subplot(131)
plot(x1,y1,'r'), title(sprintf('%s Horizontal Red',b));
subplot(132)
plot(x2,y2,'r'),title(sprintf('%s Vertical Red',b));
subplot(133)
plot(x3,y3,'r'),title(sprintf('%s Diagonal Red',b));
%----------------------------------------
pause(2);
%---------------------------------------
% Finding the correlation of adjacent pixels-------------Green
%----------------------------------------
A=double(G);
% Horizontal
x1 = A(:,1:end-1);
y1 = A(:,2:end);
fprintf(sprintf('%s Green:',b));
horizontal_values=corrcoef(x1,y1)
pause(1);
% Vertical
x2 = A(1:end-1,:);
y2 = A(2:end,:);
fprintf(sprintf('%s Green:',b));
vertical_vlaues=corrcoef(x2,y2)
pause(1);
% Diagonal,
x3 = A(1:end-1,1:end-1);
y3 = A(2:end,2:end);
fprintf(sprintf('%s Green:',b));
Diagonal_values=corrcoef(x3,y3)
%----------------------------------------
pause(1);
%----------------------------------------
% Correlation Figures
figure;
% plot(1,1),cor_figure(x1,y1,2),title(sprintf('%s Horizontal Green',b));
% plot(1,1),cor_figure(x2,y2,2),title(sprintf('%s Vertical Green',b));
% plot(1,1),cor_figure(x3,y3,2),title(sprintf('%s Diagonal Green',b));
subplot(131)
plot(x1,y1,'g'),title(sprintf('%s Horizontal Green',b));
subplot(132)
plot(x2,y2,'g'),title(sprintf('%s Vertical Green',b));
subplot(133)
plot(x3,y3,'g'),title(sprintf('%s Diagonal Green',b));
%----------------------------------------
pause(2);
%---------------------------------------
% Finding the correlation of adjacent pixels-------------Blue
%----------------------------------------
A=double(B);
% Horizontal
x1 = A(:,1:end-1);
y1 = A(:,2:end);
fprintf(sprintf('%s Blue:',b));
horizontal_values=corrcoef(x1,y1)
pause(1);
% Vertical
x2 = A(1:end-1,:);
y2 = A(2:end,:);
fprintf(sprintf('%s Blue:',b));
vertical_vlaues=corrcoef(x2,y2)
pause(1);
% Diagonal,
x3 = A(1:end-1,1:end-1);
y3 = A(2:end,2:end);
fprintf(sprintf('%s Blue:',b));
Diagonal_values=corrcoef(x3,y3)
%----------------------------------------
pause(1);
%----------------------------------------
% Correlation Figures
figure;
% plot(1,1),cor_figure(x1,y1,3),title(sprintf('%s Horizontal Blue',b));
% plot(1,1),cor_figure(x2,y2,3),title(sprintf('%s Vertical Blue',b));
% plot(1,1),cor_figure(x3,y3,3),title(sprintf('%s Diagonal Blue',b));
subplot(131)
plot(x1,y1,'b'),title(sprintf('%s Horizontal Blue',b));
subplot(132)
plot(x2,y2,'b'),title(sprintf('%s Vertical Blue',b));
subplot(133)
plot(x3,y3,'b'),title(sprintf('%s Diagonal Blue',b));
%----------------------------------------
end
%----------------------------------------
but plot for image encryption not accept
Hyderkkk
on 26 Sep 2021
IA=rgb2gray(im2double(A));
c_diag = corrcoef(IA(1:end-1, 1:end-1), IA(2:end, 2:end));
c_vert = corrcoef(IA(1:end-1, :), IA(2:end, :));
c_horz = corrcoef(IA(:, 1:end-1, :), IA(:, 2:end));
figure;
subplot(3,3,1)
plot(IA(1:end-1, 1:end-1), IA(2:end, 2:end),'b'),title(sprintf('%s Horizontal Orginal image',b));
subplot(3,3,2)
plot(IA(1:end-1, :), IA(2:end, :),'b'),title(sprintf('%s Vertical Orginal image',b));
subplot(3,3,3)
plot(IA(:, 1:end-1, :), IA(:, 2:end),'b'),title(sprintf('%s Diagonal Orginal image',b));
IAA=rgb2gray(im2double(im12));
c_diage = corrcoef(IAA(1:end-1, 1:end-1), IAA(2:end, 2:end))
c_verte = corrcoef(IAA(1:end-1, :), IAA(2:end, :))
c_horze = corrcoef(IAA(:, 1:end-1, :), IAA(:, 2:end))
subplot(3,3,4)
plot(IAA(1:end-1, 1:end-1), IAA(2:end, 2:end),'r'),title(sprintf('%s Horizontal chiphered image ',b));
subplot(3,3,5)
plot(IAA(1:end-1, :), IA(2:end, :),'r'),title(sprintf('%s Vertical chiphered image',b));
subplot(3,3,6)
plot(IAA(:, 1:end-1, :), IA(:, 2:end),'r'),title(sprintf('%s Diagonal chiphered image',b));
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!