octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Better limit behavior for images


From: Daniel J Sebald
Subject: Better limit behavior for images
Date: Sat, 24 Feb 2007 00:37:11 -0600
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.3) Gecko/20041020

Another patch that improves the automatic limits for figures with images.  For 
example, here's that four image example again, but this time without the need 
for axis().

A = loadimage("default.img");
[size_y, size_x] = size(A);
X = ones(1,size_y)'*[1:size_x];
Y = [1:size_y]'*ones(1,size_x);
fig1 = figure();
set(fig1,"visible","off")
image(X, Y, A);
hold on;
image(X+size_x, Y, fliplr(A));
image(X, Y+size_y, flipud(A));
image(X+size_x, Y+size_y, flipud(fliplr(A)));
ocean(64);
set(fig1,"visible","on");

The limits aren't exactly perfect, but John discussed this before, i.e., either 
making the get_axis_limits() more robust or figuring out how to get info back 
from gnuplot's automatic ranges.

I've also redone the old zoom option in a deprecated fashion that only requires 
in the future to pull out one hunk of code with no other alterations (except 
one obvious one) if ever zoom is removed outright.  Try the following commands 
to get a flavor of things:

image
A = loadimage("default.img");
image(A,4)
image([1,40], [1:53], A)
image([1,40], A, 5)
image([1,40], [1:53], A, 5)
image([1,40], [1:53], A, 5, 4)
[the following may need rethinking, Soren?]
imshow(A)
imshow(A,[0,63])
[may want to make this the same as above]
imshow(A,[0:63])
imshow(A,"truesize")
imshow(A,"initialmagnification",4)
imagesc(A)
imagesc(A,3)
imagesc(A,3,[0,31])
imagesc(A,3,[0:31])
imagesc(A,[0,31],3)
imagesc([1:40],[1:50],A,3,[0,31])

help image
help imshow
help imagesc

Some of the above may require altered behavior, but overall it is good.  Here's 
the only line I'm really not sure about because I don't know how minimum 
positive value is utilized.

+               xminp = min (xminp, min (img_xdata((img_xdata - dx/2)>0)) - 
dx/2);

Dan

--- /usr/local/share/octave/2.9.9+/m/plot/__uiobject_draw_axes__.m      
2007-02-23 02:13:51.000000000 -0600
+++ ./__uiobject_draw_axes__.m  2007-02-23 20:07:41.000000000 -0600
@@ -272,6 +272,22 @@
            x_origin = min (img_xdata);
            y_origin = min (img_ydata);
 
+           if (nd == 2)
+             if (xautoscale)
+               xmin = min (xmin, min (img_xdata) - dx/2);
+               xmax = max (xmax, max (img_xdata) + dx/2);
+               xminp = min (xminp, min (img_xdata((img_xdata - dx/2)>0)) - 
dx/2);
+             endif
+             if (yautoscale)
+               ymin = min (ymin, min (img_ydata) - dy/2);
+               ymax = max (ymax, max (img_ydata) + dy/2);
+               yminp = min (yminp, min (img_ydata((img_ydata - dy/2)>0)) - 
dy/2);
+             endif
+           else
+             ## Can have images in 3D, but the image routines don't seem
+             ## to have a means of arbitrary projection.
+           endif
+
            ## Let the file be deleted when Octave exits or `purge_tmp_files'
            ## is called.
            [fid, fname] = mkstemp (strcat (P_tmpdir, "/gpimageXXXXXX"), 1);
--- /usr/local/share/octave/2.9.9+/m/image/__img__.m    2007-02-23 
02:13:49.000000000 -0600
+++ ./__img__.m 2007-02-23 05:00:22.000000000 -0600
@@ -62,7 +62,7 @@
 
   __uiobject_adopt__ (ca, tmp);
 
-  set (ca, "view", [0, 90], "xlim", xlim, "ylim", ylim);
+  set (ca, "view", [0, 90]);
 
   if (nargout > 0)
     h = tmp;
--- /usr/local/share/octave/2.9.9+/m/image/image.m      2007-02-23 
02:13:49.000000000 -0600
+++ ./image.m   2007-02-24 00:01:19.984465432 -0600
@@ -41,18 +41,26 @@
 
 function image (x, y, img)
 
-  newplot ();
+  ## Deprecated zoom.  Remove this hunk of code if old zoom argument
+  ## is outmoded.
+  if ((nargin == 2 && isscalar (y)) || nargin == 4)
+    printf("Zoom argument no longer interpreted.  Use GUI features.\n")
+  endif
+  if (nargin == 4)
+    nargin = 3;
+  endif
+  if (nargin == 2 && isscalar (y))
+    nargin = 1;
+  endif
 
   if (nargin == 0)
     ## Load Bobbie Jo Richardson (Born 3/16/94)
     img = loadimage ("default.img");
     x = y = [];
-  elseif (nargin == 1 || nargin == 2)
-    ## FIXME -- should we handle the old zoom argument?  How?  What
-    ## figure property should we be setting?
+  elseif (nargin == 1)
     img = x;
     x = y = [];
-  elseif (nargin > 3)
+  elseif (nargin == 2 || nargin > 3)
     print_usage ();
   endif
 
--- /usr/local/share/octave/2.9.9+/m/image/imagesc.m    2007-02-23 
02:13:49.000000000 -0600
+++ ./imagesc.m 2007-02-23 19:58:46.000000000 -0600
@@ -20,20 +20,18 @@
 ## -*- texinfo -*-
 ## @deftypefn {Function File} {} imagesc (@var{A})
 ## @deftypefnx {Function File} {} imagesc (@var{x}, @var{y}, @var{A})
-## @deftypefnx {Function File} {} imagesc (@dots{}, @var{zoom})
 ## @deftypefnx {Function File} {} imagesc (@dots{}, @var{limits})
 ## @deftypefnx {Function File} { @var{B} = } imagesc (@dots{})
 ## Display a scaled version of the matrix @var{A} as a color image.  The
 ## matrix is scaled so that its entries are indices into the current
-## colormap.  The scaled matrix is returned.  If @var{zoom} is omitted, a
-## comfortable size is chosen.  If @var{limits} = address@hidden, @var{hi}] are
+## colormap.  The scaled matrix is returned.  If @var{limits} = 
address@hidden, @var{hi}] are
 ## given, then that range maps into the full range of the colormap rather 
 ## than the minimum and maximum values of @var{A}.
 ##
 ## The axis values corresponding to the matrix elements are specified in
 ## @var{x} and @var{y}, either as pairs giving the minimum and maximum
 ## values for the respective axes, or as values for each row and column
-## of the matrix @var{A}.  At present they are ignored.
+## of the matrix @var{A}.
 ## @seealso{image, imshow}
 ## @end deftypefn
 
@@ -41,34 +39,48 @@
 ## Created: July 1994
 ## Adapted-By: jwe
 
-function ret = imagesc (x, y, A, zoom, limits)
+function ret = imagesc (x, y, A, limits, DEPRECATEDZOOM)
 
-  if (nargin < 1 || nargin > 5)
+  ## Deprecated zoom.  Remove this hunk of code if old zoom argument
+  ## is outmoded.
+  if ((nargin == 2 && isscalar (y))
+    || (nargin == 3 && (isscalar (y) || isscalar (A)))
+    || (nargin == 4 && isscalar (limits))
+    || nargin == 5)
+    printf("Zoom argument no longer interpreted.  Use GUI features.\n");
+  endif
+  if (nargin == 5)
+    if isscalar (limits)
+      limits = DEPRECATEDZOOM;
+    endif
+    nargin = 4;
+  endif
+  if (nargin == 4 && isscalar (limits))
+    nargin = 3;
+  endif
+  if (nargin == 3 && (isscalar (y) || isscalar (A)))
+    if isscalar (y)
+      y = A;
+    endif
+    nargin = 2;
+  endif
+  if (nargin == 2 && isscalar (y))
+    nargin = 1;
+  endif
+
+  if (nargin < 1 || nargin > 4)
     print_usage ();
   elseif (nargin == 1)
     A = x;
-    zoom = x = y = limits = [];
+    x = y = limits = [];
   elseif (nargin == 2)
     A = x;
-    zoom = y;
-    x = y = limits = [];
-  elseif (nargin == 3)
-    ## Assume imagesc(x,y,A) for compatibility.  It
-    ## could also be imagesc(A,limits,zoom), but if A is
-    ## a 1x2 vector, this is equivalent to imagesc(x,y,A)
-    ## for scalar A so we won't try to guess.
-    zoom = limits = [];
-  elseif (nargin == 4)
+    limits = y;
+    x = y = [];
+  elseif (nargin == 3 && !isscalar (x) && !isscalar (y) && !isscalar (A))
     limits = [];
   endif
 
-  ## correct for zoom, limits parameter order
-  if (length (zoom) == 2)
-     swap = limits;
-     limits = zoom;
-     zoom = swap;
-  endif
-
   ## use given limits or guess them from the matrix
   if (length (limits) == 2 && limits(2) >= limits(1))
      minval = limits(1);
@@ -92,7 +104,7 @@
 
   ## display or return the image
   if (nargout == 0)
-    image (x, y, B, zoom);
+    image (x, y, B);
   else
     ret = B;
   endif
--- /usr/local/share/octave/2.9.9+/m/image/imshow.m     2007-02-23 
02:13:49.000000000 -0600
+++ ./imshow.m  2007-02-23 23:44:16.826009160 -0600
@@ -24,7 +24,7 @@
 ## @deftypefnx {Function File} {} imshow (@var{R}, @var{G}, @var{B}, @dots{})
 ## @deftypefnx {Function File} {} imshow (@var{filename})
 ## @deftypefnx {Function File} {} imshow (@dots{}, @var{string_param1}, 
@var{value1}, @dots{})
-## Display the image @var{im}, where @var{im} can a 2-dimensional
+## Display the image @var{im}, where @var{im} can be a 2-dimensional
 ## (gray-scale image) or a 3-dimensional (RGB image) matrix. If three matrices
 ## of the same size are given as arguments, they will be concatenated into
 ## a 3-dimensional (RGB image) matrix.
@@ -44,12 +44,8 @@
 ## If given, the parameter @var{string_param1} has value
 ## @var{value1}. @var{string_param1} can be any of the following:
 ## @table @samp
-## @item "display_range"
+## @item "displayrange"
 ## @var{value1} is the display range as described above.
-##
-## @item "InitialMagnification"
-## @var{value1} sets the zoom level in percent. 
-## If @var{value1} is 100 the image is showed unscaled.
 ## @end table
 ## @seealso{image, imagesc, colormap, gray2ind, rgb2ind}
 ## @end deftypefn
@@ -110,14 +106,14 @@
     elseif (ismatrix (arg) && size (arg, 2) == 3)
       color_map = arg;
       isindexed = true;
-    elseif (ischar (arg) && strcmpi (arg, "truesize"))
-      initial_magnification = 100;
     elseif (ischar (arg) && strcmpi (arg, "displayrange"))
       narg++;
       display_range = varargin{narg};
-    elseif (ischar (arg) && strcmpi (arg, "initialmagnification"))
+    elseif (ischar (arg) &&
+           (strcmpi (arg, "truesize") ||
+             strcmpi (arg, "initialmagnification")))
       narg++;
-      initial_magnification = varargin{narg};
+      printf("Zoom argument no longer interpreted.  Use GUI features.\n");
     else
       warning ("imshow: input argument number %d is unsupported", narg) 
     endif
@@ -145,11 +141,11 @@
     im(im < 0) = 0;
     im(im > 1) = 1;
   endif
-  
+
   dim = ndims (im);
   if (dim == 2)
     im = round ((size (color_map, 1) - 1) * im);
-    image (im, initial_magnification/100);
+    image (im);
     colormap (color_map);
   elseif (dim == 3 && size (im, 3) == 3)
     __img__ ([] , [], im);
@@ -171,10 +167,6 @@
 %!  imshow (loadimage ("default.img"));
 
 %!demo
-%!  I = loadimage ("default.img");
-%!  imshow (I, "truesize")
-
-%!demo
 %!  [I, M] = loadimage ("default.img");
 %!  imshow (I, M);
 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]