-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgray_tone.m
80 lines (55 loc) · 1.64 KB
/
gray_tone.m
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
function [PH,PV,PLD,PRD] = gray_tone(image,L) %%% image is assumed to be a gray scale image
%%% L is the number of gray
%%% levels
[Nx,Ny]=size(image);
PH = zeros(L,L);
PV = zeros(L,L);
PLD = zeros(L,L);
PRD = zeros(L,L);
for x = 1:Nx
for y = 1:Ny
i = image(x,y);
%%%%%% PH %%%%%%
if (y>1)
j = image(x,y-1);
PH(i+1,j+1) = PH(i+1,j+1) + 1;
end
if (y<Ny)
j = image(x,y+1);
PH(i+1,j+1) = PH(i+1,j+1) + 1;
end
%%%%%% PV %%%%%%
if (x>1)
j=image(x-1,y);
PV(i+1,j+1) = PV(i+1,j+1) +1;
end
if (x<Nx)
j=image(x+1,y);
PV(i+1,j+1) = PV(i+1,j+1) +1;
end
%%%%%% PLD %%%%%%
if ( x>1 && y>1)
j=image(x-1,y-1);
PLD(i+1,j+1) = PLD(i+1,j+1) +1;
end
if ( x<Nx && y<Ny)
j=image(x+1,y+1);
PLD(i+1,j+1) = PLD(i+1,j+1) +1;
end
%%%%%% PRD %%%%%%
if ( x>1 && y<Ny)
j=image(x-1,y+1);
PRD(i+1,j+1) = PRD(i+1,j+1) +1;
end
if ( x<Nx && y>1)
j=image(x+1,y-1);
PRD(i+1,j+1) = PRD(i+1,j+1) +1;
end
end
end
%%%%% Normalizing the Matrices %%%%%%
%PH = PH / (max(max(PH)));
PH = PH /(sum(sum(PH))) ;
PV = PV /(sum(sum(PV))) ;
PLD = PLD /(sum(sum(PLD))) ;
PRD = PRD /(sum(sum(PRD))) ;