首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >基于算法的拷贝移动伪造检测

基于算法的拷贝移动伪造检测
EN

Stack Overflow用户
提问于 2016-10-16 17:10:37
回答 1查看 593关注 0票数 0

我试图用方向梯度直方图来实现对拷贝移动伪造的纸张检测。

算法是:

  1. 将图像划分为重叠块。
  2. 计算每个块的特征向量并将它们存储在一个矩阵中。
  3. 按字典顺序排列矩阵
  4. 使用块匹配来识别伪造区域。

gradients

我被第三步困住了,不能继续了。

我实现的代码是:

代码语言:javascript
复制
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;
EN

回答 1

Stack Overflow用户

发布于 2016-10-18 20:12:42

在阅读了论文中提到的一些参考文献之后(参考文献)。8和20):

字典排序相当于字母排序,对于数字,即:1 1 1<1 1 2 1<2 3 4 5<2 4 4 5。

因此,在您的例子中,您用以下方式使用函数sortrows()

代码语言:javascript
复制
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记录排序行的原始索引。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40073025

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档