diff --git a/complete.m b/complete.m
index a864fb70725f6b67ab16e1c001d53ed2e529a504..65c3f1bdc3823234a9e0c3e5ec5f2e2614e227b9 100644
--- a/complete.m
+++ b/complete.m
@@ -3,14 +3,30 @@ function [LFRef,LFMask] = complete(LFRef,varargin)
 %   Detailed explanation goes here
 
 LFSize = size(LFRef);
-ImgSize = LFSize(1:3);
-ImgRes  = LFSize(4:end);
+numDims = ndims(LFRef);
+colDims = 1:min(3,numDims);
+rowDims = 4:numDims;
 
-LFRef  = reshape(LFRef,prod(ImgSize),prod(ImgRes));
+p = inputParser; p.StructExpand = true; p.KeepUnmatched = true;
+p.addParameter('colDims', colDims, @isnumeric);
+p.addParameter('rowDims', rowDims, @isnumeric);
+
+p.parse(varargin{:});
+colDims = p.Results.colDims;
+rowDims = p.Results.rowDims;
+
+colSize = LFSize(colDims);
+rowSize = LFSize(rowDims);
+
+LFRef = permute(LFRef,[colDims,rowDims]);
+LFRef = reshape(LFRef,prod(colSize),prod(rowSize));
 
 [LFRef,LFMask] = utils.complete(LFRef,varargin{:});
 
-LFRef  = reshape(LFRef ,[ImgSize,ImgRes]);
-LFMask = reshape(LFMask,[ImgSize,ImgRes]);
+LFRef  = reshape(LFRef  ,[colSize,rowSize]);
+LFMask = reshape(LFMask ,[colSize,rowSize]);
+
+LFRef  = ipermute(LFRef ,[colDims,rowDims]);
+LFMask = ipermute(LFMask,[colDims,rowDims]);
 
 end
\ No newline at end of file
diff --git a/factorize.m b/factorize.m
index 1c71f54d060dab54b84a9a1cad7cfa908f332787..4dff1bc5dcc5db5b52d7307dc3349d11085877e9 100644
--- a/factorize.m
+++ b/factorize.m
@@ -3,13 +3,29 @@ function [LFB,C,U,S,V] = factorize(LFRef,k,varargin)
 %   Detailed explanation goes here
 
 LFSize = size(LFRef);
-ImgSize = LFSize(1:3);
-ImgRes  = LFSize(4:end);
+numDims = ndims(LFRef);
+colDims = 1:min(3,numDims);
+rowDims = 4:numDims;
 
-LFRef  = reshape(LFRef,prod(ImgSize),prod(ImgRes));
+p = inputParser; p.StructExpand = true; p.KeepUnmatched = true;
+p.addParameter('colDims', colDims, @isnumeric);
+p.addParameter('rowDims', rowDims, @isnumeric);
+
+p.parse(varargin{:});
+colDims = p.Results.colDims;
+rowDims = p.Results.rowDims;
+
+colSize = LFSize(colDims);
+rowSize = LFSize(rowDims);
+
+LFRef = permute(LFRef,[colDims,rowDims]);
+LFRef = reshape(LFRef,prod(colSize),prod(rowSize));
+
+rowSize = [k,1];
 
 [LFB,C,U,S,V] = utils.factorize(LFRef,k);
 
-LFB = reshape(LFB ,[ImgSize,k,1]);
+LFB = reshape (LFB,[colSize,rowSize]);
+LFB = ipermute(LFB,[colDims,rowDims]);
 
 end
\ No newline at end of file