forked from pdollar/toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
subsToArray.m
33 lines (31 loc) · 1.04 KB
/
subsToArray.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
function I = subsToArray( subs, vals, siz, fillVal )
% Converts subs/vals image representation to array representation.
%
% Constructs array from subs/vals representation. Similar to Matlab's
% sparse command, except doesn't actually produce a sparse matrix. Uses
% different conventions as well.
%
% USAGE
% I = subsToArray( subs, vals, siz, [fillVal] )
%
% INPUTS
% subs - subscripts of point locations (n x d)
% vals - values at point locations (n x 1)
% siz - image size vector (1xd) - must fully contain subs
% fillVal - [0] value to fill array with at nonspecified locs
%
% OUTPUTS
% I - array of size siz
%
% EXAMPLE
%
% See also SUB2IND2, SPARSE
%
% Piotr's Image&Video Toolbox Version 2.0
% Copyright 2008 Piotr Dollar. [pdollar-at-caltech.edu]
% Please email me if you find bugs, or have suggestions or questions!
% Licensed under the Lesser GPL [see external/lgpl.txt]
if( nargin<4 || isempty(fillVal) ); fillVal=0; end
inds = sub2ind2( siz, subs );
I = repmat( fillVal, siz );
I(inds) = vals;