-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathestimatemodelparam.m
executable file
·116 lines (92 loc) · 3.93 KB
/
estimatemodelparam.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
function [mu_prisparam cov_prisparam] = estimatemodelparam(folderpath,...
blocksizerow,blocksizecol,blockrowoverlap,blockcoloverlap,sh_th)
% Input
% folderpath - Folder containing the pristine images
% blocksizerow - Height of the blocks in to which image is divided
% blocksizecol - Width of the blocks in to which image is divided
% blockrowoverlap - Amount of vertical overlap between blocks
% blockcoloverlap - Amount of horizontal overlap between blocks
% sh_th - The sharpness threshold level
%Output
%mu_prisparam - mean of multivariate Gaussian model
%cov_prisparam - covariance of multivariate Gaussian model
% Example call
%[mu_prisparam cov_prisparam] = estimatemodelparam('pristine',96,96,0,0,0.75);
%----------------------------------------------------------------
% Find the names of images in the folder
current = pwd;
cd(sprintf('%s',folderpath))
names = ls;
names = names(3:end,:);
cd(current)
% ---------------------------------------------------------------
%Number of features
% 18 features at each scale
featnum = 18;
% ---------------------------------------------------------------
% Make the directory for storing the features
mkdir(sprintf('local_risquee_prisfeatures'))
% ---------------------------------------------------------------
% Compute pristine image features
for itr = 1:size(names,1)
itr
im = imread(sprintf('%s\\%s',folderpath,names(itr,:)));
if(size(im,3)==3)
im = rgb2gray(im);
end
im = double(im);
[row col] = size(im);
block_rownum = floor(row/blocksizerow);
block_colnum = floor(col/blocksizecol);
im = im(1:block_rownum*blocksizerow, ...
1:block_colnum*blocksizecol);
window = fspecial('gaussian',7,7/6);
window = window/sum(sum(window));
scalenum = 2;
warning('off')
feat = [];
for itr_scale = 1:scalenum
mu = imfilter(im,window,'replicate');
mu_sq = mu.*mu;
sigma = sqrt(abs(imfilter(im.*im,window,'replicate') - mu_sq));
structdis = (im-mu)./(sigma+1);
feat_scale = blkproc(structdis,[blocksizerow/itr_scale blocksizecol/itr_scale], ...
[blockrowoverlap/itr_scale blockcoloverlap/itr_scale], ...
@computefeature);
feat_scale = reshape(feat_scale,[featnum ....
size(feat_scale,1)*size(feat_scale,2)/featnum]);
feat_scale = feat_scale';
if(itr_scale == 1)
sharpness = blkproc(sigma,[blocksizerow blocksizecol], ...
[blockrowoverlap blockcoloverlap],@computemean);
sharpness = sharpness(:);
end
feat = [feat feat_scale];
im =imresize(im,0.5);
end
save(sprintf('local_risquee_prisfeatures\\prisfeatures_local%d.mat',...
itr),'feat','sharpness');
end
%----------------------------------------------
% Load pristine image features
prisparam = [];
current = pwd;
cd(sprintf('%s','local_risquee_prisfeatures'))
names = ls;
names = names(3:end,:);
cd(current)
for itr = 1:size(names,1)
% Load the features and select the only features
load(sprintf('local_risquee_prisfeatures\\%s',strtrim(names(itr,:))));
IX = find(sharpness(:) >sh_th*max(sharpness(:)));
feat = feat(IX,:);
prisparam = [prisparam; feat];
end
%----------------------------------------------
% Compute model parameters
mu_prisparam = nanmean(prisparam);
cov_prisparam = nancov(prisparam);
%----------------------------------------------
% Save features in the mat file
save('modelparameters_new.mat','mu_prisparam','cov_prisparam');
%----------------------------------------------