[1422d3]: / functions / functions_PCANet / PCA_fun / PCA_output.m

Download this file

49 lines (33 with data), 1.6 kB

 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
function [OutImg, OutImgIdx] = PCA_output(InImg, InImgIdx, PatchSize, NumFilters, V)
% Computing PCA filter outputs
% ======== INPUT ============
% InImg Input images (cell structure); each cell can be either a matrix (Gray) or a 3D tensor (RGB)
% InImgIdx Image index for InImg (column vector)
% PatchSize Patch size (or filter size); the patch is set to be sqaure
% NumFilters Number of filters at the stage right before the output layer
% V PCA filter banks (cell structure); V{i} for filter bank in the ith stage
% ======== OUTPUT ===========
% OutImg filter output (cell structure)
% OutImgIdx Image index for OutImg (column vector)
% OutImgIND Indices of input patches that generate "OutImg"
% ===========================
% addpath('./Utils')
%init
ImgZ = length(InImg);
mag = (PatchSize-1)/2;
OutImg = cell(NumFilters*ImgZ,1);
cnt = 0;
for i = 1 : ImgZ
[ImgX, ImgY, NumChls] = size(InImg{i});
img = zeros(ImgX+PatchSize-1,ImgY+PatchSize-1, NumChls);
img((mag+1):end-mag,(mag+1):end-mag,:) = InImg{i};
im = im2col_mean_removal(img, [PatchSize PatchSize]); % collect all the patches of the ith image in a matrix, and perform patch mean removal
for j = 1 : NumFilters
cnt = cnt + 1;
OutImg{cnt} = reshape(V(:,j)'*im,ImgX,ImgY); % convolution output
% t = reshape(V(:,j)'*im,ImgX,ImgY); % convolution output
% OutImg{cnt} = double(efficientLBP(t));
end %for j = 1:NumFilters
InImg{i} = [];
end %for i = 1:ImgZ
OutImgIdx = kron(InImgIdx, ones(NumFilters,1));