Mentions légales du service

Skip to content
Snippets Groups Projects
Commit f1966ce7 authored by DIB Elian's avatar DIB Elian
Browse files

Created convenience function

Created convenience function for encoding light fields and corresponding example script
parent 65331327
No related branches found
No related tags found
No related merge requests found
function [frames,framesConv,framesConvRec] = encodeLF(LF,name,ConfigFile,varargin) function [frames,framesRef,framesRec] = encodeLF(LF,name,varargin)
%ENCODELF Summary of this function goes here %ENCODELF Summary of this function goes here
% Detailed explanation goes here % Detailed explanation goes here
colSpaces = {'yuv','ycbcr','lab','hsv','rgb'}; colSpaces = {'yuv','ycbcr','lab','hsv','rgb'};
subSamps = {'420','444','422','400'}; subSamps = {'420','444','422','400'};
precisions = {'uint8','uint16','uint32','uint64'... precisions = {'uint8','uint16','uint32','uint64',...
'int8','int16','int32','int64',... 'int8', 'int16', 'int32', 'int64',...
'single','double'}; 'single','double'};
p = inputParser; % Create input parser scheme
p.addRequired ('LF' ,@isnumeric); params = inputParser;
p.addRequired ('name' ,@ischar); params.StructExpand = true;
p.addRequired ('ConfigFile' ,@ischar); params.KeepUnmatched = true;
p.addParameter('colSpace' ,colSpaces{1} ,@(x) any(validatestring(x,colSpaces))); params.addParameter('colSpace' ,colSpaces{1} ,@(x) any(validatestring(x,colSpaces )));
p.addParameter('subSamp' ,subSamps{1} ,@(x) any(validatestring(x,subSamps) )); params.addParameter('subSamp' ,subSamps{1} ,@(x) any(validatestring(x,subSamps )));
p.addParameter('precision',precisions{1},@(x) any(validatestring(x,precisions))); params.addParameter('precision' ,precisions{1},@(x) any(validatestring(x,precisions)));
p.addParameter('subName' ,'_rec' ,@ischar);
p.parse(LF,name,ConfigFile,varargin{:}); % Parse arguments
%LF = p.Results.LF; params.parse(varargin{:});
%name = p.Results.name;
%ConfigFile = p.Results.name;
colSpace = p.Results.colSpace;
subSamp = p.Results.subSamp;
precision = p.Results.precision;
subName = p.Results.subName;
frames = LFToFrames(LF);
[imgRes,imgSize,framesConv] = yuv.write(frames,name,...
'colSpace',colSpace,...
'subSamp',subSamp,...
'precision',precision);
[InputFile,BitstreamFile,ReconFile,LogFile,... yuvParams = params.Results;
SourceWidth,SourceHeight,... extraParams = params.Unmatched;
FramesToBeEncoded,InputChromaFormat]...
= extractHEVCParams(name,colSpace,subSamp,subName);
HEVC.encode(ConfigFile,... if isfield(extraParams,'InputChromaFormat')
'InputFile',InputFile,... ICF = extraParams.InputChromaFormat;
'BitstreamFile',BitstreamFile,... SS = yuvParams.subSamp;
'ReconFile',ReconFile,... if ~strcmp(ICF,SS)
'LogFile',LogFile,... warning(['Conflicting SubSamp and InputChromaFormat parameters',...
'SourceWidth',SourceWidth,... ' , choosing InputChromaFormat']);
'SourceHeight',SourceHeight,... yuvParams.subSamp = ICF;
'FramesToBeEncoded',FramesToBeEncoded,... end
'InputChromaFormat',InputChromaFormat); end
framesConvRec = yuv.read(name,imgRes,imgSize,... % Change 5D LF to a collection of 2D frames
'colSpace',colSpace,... frames = LFToFrames(LF);
'subSamp',subSamp,...
'precision',precision,...
'subName',subName);
% Convert each frame according to given parameters
framesRef = yuv.convert(frames,yuvParams);
% Write frames as a YUV sequence
[imgRes,imgSize] = yuv.write(framesRef,name,yuvParams,'subName','_ref');
% Convert inputs for HEVC
HEVCparams = extractHEVCParams(name,yuvParams);
% Encode frames using HEVC
HEVC.encode(HEVCparams,extraParams);
% Recover frames
framesRec = yuv.read(name,imgRes,imgSize,yuvParams,'subName','_rec');
%% %% Auxiliary functions
function frames = LFToFrames(LF) function frames = LFToFrames(LF)
s = size(LF); s = size(LF);
frames = mat2cell(LF,ones(1,s(1)),ones(1,s(2)),s(3),s(4),s(5)); frames = mat2cell(LF,ones(1,s(1)),ones(1,s(2)),s(3),s(4),s(5));
end end
function LF = frames2LF(frames) function params = extractHEVCParams(name,yuvParams)
end colSpace = yuvParams.colSpace;
subSamp = yuvParams.subSamp;
function [InputFile,BitstreamFile,ReconFile,LogFile,...
SourceWidth,SourceHeight,...
FramesToBeEncoded,InputChromaFormat] = extractHEVCParams...
(name,colSpace,subSamp,subName)
resCell = num2cell(imgRes); resCell = num2cell(imgRes);
sizeCell = num2cell(imgSize); sizeCell = num2cell(imgSize);
fullName = [resCell,sizeCell]; fullName = [resCell,sizeCell];
fullName = cellfun(@num2str,fullName,'UniformOutput',false); fullName = cellfun(@num2str,fullName,'UniformOutput',false);
fullName = strjoin([name fullName subSamp],'_'); fullName = strjoin([name fullName subSamp],'_');
InputFile = [fullName, '.',colSpace]; params.InputFile = [fullName,'_ref','.',colSpace];
BitstreamFile = [fullName, '.','hevc' ]; params.BitstreamFile = [fullName, '.','hevc' ];
ReconFile = [fullName,subName,'.',colSpace]; params.ReconFile = [fullName,'_rec','.',colSpace];
LogFile = [fullName, '.','rtf' ]; params.LogFile = [fullName, '.','rtf' ];
SourceWidth = num2str(imgSize(2)); params.SourceWidth = num2str(imgSize(2));
SourceHeight = num2str(imgSize(1)); params.SourceHeight = num2str(imgSize(1));
FramesToBeEncoded = num2str(prod(imgRes)); params.FramesToBeEncoded = num2str(prod(imgRes));
InputChromaFormat = num2str(subSamp); params.InputChromaFormat = num2str(subSamp);
end end
end end
clear all, close all, clc
%%
LFDir = 'C:\Users\edib\Light Fields\Heidelberg\full_data\test';
name = 'bedroom';
%%
load(fullfile(LFDir,name,'LF.mat'));
LF = LF.LF;
%%
s = size(LF);
colSpace = 'yuv';
subSamp = '400';
subName = '_rec';
precision = 'uint8';
params.FramesToBeEncoded = num2str(1);
params.InputChromaFormat = num2str(subSamp);
params.QP = num2str(0);
params.colSpace = colSpace;
params.subSamp = num2str(subSamp);
params.precision = precision;
%%
[frames,convFramesRef,subFramesRec] = HEVC.encodeLF(LF,name,params);
%%
HEVC.encode(params);
%%
testHEVC = HEVC.HEVC(params);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment