| Description of slimginterp |
slimginterp
PURPOSE 
SLIMGINTERP Performs image based interpolation
SYNOPSIS 
function V = slimginterp(A, I, J, interpker)
DESCRIPTION 
CROSS-REFERENCE INFORMATION 
This function calls:
- sladdvec SLADDVEC adds a vector to columns or rows of a matrix
- slgetinterpkernel SLGETINTERPKERNEL Gets the interpolation kernel function
- raise_lackinput RAISE_LACKINPUT Raises an error indicating lack of input argument
This function is called by:
- slresizeimg SLRESIZEIMG Resizes the images by interpolation
SUBFUNCTIONS 
- function V = interp_nn(A, h, w, nc, I, J, s)
- function V = interp_kernel(A, h, w, nc, I, J, s, interpfunc, rad)
- function x = confine_value(x, lb, ub)
- function inds = ij2ind(h, I, J)
- function dxs = get_offsets(r)
- function inds = expand_inds(d, n)
SOURCE CODE 
0001 function V = slimginterp(A, I, J, interpker)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033 if nargin < 3
0034 raise_lackinput('slimginterp', 3);
0035 end
0036
0037 if ~isnumeric(A)
0038 error('sltoolbox:invalidarg', ...
0039 'The image array should be an numeric array');
0040 end
0041 dA = ndims(A);
0042 sA = size(A);
0043 h = sA(1); w = sA(2);
0044
0045 s = size(I);
0046 if ~isequal(size(J), s)
0047 error('sltoolbox:invalidarg', ...
0048 'The sizes of I and J are inconsistent');
0049 end
0050
0051 if dA == 2
0052 nc = 1;
0053 else
0054 nc = prod(sA(3:end));
0055 end
0056
0057 if nargin < 4 || isempty(interpker)
0058 interpker = 'linear';
0059 end
0060 [interpfunc, rad] = slgetinterpkernel(interpker);
0061
0062
0063
0064
0065
0066 if ischar(interpker) && strcmpi(interpker, 'nearest')
0067 V = interp_nn(A, h, w, nc, I, J, s);
0068 else
0069 V = interp_kernel(A, h, w, nc, I, J, s, interpfunc, rad);
0070 end
0071
0072
0073
0074 if dA >= 4
0075 vsiz = [s, sA(3:end)];
0076 V = reshape(V, vsiz);
0077 end
0078
0079
0080
0081 function V = interp_nn(A, h, w, nc, I, J, s)
0082
0083 Ir = round(I);
0084 Jr = round(J);
0085 Ir = confine_value(Ir, 1, h);
0086 Jr = confine_value(Jr, 1, w);
0087 inds = ij2ind(h, Ir, Jr);
0088 clear Ir Jr;
0089
0090 if nc == 1
0091 V = A(inds);
0092 else
0093 inds = inds(:);
0094 A = reshape(A, h*w, nc);
0095 V = A(inds, :);
0096 V = reshape(V, [s, nc]);
0097 end
0098
0099
0100 function V = interp_kernel(A, h, w, nc, I, J, s, interpfunc, rad)
0101
0102 n = numel(I);
0103 If = reshape(I, [1, n]);
0104 Jf = reshape(J, [1, n]);
0105
0106
0107
0108 dxs = get_offsets(rad)';
0109 nnb = 2 * rad;
0110 Iu = floor(If);
0111 Ju = floor(Jf);
0112 Iu = Iu(ones(nnb, 1), :);
0113 Ju = Ju(ones(nnb, 1), :);
0114 Iu = sladdvec(Iu, dxs, 1);
0115 Ju = sladdvec(Ju, dxs, 1);
0116
0117
0118
0119 Di = sladdvec(Iu, -If, 2);
0120 Dj = sladdvec(Ju, -Jf, 2);
0121 clear If Jf;
0122 Wi = interpfunc(Di);
0123 clear Di;
0124 Wj = interpfunc(Dj);
0125 clear Dj;
0126
0127
0128
0129 Iu = confine_value(Iu, 1, h);
0130 Ju = confine_value(Ju, 1, w);
0131
0132
0133 inds_i = expand_inds(1, nnb);
0134 inds_j = expand_inds(2, nnb);
0135 Wi = Wi(inds_i, :);
0136 Wj = Wj(inds_j, :);
0137 Iu = Iu(inds_i, :);
0138 Ju = Ju(inds_j, :);
0139
0140 W = Wi .* Wj;
0141 clear Wi Wj;
0142 Inds = ij2ind(h, Iu, Ju);
0143 clear Iu Ju;
0144
0145
0146
0147 if nc == 1
0148 M = A(Inds);
0149 clear Inds;
0150 V = sum(M .* W, 1);
0151 V = reshape(V, s);
0152 else
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165 V = zeros(1, prod(s), nc);
0166 for i = 1 : nc
0167 curA = A(:,:,i);
0168 M = curA(Inds);
0169 curV = sum(M .* W, 1);
0170 V(:,:,i) = curV;
0171 end
0172 V = reshape(V, [s, nc]);
0173
0174 end
0175
0176
0177
0178
0179
0180 function x = confine_value(x, lb, ub)
0181
0182 x(x < lb) = lb;
0183 x(x > ub) = ub;
0184
0185 function inds = ij2ind(h, I, J)
0186
0187 inds = I + h * (J - 1);
0188
0189 function dxs = get_offsets(r)
0190
0191 if r == floor(r)
0192 dxs = -(r-1) : r;
0193 else
0194 error('sltoolbox:rterror', 'The effective radius should be integer');
0195 end
0196
0197 function inds = expand_inds(d, n)
0198
0199 if d == 1
0200 inds = (1:n)';
0201 inds = inds(:, ones(1,n));
0202 inds = inds(:);
0203 elseif d == 2
0204 inds = 1:n;
0205 inds = inds(ones(n,1), :);
0206 inds = inds(:);
0207 end
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217
Generated on Wed 20-Sep-2006 12:43:11 by m2html © 2003
|
|