-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert_to_tensor.m
31 lines (24 loc) · 922 Bytes
/
convert_to_tensor.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
function [tensor_patches] = convert_to_tensor(patch, PatchSize, NumChnls)
% =======INPUT=============
% patch Image patches
% shape Shape of the patch
% NumChnls Number of Channels
% =======OUTPUT============
% tensor_patches Patches converted into tensor
% =========================
K = size(patch,2);
if (NumChnls >1)
tensor_patches = zeros(K,PatchSize,PatchSize,3);
parfor j=1:K
A = zeros(PatchSize, PatchSize, 3);
A(:,:,1)=reshape(patch(1:PatchSize^2,j),PatchSize,PatchSize);
A(:,:,2)=reshape(patch(PatchSize^2+1:2*PatchSize^2,j),PatchSize,PatchSize);
A(:,:,3)=reshape(patch(2*PatchSize^2+1:end,j),PatchSize,PatchSize);
tensor_patches(j, : ,:,:) = A;
end
else
tensor_patches = zeros(K,PatchSize,PatchSize);
parfor j=1:K
tensor_patches(j,:,:)=reshape(patch(:,j),PatchSize,PatchSize);
end
end