-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreate_tensor_patches.m
55 lines (39 loc) · 1.45 KB
/
create_tensor_patches.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
function [tensor_patches] = create_tensor_patches(InImg, PatchSize)
% =======INPUT=============
% InImg Input images (cell structure)
% PatchSize the patch size, asumed to an odd number.
% =======OUTPUT============
% tensor_patches the patches in form of tensors
% =========================
addpath('./Utils')
% to efficiently cope with the large training samples, if the number of training we randomly subsample 10000 the
% training set to learn PCA filter banks
ImgZ = length(InImg);
MaxSamples = 150000;
NumRSamples = min(ImgZ, MaxSamples);
RandIdx = randperm(ImgZ);
RandIdx = RandIdx(1:NumRSamples);
InImg = InImg(RandIdx);
RandIdx = 1:NumRSamples;
%% Learning PCA filters (V)
NumChls = size(InImg{1},3);
tensor_patches = cell(NumRSamples,1);
if(NumChls >1)
tic
parfor i = 1:numel(RandIdx)
im = im2col_mean_removal_tensor(InImg{RandIdx(i)},[PatchSize PatchSize]); % collect all the patches of the ith image in a matrix, and perform patch mean removal
tensor_patches{i} = im;
end
tensor_patches = tensor(cat(1,tensor_patches{:}));
toc
else
tic
length(RandIdx)
parfor i = 1:numel(RandIdx)
im = im2col_mean_removal_tensor2d(InImg{RandIdx(i)},[PatchSize PatchSize]); % collect all the patches of the ith image in a matrix, and perform patch mean removal
tensor_patches{i} = im;
end
tensor_patches = tensor(cat(1,tensor_patches{:}));
toc
end
end