1
+ function feat = extract_feat_constituent(constituent_im ,patch_size )
2
+
3
+ % function to extract features of PIQE framework for constituent images
4
+
5
+ for k = 1 : length(constituent_im )
6
+ [c_x{k },c_y{k }] = extract_patch(constituent_im{k },patch_size );
7
+ end
8
+
9
+ % Steerable Pyramid Decomposition
10
+ Nor = 6 ; % number of orientations
11
+ scale = 2 ; % number of scales
12
+ sig = 0.1 ; % sigma for patch weighting non-linearity
13
+
14
+ patch_sel_c_h = [];patch_sel_c_v = [];
15
+
16
+ disp(' Extracting features of Marginal Distribution for constituent images....' );
17
+ for k = 1 : length(constituent_im )
18
+ sz = length(patch_sel_c_h );
19
+ parfor t = 1 : length(c_x{k })
20
+ block_im = rgb2gray(constituent_im{k }(c_x{k }(t ,1 ): c_x{k }(t ,2 ),c_y{k }(t ,1 ): c_y{k }(t ,2 ),: ));
21
+
22
+ % Steerable pyramid decomposition
23
+ [pyr_c{k ,t },pind_c{k ,t }] = buildSFpyr(double(block_im ),scale ,Nor - 1 );
24
+
25
+ % GSM based divisive normalization and fitting marginal distribution using GGD
26
+ marginal_c{sz + t } = marginal_est(pyr_c{k ,t },pind_c{k ,t },scale ,Nor ,1 ,1 ,3 ,3 ,50 );
27
+
28
+ % values for patch weighting
29
+ % Horizontal neighbors
30
+
31
+ du = zeros(13 ,13 ); % 13 quantization levels
32
+ quant_im = floor(double(block_im )/21 )+1 ;
33
+ [glcm_constituent ,SI ] = graycomatrix(quant_im ,' Offset' ,[0 ,1 ],' NumLevels' ,...
34
+ max(quant_im(: )) - min(quant_im(: )) + 1 ,' GrayLimits' ,[min(quant_im(: )) max(quant_im(: ))]);
35
+ du(min(quant_im(: )): max(quant_im(: )),min(quant_im(: )): max(quant_im(: ))) = glcm_constituent ;
36
+ stats = graycoprops(du ,' Energy' );
37
+ patch_sel_c_h(sz + t ) = 1 - stats .Energy ; % weight = 1 - energy
38
+ patch_sel_c_h(sz + t ) = non_lin_fn(patch_sel_c_h(sz + t ),sig ); % non_linearity
39
+
40
+ % Vertical Neighbors
41
+ du = zeros(13 ,13 ); % 13 quantization levels
42
+ [glcm_constituent ,SI ] = graycomatrix(quant_im ,' Offset' ,[1 ,0 ],' NumLevels' ,...
43
+ max(quant_im(: )) - min(quant_im(: )) + 1 ,' GrayLimits' ,[min(quant_im(: )) max(quant_im(: ))]);
44
+ du(min(quant_im(: )): max(quant_im(: )),min(quant_im(: )): max(quant_im(: ))) = glcm_constituent ;
45
+ stats = graycoprops(du ,' Energy' );
46
+ patch_sel_c_v(sz + t ) = 1 - stats .Energy ; % weight = 1 - energy;
47
+ patch_sel_c_v(sz + t ) = non_lin_fn(patch_sel_c_v(sz + t ),sig ); % non_linearity
48
+ end
49
+ end
50
+
51
+ % concatenation
52
+ sz = length(c_x{1 });
53
+ for k = 2 : length(constituent_im )
54
+ pyr_c(1 ,sz + 1 : sz + length(c_x{k })) = pyr_c(k ,1 : length(c_x{k }));
55
+ pind_c(1 ,sz + 1 : sz + length(c_x{k })) = pind_c(k ,1 : length(c_x{k }));
56
+ sz = size(pyr_c ,2 );
57
+ end
58
+ pyr_c(2 : end ,: ) = [];pind_c(2 : end ,: ) = [];
59
+
60
+ % patch weights
61
+ wx = patch_sel_c_h ' ;wy = patch_sel_c_v ' ;
62
+ wx = repmat(wx ,1 ,12 );wy = repmat(wy ,1 ,12 );
63
+
64
+ % steerable features weighted averaging
65
+ wt = wx ' ;
66
+ g_shape = [];
67
+
68
+ parfor p = 1 : length(marginal_c )
69
+ if (~isempty(marginal_c{p }))
70
+ g_shape(: ,p ) = marginal_c{p }(1 : 12 ); % shape parameters of ggd
71
+ else
72
+ g_shape(: ,p ) = - 1 * ones(12 ,1 );
73
+ end
74
+ end
75
+
76
+ g_shape = g_shape .* wt ;
77
+ ft_marginal_c = sum(g_shape ,2 )/sum(wt(1 ,: ));
78
+
79
+ % patches with non-zero weights
80
+ ix = find(patch_sel_c_h > 0);iy = find(patch_sel_c_v > 0);
81
+
82
+ % Bivariste GMM fit
83
+ disp(' Extracting features of Bivariate Distribution for constituent images....' );
84
+ sc = scale - 1 ;
85
+ for orien = 1 : Nor
86
+ op = 2 * orien - 1 : 2 * orien ;
87
+ nband = (sc - 1 )*Nor + orien + 1 ;
88
+ parfor t = 1 : min(length(ix ),length(iy ))
89
+ aux_m = pyrBand(pyr_c{ix(t )}, pind_c{ix(t )}, nband );
90
+ aux_h = find_neighbor(aux_m ,1 ); % Horizontal neighbors
91
+
92
+ Xh = [aux_h{1 }(: ) - mean(aux_h{1 }(: )), aux_h{2 }(: ) - mean(aux_h{2 }(: ))];
93
+ joint_cx(t ,op ) = gmm_eig(Xh ,4 ,2 ,35 );
94
+
95
+ aux_m = pyrBand(pyr_c{iy(t )}, pind_c{iy(t )}, nband );
96
+ aux_v = find_neighbor(aux_m ,3 ); % Vertical neighbors
97
+
98
+ Xv = [aux_v{1 }(: ) - mean(aux_v{1 }(: )), aux_v{2 }(: ) - mean(aux_v{2 }(: ))];
99
+ joint_cy(t ,op ) = gmm_eig(Xv ,4 ,2 ,35 );
100
+ end
101
+ end
102
+
103
+ it = length(ix ) >= length(iy );
104
+ switch it
105
+ case 1
106
+ for orien = 1 : Nor
107
+ op = 2 * orien - 1 : 2 * orien ;
108
+ nband = (sc - 1 )*Nor + orien + 1 ;
109
+ parfor t = length(iy )+1 : length(ix )
110
+ aux_m = pyrBand(pyr_c{ix(t )}, pind_c{ix(t )}, nband );
111
+ aux_h = find_neighbor(aux_m ,1 ); % Horizontal neighbors
112
+
113
+ Xh = [aux_h{1 }(: ) - mean(aux_h{1 }(: )), aux_h{2 }(: ) - mean(aux_h{2 }(: ))];
114
+ joint_cx(t ,op ) = gmm_eig(Xh ,4 ,2 ,35 );
115
+ end
116
+ end
117
+ case 0
118
+ for orien = 1 : Nor
119
+ op = 2 * orien - 1 : 2 * orien ;
120
+ nband = (sc - 1 )*Nor + orien + 1 ;
121
+ parfor t = length(ix )+1 : length(iy )
122
+ aux_m = pyrBand(pyr_c{iy(t )}, pind_c{iy(t )}, nband );
123
+ aux_v = find_neighbor(aux_m ,3 ); % Vertical neighbors
124
+
125
+ Xv = [aux_v{1 }(: ) - mean(aux_v{1 }(: )), aux_v{2 }(: ) - mean(aux_v{2 }(: ))];
126
+ joint_cy(t ,op ) = gmm_eig(Xv ,4 ,2 ,35 );
127
+ end
128
+ end
129
+ end
130
+
131
+ joint_c_avex = zeros(size(wx ));joint_c_avey = zeros(size(wy ));
132
+ joint_c_avex(ix ,: ) = joint_cx ;joint_c_avey(ix ,: ) = joint_cy ;
133
+
134
+ % square root of eigen values
135
+ joint_c_avex = sqrt(joint_c_avex .*(wx .^ 2 ));joint_c_avey = sqrt(joint_c_avey .*(wy .^ 2 ));
136
+ joint_featx = sum(joint_c_avex ,1 )' /sum(wx(: ,1 ));joint_featy = sum(joint_c_avey ,1 )' /sum(wy(: ,1 ));
137
+
138
+ feat = [ft_marginal_c ;joint_featx ;joint_featy ];
0 commit comments