comparison main/image/inst/findbounds.m @ 11662:fbd81057dab0 octave-forge

image: new spatial transformation functions * maketform: accept input/output control points as second and third argument * imtransform: new function * findsbounds: new function * private/istform: add comment on what function does * NEWS/INDEX: update list of new functions
author carandraug
date Sun, 28 Apr 2013 02:31:13 +0000
parents
children 0f16ee5611b8
comparison
equal deleted inserted replaced
11661:1b4e81051b66 11662:fbd81057dab0
1 ## Copyright (C) 2012 Pantxo Diribarne
2 ##
3 ## This program is free software; you can redistribute it and/or modify
4 ## it under the terms of the GNU General Public License as published by
5 ## the Free Software Foundation; either version 3 of the License, or
6 ## (at your option) any later version.
7 ##
8 ## This program is distributed in the hope that it will be useful,
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 ## GNU General Public License for more details.
12 ##
13 ## You should have received a copy of the GNU General Public License
14 ## along with Octave; see the file COPYING. If not, see
15 ## <http://www.gnu.org/licenses/>.
16
17 ## -*- texinfo -*-
18 ## @deftypefn {Function File} {@var{outbnd} =} findbounds (@var{T}, @var{inbnd})
19 ## Estimate bounds for spatial transformation.
20 ##
21 ## Given a transformation structure @var{T} (see e.g. maketform)
22 ## and bounds @var{inbnd} (2-by-ndims_in) in an input space, returns
23 ## an estimation of the bounds in the output space @var{outbnd}
24 ## (2-by-ndims_out). For instance two dimensionnal bounds could
25 ## be represented as : [xmin ymin; xmax ymax]. If @var{T} does not
26 ## define a forward trasform (i.e. for 'polynomial'), the output
27 ## bounds are infered using fsolve and the inverse transform.
28 ##
29 ## @seealso{maketform, cp2tform, tformfwd}
30 ## @end deftypefn
31
32 ## Author: Pantxo Diribarne <pantxo@dibona>
33
34 function [outbnd] = findbounds (T, inbnd)
35 if (nargin != 2)
36 print_usage ();
37 elseif (! istform (T))
38 error ("imtransform: T must be a transformation structure (see `maketform')");
39 elseif (! all (size (inbnd) == [2 T.ndims_in]))
40 error ("imtransform: INBDN must have same size as T.ndims_in");
41 endif
42
43 ## Control points grid
44 if (columns (inbnd) == 2)
45 [xcp, ycp] = meshgrid (linspace (inbnd(1,1), inbnd(2,1), 3),
46 linspace (inbnd(1,2), inbnd(2,2), 3));
47 xcp = reshape (xcp, numel (xcp), 1);
48 ycp = reshape (ycp, numel (ycp), 1);
49 xycp = [xcp, ycp];
50 else
51 error ("findbounds: support only 2D inputbounds.");
52 endif
53
54 ## Output bounds
55 if (!is_function_handle (T.forward_fcn))
56 outbnd = zeros (size (xycp));
57 for ii = 1:rows (xycp)
58 fun = @(x) tforminv (T, x) - xycp(ii,:);
59 outbnd(ii,:) = fsolve (fun, xycp(ii,:));
60 endfor
61 else
62 outbnd = tformfwd (T, xycp);
63 endif
64 outbnd = [min(outbnd); max(outbnd)];
65 endfunction