Created
May 9, 2020 23:08
-
-
Save iR00i/d724b005dbf98dc80554eb42ad5aa9cb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function [key] = conceal() | |
tree = imread('tree.png'); | |
tree = tree - mod(tree,4);%set least significant bits of each pixel color component to 00 | |
r = tree(:,:,1); | |
g = tree(:,:,2); | |
b = tree(:,:,3); | |
key = randi(20); | |
hide(r,key,1); | |
hide(g,key,2); | |
hide(b,key,3); | |
result = tree; | |
result(:,:,1) = r; | |
result(:,:,2) = g; | |
result(:,:,3) = b; | |
imwrite(result, 'result.png'); | |
end | |
function [hid] = hide(image,key,dim) | |
cat = imread('cat.png'); | |
[row, col,~] = size(cat); | |
img = cat(:,:,dim); | |
% Unroll matrices to vectors to make them easy to loop over | |
treeVector = image(:); | |
catVector = img(:); | |
% Get the most significant bits | |
catVector = catVector./64; | |
max = row*col; % number of pixels/last index of vectors | |
i = 1; % loop counter | |
temp = 2; | |
n = 1; % index | |
while(i<max) | |
treeVector(n) = treeVector(n) + catVector(i); | |
n = n + key; | |
if n>max | |
n = temp; | |
temp = temp + 1; | |
end | |
i = i + 1; | |
end | |
hid = reshape(treeVector,[row,col]); | |
disp(hid); | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment