Can anyone explain the code I have given for visual cryptography?
2 次查看(过去 30 天)
显示 更早的评论
This is the main program:
clc;
clear all;
close all;
tic;
%Input
inImg = imread('D:\our project\crypt\lena.bmp');
inImg=im2double(imresize(inImg,0.5));
figure
imshow(inImg);
inImg=im2bw(inImg);
%inImg=double(inImg);
figure
imshow(inImg);
title('Secret Image');
%fn call
[share1, share2, share12] = VisCrypt(inImg);
toc;
%Output
share1 = imresize(share1, [256 256]);
%share1=im2double(imresize(share1,0.5,'nearest'));
figure
imshow(share1);
title('Share 1');
share2 = imresize(share2, [256 256]);
figure
imshow(share2);
title('Share 2');
share12 = imresize(share12, [256 256]);
figure;imshow(share12);title('Overlapping Share 1 & 2');
imwrite(share1,'Share1.jpg');
imwrite(share2,'Share2.jpg');
imwrite(share12,'Overlapped.jpg');
This function is to generate shares:
function out = generateShare(a,b)
a1 = a(1);
a2 = a(2);
b1 = b(1);
b2 = b(2);
in = [a
b];
out = zeros(size(in));
randNumber = floor(1.9*rand(1));
if (randNumber == 0)
out = in;
elseif (randNumber == 1)
a(1) = a2;
a(2) = a1;
b(1) = b2;
b(2) = b1;
out = [a
b];
end
This function generates the splitting of black and white pixel:
function [share1, share2, share12] = VisCrypt(inImg)
s = size(inImg);
share1 = zeros(s(1), (2 * s(2)));
share2 = zeros(s(1), (2 * s(2)));
%%White Pixel
s1a=[1 0];
s1b=[1 0];
[x y] = find(inImg == 1);
len = length(x);
for i=1:len
a=x(i);b=y(i);
pixShare=generateShare(s1a,s1b);
share1((a),(2*b-1):(2*b))=pixShare(1,1:2);
share2((a),(2*b-1):(2*b))=pixShare(2,1:2);
end
%Black pixel
s0a=[1 0];
s0b=[0 1];
[x y] = find(inImg == 0);
len = length(x);
for i=1:len
a=x(i);b=y(i);
pixShare=generateShare(s0a,s0b);
share1((a),(2*b-1):(2*b))=pixShare(1,1:2);
share2((a),(2*b-1):(2*b))=pixShare(2,1:2);
end
share12=bitor(share1, share2);
share12= ~share12;
1 个评论
Walter Roberson
2017-2-22
Possibly Yes, but surely documenting the code you wrote is your responsibility?? You would be the person who knows the code the best.
If you are copying someone's code, then it would be easier for the author to explain it than for any of us to explain it.
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!