【问题标题】:copy move forgery detection stuck with algorithm复制移动伪造检测卡在算法中
【发布时间】:2016-10-21 00:59:05
【问题描述】:

我正在尝试使用定向梯度直方图来实现对复制移动伪造的纸张检测。

算法是:

  1. 将图像分成重叠的块。

  2. 计算每个块的特征向量并将它们存储在矩阵中。

  3. 按字典顺序对矩阵进行排序

  4. 使用块匹配来识别伪造区域。

https://www.researchgate.net/publication/276518650_Detection_of_copy-move_image_forgery_using_histogram_of_orientated_gradients

我被第三步卡住了,无法继续。

我实现的代码是:

clc;
clear all;
close all;
%read image
img = imread('006_F.png');
img=rgb2gray(img);
img=imresize(img, 1/4);
figure(1); 
imshow(img);

b=16; %block size
nrc=5; %no. of rows to check
td=416; %threshold
[r, c]=size(img);%Rows and columns;
column=(r-b+1)*(c-b+1);
M= zeros(column,4);
Mi = zeros(1,2);
i=1;
disp('starting extraction of features');
for r1 = 1:r-b+1
for c1 = 1:c-b+1
% Extract each block
B = img(r1:r1+b-1,c1:c1+b-1);

features = extractHOGFeatures(B);%extracting features
M(i, :) = features;
Mi(i,:) = [r1 c1];
i=i+1;
end
end
[S, index] = sortrows(M , [ 1 2 3 4]);
P= zeros(1,6);
b2=r-b+1;
disp('Finding Duplicates');
for i = 1:column
    iv = index(i);
    xi=mod(iv,b2) + 1;
    yi=ceil(iv/b2);
    j = i+1;    
    while j < column && abs(i - j) < 5
        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 > 16
            offset = [xi-xj yi-yj];
            P = [P;[xi yi xj yj xi-xj yi-yj]];  

        end          
       j = j + 1;
    end
end
rows = size(P,1);
P(:,6) = P(:,6) - min(P(:,6));
P(:,5) = P(:,5) - min(P(:,5));

maxValP = max(P(:,6)) + 1;
P(:,5) = maxValP .* P(:,5) + P(:,6);
mostfrequentval = mode(P(:,5));


disp('Creating Image');
idx = 2;
% Create a copy of the image and mask it

RI = img;
while idx < rows 
  x1 = P(idx,1);
  y1 = P(idx,2);
  x2 = P(idx,3);
  y2 = P(idx,4);

  if (P(idx,5) == mostfrequentval)
    RI(y1:y1,x1:x1) = 0;
    RI(y2:y2,x2:x2) = 0;

  end
  idx = idx + 1;
end;

【问题讨论】:

  • 您能准确地说出“按字典顺序”是什么意思吗?这就是你试图用“sortrows”做的吗?
  • 字典排序的定义是字典排序.. 是的,这就是我想用 sortrows 做的事情.. 你可以参考链接上的论文来帮助.. 提前谢谢
  • sortrows 应该可以工作,只是精确的列包含要作为第二个输入参数排序的字符串。
  • 矩阵的内容是特征向量..是数字..相同或相似的向量表示相似(伪造块)
  • 有些东西我不明白:你说:“字典排序是字典排序”然后:“矩阵的内容是特征向量..是数字”你能提供一个样本吗具有多行的矩阵以及您期望从排序过程中获得的结果?

标签: matlab


【解决方案1】:

在阅读了您正在研究的论文中指出的一些参考文献后(参考文献 [8] 和 [20]):

字典排序等同于字母排序,对于数字,即 [1 1 1 1]

因此,在您的情况下,您可以通过以下方式使用函数sortrows()

A = [1 1 1 1;1 1 1 2;1 1 1 4;1 2 2 2; 1 2 2 1; 1 4 6 3; 2 3 4 5; 2 3 6 6]; % sample matrix
[B,idx] = sortrows(A,[1 2 3 4]); % Explicit notation but it is the Matlab default setting so equivalent to sortrows(A)

这意味着:首先查看第一列,然后在相等的情况下查看第二列,以此类推,对 A 的行进行排序。

如果您要查找相反的顺序,请在列号之前指定“-”。

所以最后,你的代码是好的,如果结果不符合预期,它必须来自实施的另一个步骤......

编辑:参数idx记录了排序行的原始索引。

【讨论】:

  • hi..thanx.. 在此之后我想我需要行的索引.. 来获取块的起点,以便我可以计算块之间的欧几里得距离。 .
  • 我编辑了我的答案,以便您获得已排序行的索引。
  • 我已经编辑了我的代码..正如我所做的那样..我得到的结果只有几个点..被分割为伪造..而不是应该是的区域..跨度>
  • 那么这不再是一个编程问题了。可能是因为数据,因为特征,...
  • thanx.. 你帮了大忙.. :)
猜你喜欢
  • 2016-06-27
  • 1970-01-01
  • 2022-06-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-12
  • 2018-08-15
  • 2011-02-08
相关资源
最近更新 更多