comparison scripts/image/image.m @ 17648:a433244dd697

image.m: Implement better check for linearity (bug #37410) * scripts/image/image.m: Use the percentage change from the average spacing as a unitless measure for linearity. If it deviates by more than 1%, print a warning.
author Rik <rik@octave.org>
date Sun, 13 Oct 2013 17:57:36 -0700
parents b81b9d079515
children dd8db3f1c1da
comparison
equal deleted inserted replaced
17647:7ec70c575ad6 17648:a433244dd697
119 xdata = x([1, end]); 119 xdata = x([1, end]);
120 ydata = y([1, end]); 120 ydata = y([1, end]);
121 121
122 if (numel (x) > 2 && numel (y) > 2) 122 if (numel (x) > 2 && numel (y) > 2)
123 ## Test data for non-linear spacing which is unsupported 123 ## Test data for non-linear spacing which is unsupported
124 ## FIXME: Need a better check on linearity 124 tol = .01; # 1% tolerance. FIXME: this value was chosen without thought.
125 tol = 100*eps;
126 dx = diff (x); 125 dx = diff (x);
126 dxmean = (max (x) - min (x)) / (numel (x) - 1);
127 dx = abs ((dx - dxmean) / dxmean);
127 dy = diff (y); 128 dy = diff (y);
128 dx = std (dx) / mean (abs (dx)); 129 dymean = (max (y) - min (y)) / (numel (y) - 1);
129 dy = std (dy) / mean (abs (dy)); 130 dy = abs ((dy - dymean) / dymean);
130 if (any (dx > tol) || any (dy > tol)) 131 if (any (dx > tol) || any (dy > tol))
131 warning ("image: non-linear X, Y data is ignored. IMG will be shown with linear mapping"); 132 warning ("image: non-linear X, Y data is ignored. IMG will be shown with linear mapping");
132 endif 133 endif
133 endif 134 endif
134 135