Menghitung Korelasi Horizontal Vertical dan Diagonal pada Citra Digital


Korelasi pixel tetangga pada citra digital adalah suatu cara untuk menemukan hubungan nilai antara 2 pixel. Dalam hal ini kita bisa katakan hubungan antara Horizontal Vertical dan Diagonal. Salah satu artikel yang membahas hal tersebut Tang Hongmei; Han Liying; He Yu; Wang Xia, “An improved compound image encryption scheme,” in Computer and Communication Technologies in Agriculture Engineering (CCTAE), 2010 International Conference On , vol.3, no., pp.128-131, 12-13 June 2010
Di artikel tersebut di bagian C Correlation coefficient analysis disebutkan sebagai berikut

Screenshot from 2016-01-18 18:33:34
Screenshot from 2016-01-18 18:37:15

berangkat dari formula dan grafik tersebut, kita dapat menghitung nilai korelasi dan menampilkan nilai korelasi mengggunakan matlab sebagai berikut
sebagai contoh: saya mempunyai 2 images (image original dan image yang sudah terenkripsi) kita ingin mendapatkan nilai korelasi dari image original dan encrypted image (variable r dan r2) serta memplot korelasi antar tetangga tersebut, berikut scriptnya

%horizontal
clear all, close all
imrgb_o=double(imread('kodim23.png'));
imrgb_r=double(imread('Encrypt_DES_kodim23.png'));
imgray_o=sum(imrgb_o,3)/3; 
imgray_r=sum(imrgb_r,3)/3; 
[As Bs]=size(imgray_o);
x=imgray_o;
L=As*Bs;
x_r=reshape(x',1,L)';
y_r=circshift(x_r,-1);
figure4 = figure;
axes4 = axes('Parent',figure4)
hold(axes4,'all');
for i=1:L
    plot(x_r(i),y_r(i)), hold on
end
title('Horizontal Correlation Original Image')
saveas(figure4,'Horizontal Correlation Original Image.png') 
close (figure4)
x_mean=mean(x_r);
y_mean=mean(y_r);
for i=1:L
    A(i,1)=(x_r(i,1)-x_mean)*(y_r(i,1)-y_mean);
end
ConvA=sum(A)/L;
for i=1:L
    DA_x(i,1)=(x_r(i,1)-x_mean).^2;
end
for i=1:L
    DA_y(i,1)=(y_r(i,1)-y_mean).^2;
end
D_x=sum(DA_x)/L;
D_y=sum(DA_y)/L
r=ConvA/(sqrt(D_x*D_y))
%%%%%%%%%%%%%%%%%%%%%%%%%%%
x2=imgray_r;
x2_r=reshape(x2',1,L)';
y2_r=circshift(x2_r,-1);
y2_r(1,1)=0;
figure5 = figure;
axes5 = axes('Parent',figure5)
hold(axes5,'all');
for i=1:L
    plot(x2_r(i),y2_r(i)), hold on
end
title('Horizontal Correlation Encrypted Image by DES')
saveas(figure5,'Horizontal Correlation Encrypted Image by DES.png') 
close (figure5)
x2_mean=mean(x2_r);
y2_mean=mean(y2_r);
for i=1:L
    A2(i,1)=(x2_r(i,1)-x2_mean)*(y2_r(i,1)-y2_mean);
end
ConvA2=sum(A2)/L;
for i=1:L
    DA2_x(i,1)=(x2_r(i,1)-x2_mean).^2;
end
for i=1:L
    DA2_y(i,1)=(y2_r(i,1)-y2_mean).^2;
end
D_x2=sum(DA2_x)/L;
D_y2=sum(DA2_y)/L;
r2=ConvA2/(sqrt(D_x2*D_y2))
save('Konv_horzontal.mat','r','r2')

Vertical Correlation Encrypted Image by DES

Vertical Correlation Original Image

%Vertikal
clear all
imrgb_o=double(imread('kodim23.png'));
imrgb_r=double(imread('Encrypt_DES_kodim23.png'));
imgray_o=sum(imrgb_o,3)/3; 
imgray_r=sum(imrgb_r,3)/3; 
[As Bs]=size(imgray_o);
x=imgray_o;
L=As*Bs;
x_r=reshape(x',1,L)';
y_r=circshift(x_r,-Bs);
figure7 = figure;
axes7 = axes('Parent',figure7)
hold(axes7,'all');
for i=1:L
    plot(x_r(i),y_r(i)), hold on
end
title('Vertical Correlation Original Image')
saveas(figure7,'Vertical Correlation Original Image.png') 
close (figure7)
x_mean=mean(x_r);
y_mean=mean(y_r);
for i=1:L
    A(i,1)=(x_r(i,1)-x_mean)*(y_r(i,1)-y_mean);
end
ConvA=sum(A)/L;
for i=1:L
    DA_x(i,1)=(x_r(i,1)-x_mean).^2;
end
for i=1:L
    DA_y(i,1)=(y_r(i,1)-y_mean).^2;
end
D_x=sum(DA_x)/L;
D_y=sum(DA_y)/L
r=ConvA/(sqrt(D_x*D_y))
%%%%%%%%%%%%%%%%%%%%%%%%%%%
x2=imgray_r;
% x2_r=reshape(x2',1,L)';
% y2_r=circshift(x2_r,-1);
% y2_r(1,1)=0;
x2_r=reshape(x2',1,L)';
y2_r=circshift(x2_r,-Bs);
figure8 = figure;
axes8 = axes('Parent',figure8)
hold(axes8,'all');
for i=1:L
    plot(x2_r(i),y2_r(i)), hold on
end
title('Vertical Correlation Encrypted Image by DES')
saveas(figure8,'Vertical Correlation Encrypted Image by DES.png') 
close (figure8)
x2_mean=mean(x2_r);
y2_mean=mean(y2_r);
for i=1:L
    A2(i,1)=(x2_r(i,1)-x2_mean)*(y2_r(i,1)-y2_mean);
end
ConvA2=sum(A2)/L;
for i=1:L
    DA2_x(i,1)=(x2_r(i,1)-x2_mean).^2;
end
for i=1:L
    DA2_y(i,1)=(y2_r(i,1)-y2_mean).^2;
end
D_x2=sum(DA2_x)/L;
D_y2=sum(DA2_y)/L;
r2=ConvA2/(sqrt(D_x2*D_y2))
save('Konv_vertikal.mat','r','r2')

Horizontal Correlation Encrypted Image by DES

Horizontal Correlation Original Image

%diagonal
clear all
imrgb_o=double(imread('kodim23.png'));
imrgb_r=double(imread('Encrypt_DES_kodim23.png'));
imgray_o=sum(imrgb_o,3)/3; 
imgray_r=sum(imrgb_r,3)/3; 
[As Bs]=size(imgray_o);
x=imgray_o;
L=As*Bs;
x_p=[x(:,:) x(:,1)];
x_p2=[x_p(:,:) ; [x(1,:) x(1,1)] ];
for i=1:As
    for j=1:Bs
    y(i,j)=x_p2(i+1,j+1);
    end
end
x_r=reshape(x',1,L)';
y_r=reshape(y',1,L)';
figure1 = figure;
axes1 = axes('Parent',figure1)
hold(axes1,'all');
for i=1:L
    plot(x_r(i),y_r(i)), hold on
end
title('Diagonal Correlation Original Image')
saveas(figure1,'Diagonal Correlation Original Image.png') 
close (figure1)
x_mean=mean(x_r);
y_mean=mean(y_r);
for i=1:L
    A(i,1)=(x_r(i,1)-x_mean)*(y_r(i,1)-y_mean);
end
ConvA=sum(A)/L;
for i=1:L
    DA_x(i,1)=(x_r(i,1)-x_mean).^2;
end
for i=1:L
    DA_y(i,1)=(y_r(i,1)-y_mean).^2;
end
D_x=sum(DA_x)/L;
D_y=sum(DA_y)/L
r=ConvA/(sqrt(D_x*D_y))
%%%%%%%%%%%%%%%%%%%%%%%%%%%
x2=imgray_r;
x2_p=[x2(:,:) x2(:,1)]
x2_p2=[x2_p(:,:) ; [x2(1,:) x2(1,1)] ]
for i=1:As
    for j=1:Bs
    y2(i,j)=x2_p2(i+1,j+1);
    end
end
x2_r=reshape(x2',1,L)';
y2_r=reshape(y2',1,L)';
figure2 = figure;
axes2 = axes('Parent',figure2)
hold(axes2,'all');
for i=1:L
    plot(x2_r(i),y2_r(i)), hold on
end
title('Diagonal Correlation Encrypted Image by DES')
saveas(figure2,'Diagonal Correlation Encrypted Image by DES.png') 
close (figure2)
x2_mean=mean(x2_r);
y2_mean=mean(y2_r);
for i=1:L
    A2(i,1)=(x2_r(i,1)-x2_mean)*(y2_r(i,1)-y2_mean);
end
ConvA2=sum(A2)/L;
for i=1:L
    DA2_x(i,1)=(x2_r(i,1)-x2_mean).^2;
end
for i=1:L
    DA2_y(i,1)=(y2_r(i,1)-y2_mean).^2;
end
D_x2=sum(DA2_x)/L;
D_y2=sum(DA2_y)/L;
r2=ConvA2/(sqrt(D_x2*D_y2))
save('Konv_diagonal.mat','r','r2')

Diagonal Correlation Encrypted Image by DES

Diagonal Correlation Original Image

Advertisements

Author: ridhobustami

orang ngak jelas

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s