Skip to content

Commit

Permalink
updated comments + additional check cases
Browse files Browse the repository at this point in the history
updated comments + additional check cases
  • Loading branch information
suahnkim committed Apr 22, 2021
1 parent 1924358 commit ca5dc24
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
31 changes: 17 additions & 14 deletions main.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,15 @@
payload=randi([0,1],payload_length,1);

%% Embedding for maximum contrast
iteration_max=[];
[rdh_image, ~, ~, ~,embedding_capacity_left]=mbp(image,payload,iteration_max,[]);
iteration_max=1000; % default maximum iteration_max is 1000, you can increase it as much as you want, but it may take longer time
max_contrast_bypass_mode=0; % 0 = embedes addtional synthetic bits after the specified payload has been embedded to maximize the contrast
[rdh_image, ~, ~, ~,embedding_capacity_left]=mbp(image,payload,iteration_max,max_contrast_bypass_mode);
if embedding_capacity_left < 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
disp('Failed embedding, try increasing iteration_max')
else
disp(['Can embed ' num2str(embedding_capacity_left) ' bits more (estimated)'])
end

%% 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)
Expand All @@ -41,6 +31,19 @@
disp('Failed to recover the payload')
end


%% Embedding only the payload => does not maximize the contrast
iteration_max=1000; % default maximum iteration_max is 1000, you can increase it as much as you want, but it may take longer time
max_contrast_bypass_mode=1; %1=terminates after specified payload has been embedded, does not achieve maximum contrast
[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 ~= -1
disp('Failed embedding, try increasing iteration_max')
else
disp(['Successfully embedded ' num2str(payload_length) ' bits. Cannot determine how many more bits can be embedded since max_contrast_bypass_mode was 1. To determine maximum number of bits embeddable (estimated), run with max_contrast_bypass_mode =0'])
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)
Expand Down
10 changes: 6 additions & 4 deletions mbp.m
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
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;
iteration_max = 1000;
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));
actual_payload=[de2bi(length(actual_payload),payload_length_max)'; actual_payload];


rng(0);
%image = image(5:end-5,5:end-5);
image_size = size(image);

P_s_list=zeros(1,iteration_max);
Expand Down Expand Up @@ -97,6 +95,7 @@
else
image_hor(image_hor < P_s & image_hor > P_c)=image_hor(image_hor < P_s & image_hor > P_c)+d; %LHS
end

%Embed P_s
image_hor(image_hor==P_s & message_whole)=image_hor(image_hor==P_s & message_whole)+d;

Expand All @@ -110,6 +109,9 @@
ref_image_hor(:,iteration_max+1:end) = [];
payload_total=[payload_total; payload];
embedding_capacy_left=length(payload_total)-length(actual_payload);
if max_contrast_bypass_mode ==1
embedding_capacy_left=-1;
end
break

else
Expand Down

0 comments on commit ca5dc24

Please sign in to comment.