-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphase_splice_detection.m
More file actions
164 lines (133 loc) · 5.64 KB
/
phase_splice_detection.m
File metadata and controls
164 lines (133 loc) · 5.64 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
% Input is a square test image. If it is RGB, then it is changed to a grayscale
% image.
%
% Output is a 78x2 array (maybe by 2, need to see how the Spider SVM works to see
% what the format needs to be). The values will be the 78 dimensional
% features of the test image and the predicted error image.
% The
function dataOut = phase_splice_detection(imgIn)
% read in the image (only handles black and gray
imgIn = imread(imgIn);
%% 1: FIND PREDICTED ERROR
[~, prediction_error] = predict_image(imgIn);
%% 2: TAKE WAVELET DECOMPOSITIONS
% use DB2 3 level decomp of the image; return the 4 subbands at each level
% subbands are approximation, horizontal, vertical, diagonal
% wavelet decomposition of image
[c ,s] = wavedec2(imgIn, 3, 'db2');
% approximation levels
approximationLevel1 = appcoef2(c,s,'db2',1);
approximationLevel2 = appcoef2(c,s,'db2',2);
approximationLevel3 = appcoef2(c,s,'db2',3);
% horizontal level details
horizontalLevel1 = detcoef2('h',c,s,1);
horizontalLevel2 = detcoef2('h',c,s,2);
horizontalLevel3 = detcoef2('h',c,s,3);
%vertical level details
verticalLevel1 = detcoef2('v',c,s,1);
verticalLevel2 = detcoef2('v',c,s,2);
verticalLevel3 = detcoef2('v',c,s,3);
% diagonal level details
diagonalLevel1 = detcoef2('d',c,s,1);
diagonalLevel2 = detcoef2('d',c,s,2);
diagonalLevel3 = detcoef2('d',c,s,3);
% wavelet decomposition of predicted_error
[cc ,ss] = wavedec2(prediction_error, 3, 'db2');
% approximation levels
approximationLevel11 = appcoef2(cc,ss,'db2',1);
approximationLevel22 = appcoef2(cc,ss,'db2',2);
approximationLevel33 = appcoef2(cc,ss,'db2',3);
% horizontal level details
horizontalLevel11 = detcoef2('h',cc,ss,1);
horizontalLevel22 = detcoef2('h',cc,ss,2);
horizontalLevel33 = detcoef2('h',cc,ss,3);
%vertical level details
verticalLevel11 = detcoef2('v',cc,ss,1);
verticalLevel22 = detcoef2('v',cc,ss,2);
verticalLevel33 = detcoef2('v',cc,ss,3);
% diagonal level details
diagonalLevel11 = detcoef2('d',cc,ss,1);
diagonalLevel22 = detcoef2('d',cc,ss,2);
diagonalLevel33 = detcoef2('d',cc,ss,3);
%% 4. HISTORGRAMS/PDF
% PDF of image
PDFimage = findPDF(imgIn);
% PDF of image wavelet decomposition
PDFapproximationLevel1 = findPDF(approximationLevel1);
PDFapproximationLevel2 = findPDF(approximationLevel2);
PDFapproximationLevel3 = findPDF(approximationLevel3);
PDFhorizontalLevel1 = findPDF(horizontalLevel1);
PDFhorizontalLevel2 = findPDF(horizontalLevel2);
PDFhorizontalLevel3 = findPDF(horizontalLevel3);
PDFverticalLevel1 = findPDF(verticalLevel1);
PDFverticalLevel2 = findPDF(verticalLevel2);
PDFverticalLevel3 = findPDF(verticalLevel3);
PDFdiagonalLevel1 = findPDF(diagonalLevel1);
PDFdiagonalLevel2 = findPDF(diagonalLevel2);
PDFdiagonalLevel3 = findPDF(diagonalLevel3);
% PDF of predicted_error image
PDFprediction_error = findPDF(prediction_error);
% PDF of predicted_error image wavelet decomposition
PDFapproximationLevel11 = findPDF(approximationLevel11);
PDFapproximationLevel22 = findPDF(approximationLevel22);
PDFapproximationLevel33 = findPDF(approximationLevel33);
PDFhorizontalLevel11 = findPDF(horizontalLevel11);
PDFhorizontalLevel22 = findPDF(horizontalLevel22);
PDFhorizontalLevel33 = findPDF(horizontalLevel33);
PDFverticalLevel11 = findPDF(verticalLevel11);
PDFverticalLevel22 = findPDF(verticalLevel22);
PDFverticalLevel33 = findPDF(verticalLevel33);
PDFdiagonalLevel11 = findPDF(diagonalLevel11);
PDFdiagonalLevel22 = findPDF(diagonalLevel22);
PDFdiagonalLevel33 = findPDF(diagonalLevel33);
%% 4.5 Build Matrix of all the things above
%
% Matrix of all the PDFs is organized as
% [original image | approximationLevel1 | approximationLevel2 | ...
% approximationLevel3 | horizontalLevel1 | horizontalLevel2 |
% horizontalLevel3 | verticalLevel1 | verticalLevel2 | verticalLevel3 |
% diagonalLevel1 | diagonalLevel2 | diagonalLevel3 | predition_error | ...
% | same flow as the beginning portion of the matrix ]
% then put the two together
ImgPDF = [PDFimage PDFapproximationLevel1 PDFapproximationLevel2 PDFapproximationLevel3 ...
PDFhorizontalLevel1 PDFhorizontalLevel2 PDFhorizontalLevel3 PDFverticalLevel1 PDFverticalLevel2 ...
PDFverticalLevel3 PDFdiagonalLevel1 PDFdiagonalLevel2 PDFdiagonalLevel3];
PredErrorPDF = [PDFprediction_error PDFapproximationLevel11 PDFapproximationLevel22 PDFapproximationLevel33 ...
PDFhorizontalLevel11 PDFhorizontalLevel22 PDFhorizontalLevel33 PDFverticalLevel11 PDFverticalLevel22 ...
PDFverticalLevel33 PDFdiagonalLevel11 PDFdiagonalLevel22 PDFdiagonalLevel33];
totalPDF = [ImgPDF PredErrorPDF];
[rows, columns] = size(ImgPDF);
%% 5. Fourier Transforms to Obtain the First Three Moments
% Each column in the matrix gives the PDF for each decomposition. The
% Moments matrices will hold the first three moments
for jj = 1:columns
numeratorMoment = 0;
denominatorMoment = 0;
for ii = 1:rows
numeratorMoment = numeratorMoment + totalPDF(ii,jj)*fft(totalPDF(ii,jj));
denominatorMoment = denominatorMoment + fft(totalPDF(ii,jj));
end
Moment1(jj) = numeratorMoment/denominatorMoment;
end
for jj = 1:columns
numeratorMoment = 0;
denominatorMoment = 0;
for ii = 1:rows
numeratorMoment = numeratorMoment + (totalPDF(ii,jj))^2*fft(totalPDF(ii,jj));
denominatorMoment = denominatorMoment + fft(totalPDF(ii,jj));
end
Moment2(jj) = numeratorMoment/denominatorMoment;
end
for jj = 1:columns
numeratorMoment = 0;
denominatorMoment = 0;
for ii = 1:rows
numeratorMoment = numeratorMoment + (totalPDF(ii,jj))^3*fft(totalPDF(ii,jj));
denominatorMoment = denominatorMoment + fft(totalPDF(ii,jj));
end
Moment3(jj) = numeratorMoment/denominatorMoment;
end
%% Format data for output
% format data as a row vector
dataOut = [Moment1 Moment2 Moment3];
end