changeset 11597:a066673566da

set clim to [0,1] so that scaled cdatamapping works as intended.
author Jordi Gutiérrez Hermoso <jordigh@gmail.com>
date Fri, 21 Jan 2011 13:15:38 -0500
parents a9cf422ed849
children 62b7ea59a6ff
files scripts/ChangeLog scripts/image/imshow.m
diffstat 2 files changed, 11 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog	Fri Jan 21 11:05:21 2011 -0500
+++ b/scripts/ChangeLog	Fri Jan 21 13:15:38 2011 -0500
@@ -1,3 +1,8 @@
+2011-01-20  Jordi GutiƩrrez Hermoso  <jordigh@gmail.com>
+
+	* image/imshow.m: Fix handling of clim and display_range so that
+	images are more faithfully reproduced.
+
 2011-01-20  Rik  <octave@nomad.inbox5.com>
 
 	* scripts/image/imshow.m, scripts/image/saveimage.m,
--- a/scripts/image/imshow.m	Fri Jan 21 11:05:21 2011 -0500
+++ b/scripts/image/imshow.m	Fri Jan 21 13:15:38 2011 -0500
@@ -124,10 +124,7 @@
       case {"double", "single", "logical"}
         display_range = [0, 1];
       case {"int8", "int16", "int32", "uint8", "uint16", "uint32"}
-        ## For compatibility, uint8 data should not be handled as
-        ## double.  Doing so is a quick fix to allow the images to be
-        ## displayed correctly.
-        display_range = double ([intmin(t), intmax(t)]);
+        display_range = [intmin(t), intmax(t)];
       otherwise
         error ("imshow: invalid data type for image");
     endswitch
@@ -151,13 +148,12 @@
     im = double (im);
   endif
 
-  ## Scale the image to the interval [0, 1] according to display_range.
+  ## Clamp the image to the range boundaries
   if (! (true_color || indexed || islogical (im)))
     low = display_range(1);
     high = display_range(2);
-    im = (im-low)/(high-low);
-    im(im < 0) = 0;
-    im(im > 1) = 1;
+    im(im < low) = low;
+    im(im > high) = high;
   endif
 
   if (true_color || indexed)
@@ -165,6 +161,8 @@
   else
     tmp = image (im);
     set (tmp, "cdatamapping", "scaled");
+    ## The backend is responsible for scaling to clim if necessary.
+    set (gca (), "clim", display_range);
   endif
   set (gca (), "visible", "off", "ydir", "reverse");
   axis ("image");