Mercurial > forge
changeset 11670:0f16ee5611b8 octave-forge
image: add tests to findbounds and imtransform. Patch by Pantxo Diribarne <pantxo@dibona>
author | carandraug |
---|---|
date | Mon, 29 Apr 2013 12:53:23 +0000 |
parents | 8db5e2631b23 |
children | c5116717efd1 |
files | main/image/inst/findbounds.m main/image/inst/imtransform.m |
diffstat | 2 files changed, 62 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/main/image/inst/findbounds.m Sun Apr 28 15:25:12 2013 +0000 +++ b/main/image/inst/findbounds.m Mon Apr 29 12:53:23 2013 +0000 @@ -63,3 +63,15 @@ endif outbnd = [min(outbnd); max(outbnd)]; endfunction + +%!test +%! im = checkerboard (); +%! theta = pi/6; +%! T = maketform ('affine', [cos(theta) -sin(theta); ... +%! sin(theta) cos(theta); 0 0]); +%! inbnd = [0 0; 1 1]; +%! outbnd = findbounds (T, inbnd); +%! diag = 2^.5; +%! ang = pi/4; +%! assert (diff (outbnd(:,1)), diag * abs (cos (theta - ang)), eps) +%! assert (diff (outbnd(:,2)), diag * abs (cos (theta - ang)), eps)
--- a/main/image/inst/imtransform.m Sun Apr 28 15:25:12 2013 +0000 +++ b/main/image/inst/imtransform.m Mon Apr 29 12:53:23 2013 +0000 @@ -18,6 +18,7 @@ ## @deftypefn {Function File} {@var{B} =} imtransform (@var{A}, @var{T}) ## @deftypefnx {Function File} {@var{B} =} imtransform (@var{A}, @var{T}, @var{interp}) ## @deftypefnx {Function File} {@var{B} =} imtransform (@dots{}, @var{prop}, @var{val}) +## @deftypefnx {Function File} {[@var{B}, @var{xdata}, @var{ydata}] =} imtransform (@dots{}) ## Transform image. ## ## Given an image @var{A} in one space, returns an image @var{B} @@ -66,10 +67,11 @@ ## the input space. @var{val} must be coherent with the input image ## format: for grayscale and indexed images (2D) @var{val} must be ## scalar, for RGB (n-by-m-by-3) @var{val} must be a 3 element vector. -## e.g.: -## +## ## @end table ## +## The actual output limits, @var{xdata} and @var{ydata} vectors, +## are returned respectively as second and third output variables. ## @seealso{maketform, cp2tform, tforminv, tformfwd, findbounds} ## @end deftypefn @@ -184,7 +186,6 @@ else xyscale = [(diff (udata) / columns (im)) (diff (vdata) / rows (im))]; endif - ## Fillvalues tst = strcmp ("fillvalues", props); if (any (tst)) @@ -198,7 +199,7 @@ endif endif endif - + ## Ouput/Input pixels if (isempty (imsize)) if (isempty (xyscale)) @@ -348,3 +349,48 @@ %! 'vdata', [-1 1], 'fillvalues', %! round (length (cmap) / 2)); %! imh = imshow (im2, cmap); + +%!test +%! im = checkerboard (); +%! incp = [0 0; 0 1; 1 1]; +%! scl = 10; +%! outcp = scl * incp; +%! T = maketform ('affine', incp, outcp); +%! [im2 xdata ydata] = imtransform (im, T, 'udata', [0 1], +%! 'vdata', [0 1], 'size', [500 500]); +%! assert (xdata, scl * ([0; 1])) +%! assert (ydata, scl * ([0; 1])) +%! assert (size (im2), [500 500]) + +%!test +%! im = checkerboard (); +%! incp = [0 0; 0 1; 1 1]; +%! scl = 10; +%! outcp = scl * incp; +%! xyscale = scl; +%! T = maketform ('affine', incp, outcp); +%! [im2 xdata ydata] = imtransform (im, T, 'xyscale', xyscale); +%! assert (size (im2), size (im), 1) + +%!test +%! im = checkerboard (100, 10, 4); +%! theta = 2 * pi; +%! T = maketform ('affine', [cos(theta) -sin(theta); ... +%! sin(theta) cos(theta); 0 0]); +%! im2 = imtransform (im, T, 'nearest'); +%! im = im(2:end-1, 2:end-1); %avoid boundaries +%! im2 = im2(2:end-1, 2:end-1); +%! assert (im, im2) + +%!test +%! im = checkerboard (20, 10, 4); +%! theta = pi/6; +%! T = maketform ('affine', [cos(theta) -sin(theta); ... +%! sin(theta) cos(theta); 0 0]); +%! [im2 xdata ydata] = imtransform (im, T); +%! udata = [1 columns(im)]; +%! vdata = [1 rows(im)]; +%! diag = sqrt (udata(2)^2 + vdata(2)^2); +%! ang = atan (vdata(2) / udata(2)); +%! assert (max (abs (xdata)), diag * abs (cos (theta - ang)), +%! max (size (im)) * eps)