-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJPEGBlockTechnique.m
More file actions
133 lines (113 loc) · 2.6 KB
/
JPEGBlockTechnique.m
File metadata and controls
133 lines (113 loc) · 2.6 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
function [ ] = JPEGBlockTechnique( imagearg, thresh )
%UNTITLED4 Summary of this function goes here
% Detailed explanation goes here
image = imread(imagearg);
[m,n,z] = size(image);
if z == 3
image = double( rgb2gray(image) );
else
image = double( image );
end
j = 1;
w = waitbar(0);
while 8*j < m
waitbar( 8*j/(3*m), w, 'Wait...' );
i = 1;
while 8*i < n
value = image( 8*j, 8*i ) - ...
image( 8*j, 8*i + 1 ) - ...
image( 8*j + 1, 8*i ) + ...
image( 8*j + 1, 8*i + 1 );
% Resets 64 px block to calculated val
a = 8*(j-1) + 1;
while a <= 8*i
b = 8*(i-1) + 1;
while b <= 8*i
image( a, b ) = value;
b = b + 1;
end
a = a + 1;
end
i = i + 1;
end
j = j + 1;
end
cnt = 8*j;
j = 1;
while 8*j < m
waitbar( (cnt + 8*j)/3*m, w, 'Wait...');
i = 1;
while 8*i < n
% Difference between...
% Left - Right
difflr = abs( image( 8*j, 8*i ) - ...
image( 8*j, 8*i + 1 ));
% Up - Down
diffud = abs( image( 8*j, 8*i ) - ...
image( 8*i + 1, 8*i ));
if ((difflr >= thresh) || (diffud >= thresh ))
% set all px in block to white
a = 8*(j-1) + 1;
while a <= 8*j
b = 8*(i-1) + 1;
while b <= 8*i
image( a, b ) = 255;
b = b + 1;
end
a = a + 1;
end
end
i = i + 1;
end
j = j + 1;
end
cnt = 16*j;
% Sets nonwhite blocks to 0.
j = 1;
while 8*j < m
waitbar( ( cnt + 8*j )/3*m, w, 'Almost there...');
i = 1;
while 8*i < n
if ( image( 8*j, 8*i ) ~= 255 )
a = 8*(j-1) + 1;
while a <= 8*j
b = 8*(i-1) + 1;
while b <= 8*i
image( a, b ) = 0;
b = b + 1;
end
a = a + 1;
end
end
i = i + 1;
end
j = j + 1;
end
i = 1;
while 8*i < n
i = i + 1;
end
i = i - 1;
a = 1;
while a <= m
b = 1;
while 8*(i-1) + b <= n
image( a, 8*(i-1) + b ) = 0;
b = b + 1;
end
a = a + 1;
end
% Clean up next to last row
a = 1;
while a <= n
b = 1;
while 8*(j-2) + b <= m
image( 8*(j-2) + b, a ) = 0;
b = b + 1;
end
a = a + 1;
end
close(w);
image = uint8( image );
imshow( image );
end