Skip to content

Commit

Permalink
added maximum contrast bypass mode
Browse files Browse the repository at this point in the history
The original paper assumes maximum contrast is the goal, thus it embeds synthetic random bits after the payload has been embedded. The maximum contrast bypass mode ensures that the algorithm terminates right after the payload has been embedded.
  • Loading branch information
suahnkim committed Apr 22, 2021
1 parent 5bb4838 commit 1924358
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

main.asv
*.asv
54 changes: 49 additions & 5 deletions main.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,31 @@
image=double(imread('Kodak images/Original/kodim01_org.png'));

%Payload
payload_length=25000; %number of bits to be embedded
rng(1) %Presets randomness to ensure the results are reproducible
payload_length=15000; %number of bits to be embedded
payload=randi([0,1],payload_length,1);

%Embedding
[rdh_image, ~, ~, ~,embedding_capacity_left]=mbp(image,payload);
%% Embedding for maximum contrast
iteration_max=[];
[rdh_image, ~, ~, ~,embedding_capacity_left]=mbp(image,payload,iteration_max,[]);
if embedding_capacity_left < 0
disp('Failed embedding')
disp('Failed embedding, increase iteration_max') % default maximum iteration_max is 300, you can increase it as much as you want, but it may take longer time
else
disp(['Can embed ' num2str(embedding_capacity_left) ' bits more (estimated)'])
end

%Recovery check
%% Embedding only the payload => does not maximize the contrast
max_contrast_bypass_mode=1;
iteration_max=[];
[rdh_image_non_max_contrast, ~, ~, ~,embedding_capacity_left_non_max_contrast]=mbp(image,payload,iteration_max,max_contrast_bypass_mode);
if embedding_capacity_left_non_max_contrast < 0
disp('Failed embedding, increase iteration_max') % default maximum iteration_max is 300, you can increase it as much as you want, but it may take longer time
else
disp(['Can embed ' num2str(embedding_capacity_left_non_max_contrast) ' bits more (estimated)'])
end


%% Recovery check for maximum contrast case
[payload_rec, re_image] = mbp_recovery(rdh_image);
if isequal(re_image,image)
disp('Original image recovered')
Expand All @@ -28,10 +41,41 @@
disp('Failed to recover the payload')
end

%% Recovery check for when only the specified payload has been embedded => does not maximize the contrast
[payload_rec_non_max_contrast, re_image_non_max_contrast] = mbp_recovery(rdh_image_non_max_contrast);
if isequal(re_image_non_max_contrast,image)
disp('Original image recovered')
else
disp('Failed to recover the original image')
end

if isequal(payload_rec_non_max_contrast,payload)
disp('Payload recovered')
else
disp('Failed to recover the payload')
end


%show the image
close all
figure(1)
imshow(uint8(image))
figure(2)
imshow(uint8(rdh_image))
figure(3)
imshow(uint8(rdh_image_non_max_contrast))














end
10 changes: 6 additions & 4 deletions mbp.m
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
function [rdh_image, iteration_max, EC_list, LM_size_list, embedding_capacy_left]=mbp(image, actual_payload, iteration_max)
switch nargin
case 2
function [rdh_image, iteration_max, EC_list, LM_size_list, embedding_capacy_left]=mbp(image, actual_payload,iteration_max, max_contrast_bypass_mode)
if isempty(iteration_max)
iteration_max = 300;
end
if isempty(max_contrast_bypass_mode)
max_contrast_bypass_mode = 0;
end
%Preprocess Payload (length appended)
image_size=size(image);
payload_length_max=2*ceil(log2(image_size(1)*image_size(2)+1));
Expand Down Expand Up @@ -46,7 +48,7 @@
%Embedding capacity + stop condition check
H_P_s=sum(image_hor==P_s);

if H_P_s-sum(image_hor(1:16)==P_s) < length(LM)+32 || iteration == iteration_max %Stop condition reached
if H_P_s-sum(image_hor(1:16)==P_s) < length(LM)+32 || iteration == iteration_max || (max_contrast_bypass_mode==1 && length(payload_total) > length(actual_payload)) %Stop condition reached
%no need to update iteration
P_s=P_s_previous;
P_c=P_c_previous;
Expand Down

0 comments on commit 1924358

Please sign in to comment.