-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocessShinyImage.m
More file actions
64 lines (53 loc) · 1.83 KB
/
processShinyImage.m
File metadata and controls
64 lines (53 loc) · 1.83 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
% this is the main processing function for altering the DC value of the
% shiny blocks
function [procMapVals newR] = processShinyImage(qlR,R,shine_hz,shine_vt,shine_tot,thresh,SGN)
blockSz = 8;
%depending on the quantization level of JPEG, the step size changes
if (qlR < 50)
c = 50/qlR;
else
c = (100 - qlR)/50;
end
step_sz = round(16*c/blockSz);
[M N] = size(R);
Mb = floor(M/blockSz);
Nb = floor(N/blockSz);
Mbpix = Mb*blockSz;
Nbpix = Nb*blockSz;
shineMapHz = shine_hz~=0;
shineMapVt = shine_vt~=0;
shineMap = or(shineMapHz, shineMapVt);
procMap = zeros(Mb,Nb); %3 or more edges shiny blocks
% detect shining blocks
for ii=1:Mb
for jj=1:Nb
det = shineMap((ii-1)*blockSz+1 : min(Mbpix,ii*blockSz), ...
(jj-1)*blockSz+1 : min(Nbpix,jj*blockSz));
if sum(det(:)) > thresh %test for blocks with 3 or more edges shiny
procMap(ii,jj) = 1;
end
end
end
newR = double(R(1:Mbpix,1:Nbpix));
% process shining blocks
procMapVals = zeros(Mb,Nb);
for ii=1:Mb
for jj=1:Nb
if procMap(ii,jj) == 1
Rb = R((ii-1)*blockSz+1:ii*blockSz, (jj-1)*blockSz+1:jj*blockSz);
shine = shine_tot((ii-1)*blockSz+1 : min(Mbpix,ii*blockSz), ...
(jj-1)*blockSz+1 : min(Nbpix,jj*blockSz));
procMapVals(ii,jj) = mean(abs(shine(:)));
if nargout > 1
if isequal(SGN,'positive')
val = Rb + step_sz;%*min(round(adjVal/step_sz),stepThresh);
elseif isequal(SGN,'negative')
val = Rb - step_sz;%*min(round(adjVal/step_sz),stepThresh);
else
error('SGN is either ''positive'' or ''negative''.');
end
newR((ii-1)*blockSz+1:ii*blockSz, (jj-1)*blockSz+1:jj*blockSz) = val;
end
end
end
end