Skip to content

Commit

Permalink
Minor bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Paweł Korus committed Oct 13, 2016
1 parent 1979669 commit a85661a
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 125 deletions.
74 changes: 0 additions & 74 deletions demos/demo_antiforensics.m

This file was deleted.

18 changes: 9 additions & 9 deletions detectors/applyPRNUCorrelationFieldCentral.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
% -------------------------------------------------------------------------
% Written by Paweł Korus, Shenzhen University and AGH University of Science
% and Technology
% Version: September 2016
% Version: October 2016
% Contact: pkorus [at] agh [dot] edu [dot] pl
% -------------------------------------------------------------------------

Expand Down Expand Up @@ -111,8 +111,8 @@
bsk = bsks(1);

bs2 = floor(bs/2);
maxbx = size(image,2) - bs;
maxby = size(image,1) - bs;
maxbx = size(image,2) - bs + 1;
maxby = size(image,1) - bs + 1;

maxfx = ceil((size(image,2) - bs + 1)/bsk);
maxfy = ceil((size(image,1) - bs + 1)/bsk);
Expand Down Expand Up @@ -265,8 +265,8 @@
bsk = bsks(2);

bs2 = floor(bs/2);
maxbx = size(image,2) - bs;
maxby = size(image,1) - bs;
maxbx = size(image,2) - bs + 1;
maxby = size(image,1) - bs + 1;

maxfx = ceil((size(image,2) - bs + 1)/bsk);
maxfy = ceil((size(image,1) - bs + 1)/bsk);
Expand Down Expand Up @@ -327,11 +327,11 @@

% Compact results and fill missing
if bsk > 1
map_cfar = map_cfar(mod(bs2-1,bsk)+2:bsk:end, mod(bs2-1,bsk)+2:bsk:end);
map_prp = map_prp(mod(bs2-1,bsk)+2:bsk:end, mod(bs2-1,bsk)+2:bsk:end);
map_cfar = map_cfar(mod(bs2-1,bsk)+2:bsk:end, mod(bs2-1,bsk)+2:bsk:end);
map_prp = map_prp(mod(bs2-1,bsk)+2:bsk:end, mod(bs2-1,bsk)+2:bsk:end);
end
map_cfar = fillBorders(map_cfar);
map_prp = fillBorders(map_prp);
map_prp = fillBorders(map_prp);

% Return compensated correlation field
map_cor = corr_field ./ div_factor;
Expand All @@ -344,6 +344,6 @@
map_cfar = im2bw(map_cfar);

% Compact maps for smaller storage requirements
est_cor = single(est_cor(mod(bs2-1,bsk)+2:bsk:end, mod(bs2-1,bsk)+2:bsk:end));
est_cor = single(imresize(est_cor, size(map_prp)));
map_prp = single(map_prp);
end
31 changes: 16 additions & 15 deletions detectors/detectForgeryPRNUAdaptiveWnd.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
% -------------------------------------------------------------------------
% Written by Paweł Korus, Shenzhen University and AGH University of Science
% and Technology
% Version: September 2016
% Version: October 2016
% Contact: pkorus [at] agh [dot] edu [dot] pl
% -------------------------------------------------------------------------

Expand Down Expand Up @@ -169,8 +169,8 @@
bx = bs2_min + 1;
fi = 1;

maxbx = size(image,2) - bs2_min;
maxby = size(image,1) - bs2_min;
maxbx = size(image,2) - bs2_min + 1;
maxby = size(image,1) - bs2_min + 1;

maxfx = ceil((size(image,2) - bs + 1)/bsk);
maxfy = ceil((size(image,1) - bs + 1)/bsk);
Expand Down Expand Up @@ -290,18 +290,19 @@
t_last = toc; fprintf(' done in %.2f min\n', t_last/60);
end

% Compact missing pixels due to stride > 1
if bsk > 1
for map_name = map_list
response_map.(map_name{1}) = response_map.(map_name{1})(mod(bs2_min-1,bsk)+2:bsk:end, mod(bs2_min-1,bsk)+2:bsk:end);
response_map.(map_name{1}) = fillBorders(response_map.(map_name{1}));
if image_padding
margin = floor(129/2) / bsk;
map = response_map.(map_name{1});
map = map(margin:end-margin, margin:end-margin);
response_map.(map_name{1}) = map;
end
end
% Sub-sample valid pixels, remove NaNs and invert image padding
for map_name = map_list
if bsk > 1 || image_padding
response_map.(map_name{1}) = response_map.(map_name{1})(mod(bs2_min-1,bsk)+2:bsk:end, mod(bs2_min-1,bsk)+2:bsk:end);
end
response_map.(map_name{1}) = fillBorders(response_map.(map_name{1}));
response_map.(map_name{1}) = single(response_map.(map_name{1}));
if image_padding
margin = floor(129/2) / bsk;
map = response_map.(map_name{1});
map = map(margin:end-margin, margin:end-margin);
response_map.(map_name{1}) = map;
end
end

end
48 changes: 25 additions & 23 deletions detectors/detectForgeryPRNUCentral.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
% standard deviations), default 2
% cfar_fp_rate - false alarm rate for CFAR map, default 0.01
% verbose - boolean
% calc_pce - include also PCE and p-value maps
% calc_cfar - include also a CFAR map (3-label, see below)
% calc_pce - include PCE and p-value maps
% calc_cfar - include CFAR map (3-label, see below)
% segmentwise_correlation - corr only over similar pixels
% similarity_threshold - threshold for pixel similarity
% minimum_window_size - minimum segment size (in pixels)
Expand All @@ -27,16 +27,18 @@
% - map_cor - correlation field
% - est_cor - predicted correlation field
% - map_prp - tampering probability with real-valued scores [0,1]
% - map_cfar - binary decision map according to the two-threshold CFAR method
% and optionally:
% - map_cfar - binary decision map according to the two-threshold
% CFAR method and optionally:
% - map_pva - p-value based response map
% - map_pce - PCE response map
%
% Notes:
%
% The optional CFAR map is generated with 3 labels: 0 - authentic pixels; 1 - potentially
% tampered pixels that do not meet the constraint on the desired false positive rate;
% 2 - potentially tampered pixels that satisfy the FAR constraint.
% The optional CFAR map is generated with 3 labels:
% 0 - authentic pixels;
% 1 - potentially tampered pixels that do not meet the constraint on the
% desired false positive rate;
% 2 - potentially tampered pixels that satisfy the FAR constraint.
%
% References:
%
Expand All @@ -51,7 +53,7 @@
% -------------------------------------------------------------------------
% Written by Paweł Korus, Shenzhen University and AGH University of Science
% and Technology
% Version: September 2016
% Version: October 2016
% Contact: pkorus [at] agh [dot] edu [dot] pl
% -------------------------------------------------------------------------

Expand Down Expand Up @@ -182,8 +184,8 @@
sum2 = @(x) sum(x(:));

bs2 = floor(bs/2);
maxbx = size(image,2) - bs;
maxby = size(image,1) - bs;
maxbx = size(image,2) - bs + 1;
maxby = size(image,1) - bs + 1;

maxfx = ceil((size(image,2) - bs + 1)/bsk);
maxfy = ceil((size(image,1) - bs + 1)/bsk);
Expand Down Expand Up @@ -374,12 +376,12 @@
% the first threshold (here, fixed at 2 * standard deviation - approx 1% of false miss rate
% the second threshold is dynamic - guarantees certain fale acceptance rate limit
if calc_cfar
threshold = rates(1) * absence_model.normfit(2);
threshold = cfar_std_mul * absence_model.normfit(2);
label = 0;
if ncorr < threshold
% Check the H1 distribution to see if fp limit is not
% exceeded
if normcdf(ncorr, pred_cor, predictor.normfit(2)) < rates(2)
if normcdf(ncorr, pred_cor, predictor.normfit(2)) < cfar_fp_rate
label = 2;
else
label = 1;
Expand Down Expand Up @@ -414,18 +416,18 @@
t_last = toc; fprintf(' done in %.2f min\n', t_last/60);
end

% Compact missing pixels due to stride > 1
if bsk > 1
for map_name = map_list
% Sub-sample valid pixels, remove NaNs and invert image padding
for map_name = map_list
if bsk > 1 || image_padding
response_map.(map_name{1}) = response_map.(map_name{1})(mod(bs2-1,bsk)+2:bsk:end, mod(bs2-1,bsk)+2:bsk:end);
response_map.(map_name{1}) = fillBorders(response_map.(map_name{1}));
response_map.(map_name{1}) = single(response_map.(map_name{1}));
if image_padding
margin = floor(bs/2) / bsk;
map = response_map.(map_name{1});
map = map(margin:end-margin, margin:end-margin);
response_map.(map_name{1}) = map;
end
end
response_map.(map_name{1}) = fillBorders(response_map.(map_name{1}));
response_map.(map_name{1}) = single(response_map.(map_name{1}));
if image_padding
margin = floor(bs/2) / bsk;
map = response_map.(map_name{1});
map = map(margin:end-margin, margin:end-margin);
response_map.(map_name{1}) = map;
end
end

Expand Down
15 changes: 11 additions & 4 deletions detectors/detectForgeryPRNUFilter.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
% - bs - block size, e.g., 128 (only some values are allowed)
% - advanced - advanced parameters:
% mode - filtering mode: 'central', 'boxcar' or 'guided'
% stride - stride, e.g., 8
% stride - stride for probability computation, e.g., 8
% predictor_stride - stride for correlation estimation, e.g., 8
% cfar_std_mul - tampering acceptance threshold (number of standard deviations), default 2
% cfar_fp_rate - false alarm rate for CFAR map, default 0.01
% verbose - boolean
Expand All @@ -32,7 +33,7 @@
% -------------------------------------------------------------------------
% Written by Paweł Korus, Shenzhen University and AGH University of Science
% and Technology
% Version: September 2016
% Version: October 2016
% Contact: pkorus [at] agh [dot] edu [dot] pl
% -------------------------------------------------------------------------

Expand Down Expand Up @@ -65,7 +66,13 @@
if isfield(advanced, 'stride')
bsk = advanced.stride;
else
bsk = 16;
bsk = 4;
end

if isfield(advanced, 'predictor_stride')
pbsk = advanced.predictor_stride;
else
pbsk = 8;
end

% Extract noise from the image
Expand Down Expand Up @@ -113,7 +120,7 @@
end

% Estimate the correlation field and apply predictor
[decision_map, map_prp, est_field, map_cor] = applyPRNUCorrelationFieldCentral(image, camera_model, response, bs, [bsk 4], [cfar_std_mul cfar_fp_rate], verbose);
[decision_map, map_prp, est_field, map_cor] = applyPRNUCorrelationFieldCentral(image, camera_model, response, bs, [pbsk bsk], [cfar_std_mul cfar_fp_rate], verbose);

% Populate output struct
guided_response = struct();
Expand Down

0 comments on commit a85661a

Please sign in to comment.