Mercurial > hg > octave-image
changeset 837:f17bab055e35
Fix several warnings and errors on tests.
* applylut.m, imadjust.m, imrotate.m : remove \ as continuation markers
in %! test blocks, use 2 argument call to assert, adn create function
handles instead of using inline().
* bweuler.m: use isbw (im, "non-logical").
* imsubtract.m: add check for warning about requesting signed integer
results for unsigned input.
* imresize.m: remove unecessary %!shared block and use normal %!test.
* imerode.cc: fix call to convn with shape "same" to compare results.
author | Carnë Draug <carandraug@octave.org> |
---|---|
date | Tue, 12 Nov 2013 02:36:37 +0000 |
parents | 8d944199b605 |
children | dbe605c10a08 |
files | inst/applylut.m inst/bweuler.m inst/imadjust.m inst/imresize.m inst/imrotate.m inst/imsubtract.m src/imerode.cc |
diffstat | 7 files changed, 48 insertions(+), 44 deletions(-) [+] |
line wrap: on
line diff
--- a/inst/applylut.m +++ b/inst/applylut.m @@ -48,7 +48,11 @@ %! disp (S) %! ## Everything should be 0 despite a diagonal which doesn't reach borders. -%!assert(prod(applylut(eye(3),makelut(inline('x(1,1)==1','x'),2))==eye(3))==1); % 2-by-2 test -%!assert(prod(applylut(eye(3),makelut(inline('x(2,2)==1','x'),3))==eye(3))==1); % 3-by-3 test -%!assert(prod(applylut(eye(3),makelut(inline('x(3,3)==1','x'),3))== \ -%! applylut(eye(3),makelut(inline('x(2,2)==1','x'),2)))==1); +## 2-by-2 test +%!assert (prod (applylut (eye (3), makelut (@(x) x(1) == 1, 2)) == eye (3)), [1 1 1]); + +## 3-by-3 test +%!assert (prod (applylut (eye (3), makelut (@(x) x(2,2) == 1, 3)) == eye (3)), [1 1 1]); +%!assert (prod (applylut (eye (3), makelut (@(x) x(3,3) == 1, 3)) == +%! applylut (eye (3), makelut (@(x) x(2,2) == 1, 2))), +%! [1 1 1]);
--- a/inst/bweuler.m +++ b/inst/bweuler.m @@ -37,7 +37,7 @@ function eul = bweuler (BW, n = 8) if (nargin < 1 || nargin > 2) print_usage; - elseif (!isbw (BW)) + elseif (!isbw (BW, "non-logical")) error("first argument must be a Black and White image"); endif
--- a/inst/imadjust.m +++ b/inst/imadjust.m @@ -220,19 +220,19 @@ %!assert(imadjust([1:100]),[0,linspace(0,1,98),1]); %!# test with only input arg -%!assert(sum(abs((imadjust(linspace(0,1,100),[1/99;98/99]) - \ +%!assert(sum(abs((imadjust(linspace(0,1,100),[1/99;98/99]) - %! [0,linspace(0,1,98),1] )(:))) < 1e-10); %!# a test with input and output args -%!assert(imadjust([1:100],[50;90],[-50;-30]), \ +%!assert(imadjust([1:100],[50;90],[-50;-30]), %! [-50*ones(1,49), linspace(-50,-30,90-50+1), -30*ones(1,10)]); %!# a test with input and output args in a row vector (Compatibility behaviour) -%!assert(imadjust([1:100],[50,90],[-50,-30]), \ +%!assert(imadjust([1:100],[50,90],[-50,-30]), %! [-50*ones(1,49), linspace(-50,-30,90-50+1), -30*ones(1,10)]); %!# the previous test, "negated" -%!assert(imadjust([1:100],[50;90],[-30;-50]), \ +%!assert(imadjust([1:100],[50;90],[-30;-50]), %! [-30*ones(1,49), linspace(-30,-50,90-50+1), -50*ones(1,10)]); %!shared cm,cmn @@ -249,27 +249,27 @@ %!assert(imadjust(cmn,[0;1],[10,20,30;11,21,31]),cmn+repmat([10,20,30],10,1)); %!# a colormap, different input on each, we need increased tolerance for this test -%!assert(sum(abs((imadjust(cm,[2,4,6;7,9,11],[0;1]) - \ -%! [[0,linspace(0,1,6),1,1,1]', \ -%! [0,0,linspace(0,1,6),1,1]', \ -%! [0,0,0,linspace(0,1,6),1]'] \ -%! ))(:)) < 1e-10 \ +%!assert(sum(abs((imadjust(cm,[2,4,6;7,9,11],[0;1]) - +%! [[0 linspace(0, 1, 6) 1 1 1]' ... +%! [0 0 linspace(0, 1, 6) 1 1]' ... +%! [0 0 0 linspace(0, 1, 6) 1]'] +%! ))(:)) < 1e-10 %! ); %!# a colormap, different input and output on each -%!assert(sum(abs((imadjust(cm,[2,4,6;7,9,11],[0,1,2;1,2,3]) - \ -%! [[0,linspace(0,1,6),1,1,1]', \ -%! [0,0,linspace(0,1,6),1,1]'+1, \ -%! [0,0,0,linspace(0,1,6),1]'+2] \ -%! ))(:)) < 1e-10 \ +%!assert(sum(abs((imadjust(cm,[2,4,6;7,9,11],[0,1,2;1,2,3]) - +%! [[0 linspace(0, 1, 6) 1 1 1]' ... +%! [0 0 linspace(0, 1, 6) 1 1]'+1, ... +%! [0 0 0 linspace(0, 1, 6) 1]'+2] +%! ))(:)) < 1e-10 %! ); %!# a colormap, different gamma, input and output on each -%!assert(sum(abs((imadjust(cm,[2,4,6;7,9,11],[0,1,2;1,2,3],[1,2,3]) - \ -%! [[0,linspace(0,1,6),1,1,1]', \ -%! [0,0,linspace(0,1,6).^2,1,1]'+1, \ -%! [0,0,0,linspace(0,1,6).^3,1]'+2] \ -%! )(:))) < 1e-10 \ +%!assert(sum(abs((imadjust(cm,[2,4,6;7,9,11],[0,1,2;1,2,3],[1,2,3]) - +%! [[0 linspace(0, 1, 6) 1 1 1]', ... +%! [0 0 linspace(0, 1, 6).^2 1 1]'+1, ... +%! [0 0 0 linspace(0, 1, 6).^3 1]'+2] +%! )(:))) < 1e-10 %! ); %!shared iRGB,iRGBn,oRGB
--- a/inst/imresize.m +++ b/inst/imresize.m @@ -147,7 +147,7 @@ endif endfunction -%!shared in, out +%!test %! in = [116 227 153 69 146 194 59 130 139 106 %! 2 47 137 249 90 75 16 24 158 44 %! 155 68 46 84 166 156 69 204 32 152 @@ -155,8 +155,8 @@ %! 107 143 108 52 51 73 101 21 175 90 %! 54 158 143 77 26 168 113 229 165 225 %! 9 47 133 135 130 207 236 43 19 73]; -%!assert (imresize (uint8 (in), 1, "nearest"), uint8 (in)) -%!assert (imresize (uint8 (in), 1, "bicubic"), uint8 (in)) +%! assert (imresize (uint8 (in), 1, "nearest"), uint8 (in)) +%! assert (imresize (uint8 (in), 1, "bicubic"), uint8 (in)) %! %! out = [116 116 227 227 153 153 69 69 146 146 194 194 59 59 130 130 139 139 106 106 %! 116 116 227 227 153 153 69 69 146 146 194 194 59 59 130 130 139 139 106 106 @@ -172,10 +172,10 @@ %! 54 54 158 158 143 143 77 77 26 26 168 168 113 113 229 229 165 165 225 225 %! 9 9 47 47 133 133 135 135 130 130 207 207 236 236 43 43 19 19 73 73 %! 9 9 47 47 133 133 135 135 130 130 207 207 236 236 43 43 19 19 73 73]; -%!assert (imresize (uint8 (in), 2, "nearest"), uint8 (out)) -%!assert (imresize (uint8 (in), 2, "neAreST"), uint8 (out)) -%!assert (imresize (uint8 (in), [14 NaN], "nearest"), uint8 (out)) -%!assert (imresize (uint8 (in), [NaN 20], "nearest"), uint8 (out)) +%! assert (imresize (uint8 (in), 2, "nearest"), uint8 (out)) +%! assert (imresize (uint8 (in), 2, "neAreST"), uint8 (out)) +%! assert (imresize (uint8 (in), [14 NaN], "nearest"), uint8 (out)) +%! assert (imresize (uint8 (in), [NaN 20], "nearest"), uint8 (out)) %! %! out = [116 116 227 227 153 153 69 69 146 146 194 194 59 59 130 130 139 139 106 106 %! 2 2 47 47 137 137 249 249 90 90 75 75 16 16 24 24 158 158 44 44 @@ -184,19 +184,19 @@ %! 107 107 143 143 108 108 52 52 51 51 73 73 101 101 21 21 175 175 90 90 %! 54 54 158 158 143 143 77 77 26 26 168 168 113 113 229 229 165 165 225 225 %! 9 9 47 47 133 133 135 135 130 130 207 207 236 236 43 43 19 19 73 73]; -%!assert (imresize (uint8 (in), [7 20], "nearest"), uint8 (out)) +%! assert (imresize (uint8 (in), [7 20], "nearest"), uint8 (out)) %! -%!assert (imresize (uint8 (in), 1.5, "bicubic"), imresize (uint8 (in), 1.5, "cubic")) -%!assert (imresize (uint8 (in), [NaN, size(in,2)*1.5], "bicubic"), imresize (uint8 (in), 1.5, "cubic")) -%!assert (imresize (uint8 (in), [size(in,1)*1.5, NaN], "bicubic"), imresize (uint8 (in), 1.5, "cubic")) -%!assert (imresize (uint8 (in), 1.5, "linear"), imresize (uint8 (in), 1.5, "LIneAR")) -%!assert (imresize (uint8 (in), 1.5, "linear"), imresize (uint8 (in), 1.5, "triangle")) +%! assert (imresize (uint8 (in), 1.5, "bicubic"), imresize (uint8 (in), 1.5, "cubic")) +%! assert (imresize (uint8 (in), [NaN, size(in,2)*1.5], "bicubic"), imresize (uint8 (in), 1.5, "cubic")) +%! assert (imresize (uint8 (in), [size(in,1)*1.5, NaN], "bicubic"), imresize (uint8 (in), 1.5, "cubic")) +%! assert (imresize (uint8 (in), 1.5, "linear"), imresize (uint8 (in), 1.5, "LIneAR")) +%! assert (imresize (uint8 (in), 1.5, "linear"), imresize (uint8 (in), 1.5, "triangle")) %! %! out = [ 47 249 75 24 44 %! 221 230 153 115 118 %! 158 77 168 229 225 %! 47 135 207 43 73]; -%!assert (imresize (uint8 (in), 0.5, "nearest"), uint8 (out)) +%! assert (imresize (uint8 (in), 0.5, "nearest"), uint8 (out)) ## The following are the matlab results. We have slighlty different results but ## not by much. If there's would be any fixes, they would have to be on interp2 @@ -248,4 +248,3 @@ %! 115 108 93 128 146 %! 38 124 175 143 54]; %!xtest assert (imresize (uint8 (in), 0.5, "bicubic"), uint8 (out)) -
--- a/inst/imrotate.m +++ b/inst/imrotate.m @@ -305,8 +305,8 @@ %! # This is peaks(50) without the dependency on the plot package %! x = y = linspace(-3,3,50); %! [X,Y] = meshgrid(x,y); -%! x = 3*(1-X).^2.*exp(-X.^2 - (Y+1).^2) \ -%! - 10*(X/5 - X.^3 - Y.^5).*exp(-X.^2-Y.^2) \ +%! x = 3*(1-X).^2.*exp(-X.^2 - (Y+1).^2) ... +%! - 10*(X/5 - X.^3 - Y.^5).*exp(-X.^2-Y.^2) ... %! - 1/3*exp(-(X+1).^2 - Y.^2); %! %! x -= min(x(:)); # Fourier does not handle neg. values well
--- a/inst/imsubtract.m +++ b/inst/imsubtract.m @@ -33,7 +33,7 @@ ## @emph{Note 2}: the values are truncated to the mininum value of the output ## class. ## -## @emph{NOte 3}: values are truncated before the operation so if input images are +## @emph{Note 3}: values are truncated before the operation so if input images are ## unsigned integers and the request output class is a signed integer, it may lead ## to unexpected results: ## @@ -77,7 +77,8 @@ %!assert (imsubtract (uint8 ([23 250]), uint8 ([24 50])), uint8 ([ 0 200])); # default to first class and truncate %!assert (imsubtract (uint8 ([23 250]), 10), uint8 ([13 240])); # works subtracting a scalar %!assert (imsubtract (uint8 ([23 250]), uint8 ([24 50]), "uint16"), uint16 ([ 0 200])); # defining output class works (not in matlab) -%!assert (imsubtract (uint8 ([23 250]), uint8 ([24 255]), "int8"), int8 ([-1 0])); # signed integers kinda work (not in matlab) %!assert (imsubtract (logical ([ 1 0]), logical ([ 1 1])), double ([ 0 -1])); # return double for two logical images %!assert (imsubtract (logical ([ 1 0]), logical ([ 1 1]), "logical"), logical ([ 0 0])); # this is matlab incompatible on purpose %!fail ("imsubtract (uint8 ([23 250]), uint16 ([23 250]))"); # input need to have same class +%!assert (imsubtract (uint8 ([23 250]), uint8 ([24 255]), "int8"), int8 ([-1 0])); # signed integers kinda work (not in matlab) +%!warning <signed integer> imsubtract (uint8 ([23 250]), uint8 ([24 255]), "int8");
--- a/src/imerode.cc +++ b/src/imerode.cc @@ -726,7 +726,7 @@ %!test %! a = rand ([10 40 15 6 8 5]) > 0.8; %! se = ones ([5 3 7]); -%! assert (imdilate (a, se), convn (a, se) > 0) +%! assert (imdilate (a, se), convn (a, se, "same") > 0) %! assert (imdilate (a, se, "full"), convn (a, se, "full") > 0) %! assert (imdilate (a, se, "valid"), convn (a, se, "valid") > 0) %! assert (imdilate (a, se), colfilt (a, size (se), "sliding", @any))