-
Notifications
You must be signed in to change notification settings - Fork 1
/
RandomWalk_NoisyImages.m
112 lines (55 loc) · 2.57 KB
/
RandomWalk_NoisyImages.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
function RandomWalk_NoisyImages(Image_Dataset_Path,Image_CNNPath,Noisy_Image_Dataset_Path)
%AL: This code perform randowm walk over the CNN features of images, we
%remove images which are less consistant with rest of images.
AllActions=dir(Image_CNNPath);
AllActions=AllActions(3:end);
AllActions_Image=dir(Image_Dataset_Path);
AllActions_Image=AllActions_Image(3:end);
for iaction=1:length(AllActions)
fprintf('Action (%d/%d) done\n', iaction, numel(AllActions));
ActionPath=[Image_CNNPath,'/',AllActions(iaction).name];
ActionImagePath=[Image_Dataset_Path,'/',AllActions_Image(iaction).name];
NoisyImagePath=[Noisy_Image_Dataset_Path,'/',AllActions_Image(iaction).name];
if ~exist(NoisyImagePath,'dir')
mkdir(NoisyImagePath);
end
All_files=dir(ActionPath);
All_files=All_files(3:end);
All_features=zeros(length(All_files),4096);
for im=1:length(All_files)
Pfilename=[ActionPath,'/',All_files(im).name];
load(Pfilename)
All_features(im,:)=res/sum(res);
end
%% You can change the parameters of random walk, number of Iteration and may get better results.
dist_Mat=distance(All_features',All_features');
sim_mat=exp(-100*dist_Mat);
for col=1:size(sim_mat,2)
sim_mat(:,col)=sim_mat(:,col)/sum(sim_mat(:,col));
end
init_scores=ones(size(sim_mat,2),1)/size(sim_mat,2);
relevance_scores=init_scores;
alpha=0.99;
for it=1:1000
%curr_score=alpha*Transition_Matrix* prev_score+(1-alpha)*prev_assign;
New_relevance_scores=alpha*(sim_mat*relevance_scores)+(1-alpha)*init_scores;
relevance_scores=New_relevance_scores;
end
all_dist=sum(dist_Mat);
[val,idx]=sort(all_dist);
[val,idx]=sort(relevance_scores,'descend');
% We remove 30% of images. You can change this parameter.
per_remove_image=0.3;
ss=length(idx);
ss_idx=ss-round(ss*per_remove_image);
idx=idx(ss_idx:end);
ss=length(idx);
for ii=1:length(idx)
Im_Path=[ActionImagePath,'/',All_files(idx(ii)).name(1:end-4),'.jpg'];
N_Path =[NoisyImagePath,'/',All_files(idx(ii)).name(1:end-4),'.jpg'];
if ~exist(N_Path,'file')
movefile(Im_Path,N_Path);
end
% subplot(round(ss/10),10,ii); imshow(I)
end
end