Mercurial > hg > octave-image
changeset 889:ea45a8e63169
maint: Periodic merge of stable to default.
author | Carnë Draug <carandraug@octave.org> |
---|---|
date | Tue, 02 Sep 2014 15:01:16 +0100 |
parents | 33c44c229f74 (current diff) d316de4780ce (diff) |
children | 3d1d76c830c6 |
files | |
diffstat | 5 files changed, 74 insertions(+), 35 deletions(-) [+] |
line wrap: on
line diff
--- a/inst/fftconv2.m +++ b/inst/fftconv2.m @@ -101,41 +101,48 @@ endfunction -%!# usage: fftconv2(a,b,[, shape]) -%!shared a,b +## usage: fftconv2(a,b,[, shape]) +%!test +%! a = repmat (1:10, 5); +%! b = repmat (10:-1:3, 7); +%! assert (fftconv2 (a, b), conv2 (a, b), 1e4*eps) +%! assert (fftconv2 (b, a), conv2 (b, a), 1e4*eps) +%! assert (fftconv2 (a, b, "full"), conv2 (a, b, "full"), 1e4*eps) +%! assert (fftconv2 (b, a, "full"), conv2 (b, a, "full"), 1e4*eps) +%! assert (fftconv2 (a, b, "same"), conv2 (a, b, "same"), 1e4*eps) +%! assert (fftconv2 (b, a, "same"), conv2 (b, a, "same"), 1e4*eps) +%! assert (isempty (fftconv2 (a, b, "valid"))); +%! assert (fftconv2 (b, a, "valid"), conv2 (b, a, "valid"), 1e4*eps) + +## usage: fftconv2(v1, v2, a[, shape]) +%!test +%! x = 1:4; +%! y = 4:-1:1; %! a = repmat(1:10, 5); -%! b = repmat(10:-1:3, 7); -%!assert(norm(fftconv2(a,b)-conv2(a,b)), 0, 1e6*eps) -%!assert(norm(fftconv2(b,a)-conv2(b,a)), 0, 1e6*eps) -%!assert(norm(fftconv2(a,b,'full')-conv2(a,b,'full')), 0, 1e6*eps) -%!assert(norm(fftconv2(b,a,'full')-conv2(b,a,'full')), 0, 1e6*eps) -%!assert(norm(fftconv2(a,b,'same')-conv2(a,b,'same')), 0, 1e6*eps) -%!assert(norm(fftconv2(b,a,'same')-conv2(b,a,'same')), 0, 1e6*eps) -%!assert(isempty(fftconv2(a,b,'valid'))); -%!assert(norm(fftconv2(b,a,'valid')-conv2(b,a,'valid')), 0, 1e6*eps) - -%!# usage: fftconv2(v1, v2, a[, shape]) -%!##FIXME this usage is broken -%!shared x,y,a -%! x = 1:4; y = 4:-1:1; a = repmat(1:10, 5); -%!test assert(norm(fftconv2(x,y,a)-conv2(x,y,a)), 0, 1e6*eps) -%!test assert(norm(fftconv2(x,y,a,'full')-conv2(x,y,a,'full')), 0, 1e6*eps) -%!test assert(norm(fftconv2(x,y,a,'same')-conv2(x,y,a,'same')), 0, 1e6*eps) -%!test assert(norm(fftconv2(x,y,a,'valid')-conv2(x,y,a,'valid')), 0, 1e6*eps) +%! assert (fftconv2 (x, y, a), conv2 (x, y, a), 1e4*eps) +%! assert (fftconv2 (x, y, a, "full"), conv2 (x, y, a, "full"), 1e4*eps) +%! assert (fftconv2 (x, y, a, "same"), conv2 (x, y, a, "same"), 1e4*eps) +%! assert (fftconv2 (x, y, a, "valid"), conv2 (x, y, a, "valid"), 1e4*eps) %!demo %! ## Draw a cross -%! N = 100; -%! [x,y] = meshgrid(-N:N, -N:N); -%! z = 0*x; -%! z(N,1:2*N+1) = 1; z(1:2*N+1, N) = 1; -%! imshow(z); +%! z = zeros (101, 101); +%! z(50, :) = 1; +%! z(:, 50) = 1; +%! subplot (1, 3, 1) +%! imshow (z); +%! title ("Original thin cross") %! %! ## Draw a sinc blob -%! n = floor(N/10); -%! [x,y] = meshgrid(-n:n, -n:n); -%! b = x.^2 + y.^2; b = max(b(:)) - b; b = b / max(b(:)); -%! imshow(b); +%! b = getheight (strel ("ball", 10, 1)); +%! subplot (1, 3, 2) +%! imshow (b); +%! title ("Sync blob") %! %! ## Convolve the cross with the blob -%! imshow(real(fftconv2(z, b, 'same')*N)) +%! fc = real (fftconv2 (z, b, "same")); +%! subplot (1, 3, 3) +%! imshow (fc, [min(fc(:)) max(fc(:))]) +%! title ("Convolution in the frequency domain") + +
--- a/inst/imcrop.m +++ b/inst/imcrop.m @@ -129,7 +129,11 @@ ## use current figure from_fig = true; h = gcf (); - elseif (fnargin == 1 && ishandle (varargin{1})) + ## We check isscalar() because ishandle() accepts arrays of handles, and we + ## check "!= 0" because 0 is and handle for the "root figure" which is + ## invalid for imcrop (see bug #42714). + elseif (fnargin == 1 && isscalar (varargin{1}) + && varargin{1} != 0 && ishandle (varargin{1})) ## use specified figure from_fig = true; h = varargin{1}; @@ -222,3 +226,7 @@ %! assert (nthargout (2, @imcrop, a, rect), rect); %! assert (nthargout ([3 4], 4, @imcrop, a, rect), {a(30:35, 20:23) rect}); +## 0 is the root figure (always true figure handle), so make sure we use +## scalar 0 as image data, not as figure handle. +%!assert (imcrop (0, [0.5 0.5 0.9 0.9]), 0); +%!assert (imcrop (zeros (5), [1 1 1 1]), zeros (2));
--- a/inst/imshear.m +++ b/inst/imshear.m @@ -32,7 +32,7 @@ ## NOTE: @var{alpha} does NOT need to be an integer. ## ## @var{bbox} can be one of 'loose', 'crop' or 'wrap'. -## 'loose' allows the image to grow to accomodate the new transformed image. +## 'loose' allows the image to grow to accommodate the new transformed image. ## 'crop' keeps the same size as the original, clipping any part of the image ## that is moved outside the bounding box. ## 'wrap' keeps the same size as the original, but does not clip the part
--- a/src/bwdist.cc +++ b/src/bwdist.cc @@ -65,7 +65,7 @@ } } - float olddist2, newdist2, newdistx, newdisty; + double olddist2, newdist2, newdistx, newdisty; bool changed; // Initialize index offsets for the current image width @@ -641,5 +641,29 @@ %! assert (dout, dist) %! assert (cout, c) +## The quasi-euclidean method is apparently sensitive to a machine precision +## error that happens in x86 systems only. This test will cause an endless +## loop in case of a regression. +%!test +%! bw = [ 0 1 1 0 0 0 1 0 +%! 0 0 0 0 0 0 0 0 +%! 1 1 0 0 0 0 0 0 +%! 0 0 0 0 0 0 1 0 +%! 0 0 0 0 1 0 0 1 +%! 0 0 0 0 0 0 0 0 +%! 1 0 0 0 0 0 0 0 +%! 0 0 1 0 0 1 1 0]; +%! out = single ([ +%! 1.00000 0.00000 0.00000 1.00000 2.00000 1.00000 0.00000 1.00000 +%! 1.00000 1.00000 1.00000 sqrt(2) sqrt(2)+1 sqrt(2) 1.00000 sqrt(2) +%! 0.00000 0.00000 1.00000 2.00000 2.00000 sqrt(2) 1.00000 sqrt(2) +%! 1.00000 1.00000 sqrt(2) sqrt(2) 1.00000 1.00000 0.00000 1.00000 +%! 2.00000 2.00000 2.00000 1.00000 0.00000 1.00000 1.00000 0.00000 +%! 1.00000 sqrt(2) 2.00000 sqrt(2) 1.00000 sqrt(2) sqrt(2) 1.00000 +%! 0.00000 1.00000 1.00000 sqrt(2) sqrt(2) 1.00000 1.00000 sqrt(2) +%! 1.00000 1.00000 0.00000 1.00000 1.00000 0.00000 0.00000 1.00000 +%! ]); +%! assert (bwdist (bw, "quasi-euclidean"), out); + %!error <unknown METHOD> bwdist (bw, "not a valid method"); */
--- a/src/imerode.cc +++ b/src/imerode.cc @@ -390,7 +390,7 @@ Return image of the same size as input @var{im}.\n\ \n\ @item @qcode{\"full\"}\n\ -Return the full erosion (image is padded to accomodate @var{se} near the\n\ +Return the full erosion (image is padded to accommodate @var{se} near the\n\ borders).\n\ \n\ @item @qcode{\"valid\"}\n\ @@ -704,7 +704,7 @@ Return image of the same size as input @var{im}.\n\ \n\ @item @qcode{\"full\"}\n\ -Return the full dilation (matrix is padded to accomodate @var{se} near the\n\ +Return the full dilation (matrix is padded to accommodate @var{se} near the\n\ borders).\n\ \n\ @item @qcode{\"valid\"}\n\