From: Paul K. <pki...@us...> - 2005-02-18 04:43:20
|
On Feb 16, 2005, at 5:08 AM, Justus Piater wrote: >> Using a smoother function worked better: >> >> X = peaks(30); >> Y = imrotate(imrotate(X,30,'bicubic'),-30,'bicubic'); >> norm(X(17+[1:5],17+[1:5])-Y(30+[1:5],30+[1:5])) >> ans = 0.0036647 > > I like this. I suggest to use "crop", this saves indexing adjustments > and makes the code more transparent and robust to future changes to > the size of the rotated image. Moreover, Fourier does not seem to > handle negative pixel values: > > X = peaks(30); > X -= min(min(X)); > Y = imrotate(imrotate(X, 30, "bicubic", "crop"), -30, "bicubic", > "crop"); > norm(X(10:20,10:20) - Y(10:20,10:20)) > ans = 0.076178 > > This can now be used with all four interpolation methods. This still begs the question of what is a 'good' value. How about the following: x=peaks(50); y=x; for i=1:5, y=imrotate(y,60,'bicubic','crop'); end norm((x-imrotate(y,59,'bicubic','crop'))(10:40,10:40)) ans = 2.6138 norm((x-imrotate(y,60,'bicubic','crop'))(10:40,10:40)) ans = 0.069348 norm((x-imrotate(y,61,'bicubic','crop'))(10:40,10:40)) ans = 2.6850 This should be a pretty good test of slight over- or under- rotation. I'm sure you already know the rotation is lossy: y=x=peaks(50); for i=1:6, y=imrotate(y,60,'bicubic','crop'); end norm((x-y)(10:40,10:40)) ans = 0.069348 for i=1:6, y=imrotate(y,60,'bicubic','crop'); end norm((x-y)(10:40,10:40)) ans = 0.13736 > As a complementary test of the "nearest" method, I suggest to compare > near-90-degree rotations to exact 90-degree rotations (only the latter > are handled by rot90, with greetings to Todd!). For odd image sizes, > the result should be exact: > > X = rand(99); > Y = imrotate(X, 89.9, "nearest"); > Z = imrotate(Y, -89.9, "nearest"); > norm(X-Z) > ans = 0 > norm(Y - imrotate(X, 90, "nearest")) > ans = 0 > > Also try 90.1 degrees, and likewise around 180 and 270. > > I think it would be useful to add these test cases to imrotate.m. > Send me a patch and I will add it. Embedded tests are run automatically. E.g., I added the following test: %!test %! X = rand(19); %! Z = imrotate(imrotate(X, 89.9, "nearest"), -89.9, "nearest"); %! assert(norm(X-Z),0); See 'help test' for more details. Thanks, - Paul |