changeset 3486:9493fe321888

[project @ 2000-01-28 05:05:41 by jwe]
author jwe
date Fri, 28 Jan 2000 05:05:42 +0000
parents e5d5848370c9
children 8a72d9e400da
files scripts/ChangeLog scripts/general/reshape.m scripts/image/ind2gray.m scripts/image/ind2rgb.m scripts/image/rgb2ind.m scripts/signal/sinc.m
diffstat 6 files changed, 34 insertions(+), 86 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog	Fri Jan 28 02:07:38 2000 +0000
+++ b/scripts/ChangeLog	Fri Jan 28 05:05:42 2000 +0000
@@ -1,3 +1,13 @@
+2000-01-27  John W. Eaton  <jwe@bevo.che.wisc.edu>
+
+	* signal/sinc.m: Avoid reshaping.
+
+	* image/rgb2ind.m: No longer needs to reset do_fortran_indexing.
+	* image/ind2rgb.m: Ditto.
+	* image/ind2gray.m: Ditto.
+	* general/reshape.m: Ditto.  Also no longer needs to reset
+	implicit_str_to_num_ok.
+
 2000-01-26  John W. Eaton  <jwe@bevo.che.wisc.edu>
 
 	* miscellaneous/popen2.m: Deal with the fact that pipe now returns
--- a/scripts/general/reshape.m	Fri Jan 28 02:07:38 2000 +0000
+++ b/scripts/general/reshape.m	Fri Jan 28 05:05:42 2000 +0000
@@ -64,20 +64,11 @@
   if (nargin == 3)
     [nr, nc] = size (a);
     if (nr * nc == m * n)
-      dfi = do_fortran_indexing;
-      istno = implicit_str_to_num_ok;
-      unwind_protect
-        do_fortran_indexing = 1;
-        implicit_str_to_num_ok = 1;
-        retval = zeros (m, n);
-        retval (:) = a;
-        if (isstr (a))
-          retval = setstr (retval);
-        endif
-      unwind_protect_cleanup
-        do_fortran_indexing = dfi;
-        implicit_str_to_num_ok = istno;
-      end_unwind_protect
+      retval = zeros (m, n);
+      if (isstr (a))
+	retval = setstr (retval);
+      endif
+      retval(:) = a;
     else
       error ("reshape: sizes must match");
     endif
--- a/scripts/image/ind2gray.m	Fri Jan 28 02:07:38 2000 +0000
+++ b/scripts/image/ind2gray.m	Fri Jan 28 05:05:42 2000 +0000
@@ -37,29 +37,14 @@
     map = colormap ();
   endif
 
-  ## Convert colormap to intensity values.
-
-  yiq = rgb2ntsc (map);
-  y = yiq(:,1);
-
-  ## We need Fortran indexing capability, but be sure to save the user's
-  ## preference.
-
-  pref = do_fortran_indexing;
-
-  unwind_protect
+  [rows, cols] = size (X);
 
-    do_fortran_indexing = 1;
-
-    ## Replace indices in the input matrix with indexed values in the output
-    ## matrix.
+  ## Convert colormap to intensity values (the first column of the
+  ## result of the call to rgb2ntsc) and then replace indices in
+  ## the input matrix with indexed values in the output matrix (indexed
+  ## values are the result of indexing the the intensity values by the
+  ## elements of X(:)).
 
-    [rows, cols] = size (X);
-    Y = y(X(:));
-    Y = reshape (Y, rows, cols);
-
-  unwind_protect_cleanup
-    do_fortran_indexing = pref;
-  end_unwind_protect
+  Y = reshape (((rgb2ntsc (map))(:,1))(X(:)), rows, cols);
 
 endfunction
--- a/scripts/image/ind2rgb.m	Fri Jan 28 02:07:38 2000 +0000
+++ b/scripts/image/ind2rgb.m	Fri Jan 28 05:05:42 2000 +0000
@@ -40,22 +40,8 @@
 
   ## XXX FIXME XXX -- we should check size of X and map.
 
-  pref = do_fortran_indexing;
-
-  unwind_protect
-
-    do_fortran_indexing = 1;
-
-    R = map (X(:), 1);
-    G = map (X(:), 2);
-    B = map (X(:), 3);
-
-    R = reshape (R, hi, wi);
-    G = reshape (G, hi, wi);
-    B = reshape (B, hi, wi);
-
-  unwind_protect_cleanup
-    do_fortran_indexing = pref;
-  end_unwind_protect
+  R = reshape (map (X(:), 1), hi, wi);
+  G = reshape (map (X(:), 2), hi, wi);
+  B = reshape (map (X(:), 3), hi, wi);
 
 endfunction
--- a/scripts/image/rgb2ind.m	Fri Jan 28 02:07:38 2000 +0000
+++ b/scripts/image/rgb2ind.m	Fri Jan 28 05:05:42 2000 +0000
@@ -45,20 +45,10 @@
 
   map = zeros (hi*wi, 3);
 
-  pref = do_fortran_indexing;
-
-  unwind_protect
-
-    do_fortran_indexing = 1;
+  map(:,1) = R(:);
+  map(:,2) = G(:);
+  map(:,3) = B(:);
 
-    map(:,1) = R(:);
-    map(:,2) = G(:);
-    map(:,3) = B(:);
-
-    X(:) = 1:(hi*wi);
-
-  unwind_protect_cleanup
-    do_fortran_indexing = pref;
-  end_unwind_protect
+  X(:) = 1:(hi*wi);
 
 endfunction
--- a/scripts/signal/sinc.m	Fri Jan 28 02:07:38 2000 +0000
+++ b/scripts/signal/sinc.m	Fri Jan 28 05:05:42 2000 +0000
@@ -34,27 +34,13 @@
 
 function result = sinc (x)
 
-  ## We either need to set the do_fortran_indexing variable to "true"
-  ## or use reshape to convert the input matrix to a vector, so that
-  ## we can use find to determine the elements of x that equal zero.
-  ## I prefer reshaping.
+  result = ones (size (x));
 
-  [nr, nc] = size(x);
-
-  nels = nr*nc;
+  i = (x != 0);
 
-  x = reshape(x,nels,1);
-
-  ## Set result to all ones initially.
-  result = ones(nels,1);
-
-  ## Find non-zero elements in the input matrix.
-  i = find(x);
-
-  if (!isempty(i))
-    result(i) = sin(pi*x(i))./(pi*x(i));
+  if (any (i))
+    t = pi * x(i);
+    result(i) = sin (t) ./ t;
   endif
 
-  result = reshape(result,nr,nc);
-
 endfunction