【发布时间】:2016-10-21 00:59:05
【问题描述】:
我正在尝试使用定向梯度直方图来实现对复制移动伪造的纸张检测。
算法是:
将图像分成重叠的块。
计算每个块的特征向量并将它们存储在矩阵中。
按字典顺序对矩阵进行排序
使用块匹配来识别伪造区域。
我被第三步卡住了,无法继续。
我实现的代码是:
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