-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcopy_paste_forge.m
More file actions
43 lines (32 loc) · 1.09 KB
/
copy_paste_forge.m
File metadata and controls
43 lines (32 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
function imgOut = copy_paste_forge(imgIn, varargin)
if nargin == 2;
try copies = varargin{1};
assert(isnumeric(copies))
assert(isscalar(copies))
assert(copies - floor(copies) == 0)
assert(copies > 0);
catch
error('number_of_forgeries should be a positive integer');
end
else
copies = 1;
end
imgOut = imgIn;
[rows, cols, ~] = size(imgIn);
rows = rows - mod(rows, 12);
cols = cols - mod(cols, 12);
% so evenly divisible by 3 and 4
limiting_dim = min(rows, cols);
for j=1:copies
forgeSize = randi(100, limiting_dim/4);
copy_from_row = randi([1, rows/4]);
copy_from_row = copy_from_row:(copy_from_row+forgeSize);
copy_from_col = randi([1, cols/4]);
copy_from_col = copy_from_col:(copy_from_col+forgeSize);
copy_to_row = randi([rows/2, floor(rows*2/3)]);
copy_to_row = copy_to_row:(copy_to_row+forgeSize);
copy_to_col = randi([cols/2, floor(cols*2/3)]);
copy_to_col = copy_to_col:(copy_to_col+forgeSize);
imgOut(copy_to_row, copy_to_col, :) = ...
imgIn(copy_from_row, copy_from_col, :);
end