From: Justus P. <Jus...@UL...> - 2005-02-25 08:05:15
|
Paul Kienzle <pki...@us...> wrote on Tue, 22 Feb 2005 07:13:43 -0500: > Justus, > > I was testing the wrong code. When I look at it now it looks fine. > Sorry to trouble you. Frankly, it did trouble me ("imrotate seems to be broken for all of...", "particularly glaring", "Can the [other!?] users of this function please come up with a fix"). But I accept your apology. > I would still like you to tell me which tests you prefer. I know I've > thrown a lot of suggestions your way :-) I went through all of the suggestions and cast comprehensive versions of the essence of them into the following three tests, which I suggest to be added to the end of imrotate.m. Justus %!test %! ## Verify minimal loss across six rotations that add up to 360 +/- 1 deg= .: %! methods =3D { "nearest", "bilinear", "bicubic", "Fourier" }; %! angles =3D [ 59 60 61 ]; %! tolerances =3D [ 7.4 8.5 8.6 # nearest %! 3.5 3.1 3.5 # bilinear %! 2.7 0.1 2.7 # bicubic %! 2.7 1.6 2.8 ]; # Fourier %! x =3D peaks(50); %! x -=3D min(min(x)); # Fourier does not handle neg. values well %! for m =3D 1:(length(methods)) %! y =3D x; %! for i =3D 1:5 %! y =3D imrotate(y, 60, methods(m), "crop"); %! end %! for a =3D 1:(length(angles)) %! assert(norm((x - imrotate(y, angles(a), methods(m), "crop")) %! (10:40, 10:40)) < tolerances(m,a)); %! end %! end %!test %! ## Verify exactness of near-90 and 90-degree rotations: %! X =3D rand(99); %! for angle =3D [90 180 270] %! for da =3D [-0.1 0.1] %! Y =3D imrotate(X, angle + da , "nearest"); %! Z =3D imrotate(Y, -(angle + da), "nearest"); %! assert(norm(X - Z) =3D=3D 0); # exact zero-sum rotation %! assert(norm(Y - imrotate(X, angle, "nearest")) =3D=3D 0); # near zer= o-sum %! end %! end %!test %! ## Verify preserved pixel density: %! methods =3D { "nearest", "bilinear", "bicubic", "Fourier" }; %! ## This test does not seem to do justice to the Fourier method...: %! tolerances =3D [ 4 2.2 2.0 209 ]; %! range =3D 3:9:100; %! for m =3D 1:(length(methods)) %! t =3D []; %! for n =3D range %! t(end + 1) =3D sum(imrotate(eye(n), 20, methods(m))(:)); %! end %! assert(t, range, tolerances(m)); %! end --=20 Justus H. Piater, Ph.D. http://www.montefiore.ulg.ac.be/~piater/ Institut Montefiore, B28 Phone: +32-4-366-2279 Universit=E9 de Li=E8ge, Belgium Fax: +32-4-366-2620 |