-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmbi.m
119 lines (99 loc) · 3.39 KB
/
mbi.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
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
%---------------------------
% mbi algorithm
% input: a RGB 3-channel aerial image
% parameter setting: image size(width & length),
% Window size(the min size,the max size,and the step size)
% output: MBI feature map, a 8-bit gray image
%---------------------------
clear all
%%
%---------------------------------
% parameter settings
%---------------------------------
% image size (width and length)
width=2885;
length=2561;
% window size (min window size, max window size and step size)
step = 5;
Smin = 2;
Smax = 42;
%%
%---------------------------------
% the input of this matlab file
%---------------------------------
I = imread('01RGB.bmp');
%figure(1);
%imshow(I);
%%
%---------------------------------
% step1 the generation of brightness image
%---------------------------------
[col, row, channel] = size(I);
I_r = I(:,:,1);
I_g = I(:,:,2);
I_b = I(:,:,3);
I_final = I(:,:,1);
for i = 1:col
for j = 1:row
I_final(i,j) = max(max(I_r(i,j), I_g(i,j)), I_b(i,j));
%for each pixel, find the max grayvalue among RGB channels
% if it does not look well, consider use hist equalization
end
end
%figure(2);
%imshow(I_final);
%%
%------------
% step two
% note: it just illustrates the basic priciples and is not invovled in the
% algorithm
%------------
% lanmd = 9;
% opening_profile(:,:,1)=open_by_reconstruction(I_final,lanmd);
% Delt_opening_profile(:,:,1)=I_final(:,:,1) - opening_profile(:,:,1);
%%
%--------------
% step three and four
% directional THR and its multi-scale average
%--------------
S = (Smax - Smin) / step + 1;
%SUM = 0;
t = 1;
SUM_opening_profiles1 = uint32(zeros(length,width)); %¿í*³¤
SUM_opening_profiles2 = uint32(zeros(length,width));
SUM_THR = uint32(zeros(length,width));
for s = Smin : step : Smax
for d = 0:45:135
% using the fuction of linear morphological elements
opening_profile_line1(:,:)=open_by_reconstr_line(I_final, s, d);
index = d / 45 + 1;
Delt_opening_profile1(:,:,index)=I_final(:,:) - opening_profile_line1(:,:);
end
SUM_opening_profile1(:,:) = abs(uint32(Delt_opening_profile1(:,:,1)))+abs(uint32(Delt_opening_profile1(:,:,2)))+abs(uint32(Delt_opening_profile1(:,:,3)))+abs(uint32(Delt_opening_profile1(:,:,4)));
mean_opening_profile1(:,:,1) = SUM_opening_profile1(:,:)/4;
% average them
s = s + step;
for d = 0:45:135
% using the fuction of linear morphological elements
opening_profile_line2(:,:)=open_by_reconstr_line(I_final, s, d);
index = d / 45 + 1;
Delt_opening_profile2(:,:,index)=I_final(:,:) - opening_profile_line2(:,:);
end
SUM_opening_profile2(:,:) = abs(uint32(Delt_opening_profile2(:,:,1)))+abs(uint32(Delt_opening_profile2(:,:,2)))+abs(uint32(Delt_opening_profile2(:,:,3)))+abs(uint32(Delt_opening_profile2(:,:,4)));
mean_opening_profile2(:,:,1) = SUM_opening_profile2(:,:)/4;
s = s - step;
THR(:,:,t) = mean_opening_profile2(:,:) - mean_opening_profile1(:,:);
t = t + 1;
end
THR1(:,:) = THR(:,:,1);
THR2(:,:) = THR(:,:,2);
THR3(:,:) = THR(:,:,3);
THR4(:,:) = THR(:,:,4);
SUM_THR(:,:) = abs(THR1(:,:)) + abs(THR2(:,:)) + abs(THR3(:,:)) + abs(THR4(:,:));
BMI(:,:) = SUM_THR(:,:) / 4;
%%
BMI_final = uint8(BMI);
BMI_final = mat2gray(BMI_final);
imwrite(BMI_final,'avrMBI.bmp');
%figure(3);
%imshow(BMI_final);