I am trying to implement the fake paging detection Copy-Cover (Copy-Move) algorithm , and I seem to be missing something. The Matlab program works without any errors, but I get an output containing almost the entire image.
The main algorithm (as I understand it):
- Create an Nb x Nc matrix of PCA values, where Nb = (sqrt (N) - * sqrt (b) +1) ^ 2 and Nc is 27
- Row sorting
- Iterate over a sorted array and for | ij | <Nn processes the element (lines are next to each other)
- Find the offset of the processed pixels and discard those that are not next to each other.
- Find the frequency of the coordinates found (count them)
- Set the maximum number of dots per new image.
Note. This only works with grayscale images (of which I use), unless you break up the RGB colors.
matlab Code:
%L = imread('images/lena3.jpg');
L = imread('images/Toronto2_F.png');
L=rgb2gray(L);
figure(1);
imshow(L);
b=256; % block size used to look for duplicates
b1=sqrt(b);
Nn = 5; % how many close rows to check
Nd = 15; %Threashold
Nc=26; % Truncate PCA at this length
Nt=26;
% calculate the total size of the image
n = numel(L);
b2 = sqrt(n)-sqrt(b)+1;
% calculate Nb
Nb= power((sqrt(n)-sqrt(b)+1),2);
% the matix of Nc plus the position
M=zeros(Nb, Nc);
% temp index array
Mi = zeros(Nb, 2);
i=1;
disp('Starting PCA');
for r = 1:b2
for c = 1:b2
% Extract each block
B = L(r:r+b1-1,c:c+b1-1);
[pc, latent, explained] = pcacov(cov(double(B)));
%[pc, latent, explained] = princomp(double(B), 'NumComponents', Nc);
Z = pc(1:Nc);
Mi(i,:) = [r c];
M(i,:) = Z;
i = i+1;
end
end
disp('Sorting M -> S');
%Sort M array in lexicographic order -> S
[S, index] = sortrows(M);
P= zeros(1,3);
disp('Finding Duplicates');
for i = 1:Nb
iv = index(i);
xi=mod(iv,b2) + 1;
yi=ceil(iv/b2);
j = i+1;
while j < Nb && abs(i - j) < Nn
jv=index(j);
xj=mod(jv,b2) + 1;
yj=ceil(jv/b2);
z=sqrt(power(xi-xj,2) + power(yi-yj,2));
% only process those whose size is above Nd
if z > Nd
idx = find(P(:,1)== xi & P(:,2)==yi, 1, 'last');
if isempty(idx)==1
P = [P; [xi, yi, 1]];
else
P(idx,3) = P(idx,3) + 1;
end
idx = find(P(:,1)== xi & P(:,2)==yi, 1, 'last');
if isempty(idx)==1
P = [P; [xj, yj, 1]];
else
P(idx,3) = P(idx,3) + 1;
end
end
j = j + 1;
end
end
disp('Sorting findings');
rows = size(P,1);
% sort descending order
P = sortrows(P, -3);
% Mark the found blocks
disp('Creating Image');
idx = 1;
% Create a black image
RI = zeros(sqrt(n), sqrt(n));
while idx < rows && P(idx,3) > 5
x = P(idx,1);
y = P(idx,2);
RI(x,y) = 1;
idx = idx + 1;
end
figure(2);
imshow(RI);
matlab is not in my wheelhouse, and I'm sure the code above is not efficient, but to be honest, I'm just trying to get it to work. Anyone have suggestions what can I do wrong?
Note: a copy of the image can be found here (I do not want to publish, since I do not know about the copyright of the image), just copy the paste a couple of blocks 81x81 in size around.
I also included my own photo, which can be used for testing.


