Professional Documents
Culture Documents
Date – 16/05/2011
Phase 1
Problem statement:
Solution:
The algorithm mentioned below explains the solution to the above mentioned problem
statement.
1) Start.
2) Generate two 4x4 matrixes as a source of random numbers between 1 and 255 each 8
bit long which will act as pixel sources. These matrices are represented as frames
specifically 2 in number.
a) Function takes in two input values as row and column of the first matrix which
needs to be searched within the second matrix. This is done using subtraction and
calculating the error. Square this difference value.
b) Find the total sum of all the squared differences calculated (total error).
c) Repeat the loop till all the elements of second matrix are subtracted with the
desired row and column of the first matrix.
6) End
MATLAB code for the above algorithm
The code consists of defining a function which allows the user to input a particular row and
column within the first matrix which needs to be searched in the second matrix. The function
is shown below:
Pixel_2_src = randsrc(4,4,[1:255]);
mat_diff=0;
sum=0;
for i=1:4 % loop used to calculate the difference between two matrices
for j=1:4
mat_diff = Pixel_1_src (row,column)- Pixel_2_src (i,j);
sum = sum + mat_diff ^2;
end
end
end
Pixel_1_src =
71 178 112 48
12 81 98 125
Pixel_2_src =
193 42 87 66
71 31 150 130
Mean_Square_Error =
4.2314e+003
The task is to implement a block search for small group of pixels and should be extended to
larger block.
Solution:
The algorithm mentioned below explains the solution to the above mentioned problem
statement.
1) Start.
2) Generate two 4x4 matrixes as a source of random numbers between 1 and 255 each 8
bit long which will act as pixel sources.
3) Define a motion vector of size 2x2. The user inputs the row and column to be
searched.
4) Function takes in two input values as row and column of the first matrix which needs
to be searched (subtracted) in second matrix.
d) Repeat the loop 9 times as the combination of the number of all possible locations
is 9, so the number of steps of the loop is set to 9.
This algorithm can be extended to a larger block of pixels as explained in Phase 2 section of
the report.
Pixel_2_src = randsrc(4,4,[1:255])
Motion_vector = [0 0 ; 0 0];
Mat_diff = 0;
error=0;
error = (1/4)*(det(Motion_vector));
end
end
end
Pixel_1_src =
54 244 148 46
73 232 34 149
207 41 163 21
Pixel_2_src =
133 25 87 96
25 91 150 232
Mean_Sqare_Error =
1.0748e+007
Phase 2
Problem statement:
Solution:
The algorithm mentioned below explains the solution to the above mentioned problem
statement.
1) Start.
2) Generate random numbers between 1 and 255 each 8 bit long which will act as pixel
sources.
48x48
48x48
4) Function inputs row and column values which is the position of motion vector in the
first frame.
5) Use a well-defined loop for calculation of motion vector and the differences between
the two pixel sources (matrix). The number of all possible 16x16 matrixes is 1089
(33x33) in size. So the loop repetition is set to 1089 times.
a) At each step, a 16x16 matrix is chosen in the first frame and this is compared to
one of all possible 16x16 matrixes in the second frame as shown below:
16x16 ………………….
16x16
……………………. 16x16
48x48 48x48
Pixel source 1 Pixel source 2
b) Find the total sum of all the differences calculated. If the sum is negative then
remove the negative sign and make it positive.
6) To get Minimum Square Error, there is a need to find the minimum value of the
difference and also the position of it in order to know the positions of the most similar
matrix which is known by index value. Find the matrix index.
7) Find the minimum value of the pixel difference in order to find the most similar
matrix. Using this calculate the mean square error.
8) Find the row and column of the matched matrix using index value.
9) Display the mean square error, matched matrix index, matched matrix row, matched
matrix column and the two matched matrices.
10) End
Pixel_2_src = randsrc(48,48,[1:255]);
for i= 1:33;
for j=1:33;
for c=1:16
for d =1:16
end
end
temp_mat_diff(count) = abs(mat_diff);
% absolute value of total difference is stored as a vector
Name- Krishnav B. Dave The University of York
Exam Number-Y6355282
Page 10
DSP Architecture Mini Project
mat_diff = 0;
% matrix difference variable is made zero for the second time for loop execution
count = count + 1;
end
end
if(column_found == 0)
column_found = 33; % column and row search
else
row_found = row_found + 1;
end
row_found
column_found
Mean_Square_Error =
20025
row_found =
24
column_found =
21
ans =
77 239 8 107 221 128 226 233 135 199 88 90 150 243 120 3
72 164 25 200 215 188 241 70 65 250 62 52 114 110 184 215
149 139 153 166 39 38 98 206 74 225 136 42 97 202 116 120
245 215 112 197 191 236 217 223 185 2 43 216 13 229 206 247
253 111 128 23 161 43 100 208 13 220 197 190 52 249 115 178
124 235 27 35 74 200 47 187 154 82 220 186 235 236 81 239
25 70 46 182 255 222 71 109 21 150 77 158 159 230 237 136
135 197 133 202 106 81 140 147 160 10 121 216 254 79 18 106
110 7 184 206 196 108 149 143 106 82 114 192 204 47 126 110
251 99 223 102 76 30 236 72 192 74 147 150 180 211 151 117
ans =
107 182 125 154 117 23 57 44 65 30 186 241 190 206 173 146
166 170 242 10 15 122 82 117 71 25 141 227 231 156 127 24
242 82 75 190 249 167 249 201 242 199 42 194 50 206 244 147
161 71 117 218 83 175 216 116 183 3 195 88 172 18 128 50
75 246 58 224 171 63 119 87 213 192 197 103 126 168 155 71
242 75 154 36 150 251 90 171 110 207 251 80 250 239 111 71
213 84 203 157 116 204 198 228 117 192 164 159 171 67 238 87
205 188 68 229 208 88 68 100 158 105 202 198 119 199 86 186
164 115 19 190 254 255 184 22 253 140 26 158 98 119 18 72
24 161 150 122 159 181 119 227 59 99 221 255 203 77 8 220
164 238 14
188 168 48 253 79 73 251 167 113 173 121 170 24 196 42 17
117 189 41 67 53 4 249 195 152 57 80 230 112 149 165 239
Conclusion:
The report shows three codes for Mean square error, block search implementation and
fast search implementation which performs the task of calculating Mean square error for a
given motion vector. Mean square error leads to higher capacity for searching; this comes as
an advantage for image processing while on the other side the high computing time for Mean
square error brings down the speed performance.