changeset 1024:56520a75b5b3

[project @ 1995-01-11 20:30:04 by jwe]
author jwe
date Wed, 11 Jan 1995 20:30:04 +0000
parents 914348f891f0
children f558749713f1
files scripts/image/colormap.m scripts/image/gray.m scripts/image/gray2ind.m scripts/image/image.m scripts/image/imagesc.m scripts/image/imshow.m scripts/image/ind2gray.m scripts/image/ind2rgb.m scripts/image/loadimage.m scripts/image/ntsc2rgb.m scripts/image/ocean.m scripts/image/rgb2ind.m scripts/image/rgb2ntsc.m scripts/image/saveimage.m
diffstat 14 files changed, 495 insertions(+), 179 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/image/colormap.m	Wed Jan 11 02:56:01 1995 +0000
+++ b/scripts/image/colormap.m	Wed Jan 11 20:30:04 1995 +0000
@@ -1,42 +1,61 @@
-function cmap = colormap(map)
+# Copyright (C) 1995 John W. Eaton
+# 
+# This file is part of Octave.
+# 
+# Octave is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation; either version 2, or (at your option) any
+# later version.
+# 
+# Octave is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with Octave; see the file COPYING.  If not, write to the Free
+# Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+
+function cmap = colormap (map)
 
 # Set the current colormap.
 # 
-# colormap(map) sets the current colormap to map.  map should be an n row
-# by 3 column matrix. The columns contain red, green, and blue intensities
-# respectively.  All entries should be between 0 and 1 inclusive. The new
-# colormap is returned.
+# colormap (map) sets the current colormap to map.  map should be an n
+# row by 3 column matrix. The columns contain red, green, and blue
+# intensities respectively.  All entries should be between 0 and 1
+# inclusive. The new colormap is returned.
 # 
-# colormap("default") restores the default colormap (a gray scale colormap
-# with 64 entries). The default colormap is returned.
+# colormap ("default") restores the default colormap (a gray scale
+# colormap with 64 entries). The default colormap is returned.
 # 
 # colormap with no arguments returns the current colormap.
 
-# Author:
-#  Tony Richardson
-#  amr@mpl.ucsd.edu
-#  July 1994
+# Written by Tony Richardson (amr@mpl.ucsd.edu) July 1994.
 
   global CURRENT_COLOR_MAP
 
   cmap_name = "CURRENT_COLOR_MAP";
 
-  if(nargin == 1)
-    if(isstr(map))
-      if(strcmp(map,"default"))
+  if (nargin == 1)
+    if (isstr (map))
+      if (strcmp (map, "default"))
         CURRENT_COLOR_MAP = gray;
       else
-        error("invalid argument");
+        error ("invalid argument");
       endif
     else
-      # Set the new color map
+# Set the new color map
       CURRENT_COLOR_MAP = map;
     endif
-  elseif(exist(cmap_name) == 0)
-    # If global color map doesn't exist, create the default map.
+  elseif (nargin == 0 && exist (cmap_name) == 0)
+# If global color map doesn't exist, create the default map.
     CURRENT_COLOR_MAP = gray;
+  else
+    usage ("colormap (map)");
   endif
 
-  # Return current color map.
+# Return current color map.
+
   cmap = CURRENT_COLOR_MAP;
+
 endfunction
--- a/scripts/image/gray.m	Wed Jan 11 02:56:01 1995 +0000
+++ b/scripts/image/gray.m	Wed Jan 11 20:30:04 1995 +0000
@@ -1,12 +1,35 @@
-function map = gray(number)
+# Copyright (C) 1995 John W. Eaton
+# 
+# This file is part of Octave.
+# 
+# Octave is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation; either version 2, or (at your option) any
+# later version.
+# 
+# Octave is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with Octave; see the file COPYING.  If not, write to the Free
+# Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 
-  if(nargin == 0)
+function map = gray (number)
+
+# Colormap.
+
+# Written by Tony Richardson (amr@mpl.ucsd.edu) July 1994.
+
+  if (nargin == 0)
     number = 64;
+  elseif (nargin > 1)
+    usage ("gray (number)");
   endif
 
   gr = [0:(number-1)]';
-  
 
-  map = [ gr gr gr ]/(number-1);
+  map = [ gr, gr, gr ] / (number - 1);
 
 endfunction
--- a/scripts/image/gray2ind.m	Wed Jan 11 02:56:01 1995 +0000
+++ b/scripts/image/gray2ind.m	Wed Jan 11 20:30:04 1995 +0000
@@ -1,11 +1,35 @@
-function [X, map] = gray2ind(I,n)
+# Copyright (C) 1995 John W. Eaton
+# 
+# This file is part of Octave.
+# 
+# Octave is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation; either version 2, or (at your option) any
+# later version.
+# 
+# Octave is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with Octave; see the file COPYING.  If not, write to the Free
+# Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 
-  if(nargin == 1)
+function [X, map] = gray2ind (I, n)
+
+# Image format conversion
+
+# Written by Tony Richardson (amr@mpl.ucsd.edu) July 1994.
+
+  if (nargin < 1 || nargin > 2)
+    usage ("gray2ind (I, n)");
+  elseif (nargin == 1)
     n = 64;
   endif
 
-  map = gray(n);
+  map = gray (n);
 
-  X = round(I*(n-1)) + 1;
+  X = round (I*(n-1)) + 1;
 
 endfunction
--- a/scripts/image/image.m	Wed Jan 11 02:56:01 1995 +0000
+++ b/scripts/image/image.m	Wed Jan 11 20:30:04 1995 +0000
@@ -1,46 +1,61 @@
-function image(x, zoom)
+# Copyright (C) 1995 John W. Eaton
+# 
+# This file is part of Octave.
+# 
+# Octave is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation; either version 2, or (at your option) any
+# later version.
+# 
+# Octave is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with Octave; see the file COPYING.  If not, write to the Free
+# Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+
+function image (x, zoom)
 
 # Display an octave image matrix.
 #
-# image(x) displays a matrix as a color image. The elements of x are indices
-# into the current colormap and should have values between 1 and the length
-# of the colormap.
+# image (x) displays a matrix as a color image. The elements of x are
+# indices into the current colormap and should have values between 1
+# and the length of the colormap.
 #
-# image(x,zoom) changes the zoom factor.  The default value is 4.
+# image (x, zoom) changes the zoom factor.  The default value is 4.
 #
 # SEE ALSO: imshow, imagesc, colormap.
 
-# Author:
-#  Tony Richardson
-#  amr@mpl.ucsd.edu
-#  July 1994
+# Written by Tony Richardson (amr@mpl.ucsd.edu) July 1994.
 
   if (nargin == 0)
-    # Load Bobbie Jo Richardson (Born 3/16/94)
-    x = loadimage("default.img");
+# Load Bobbie Jo Richardson (Born 3/16/94)
+    x = loadimage ("default.img");
     zoom = 2;
-  elseif(nargin == 1)
+  elseif (nargin == 1)
     zoom = 4;
-  elseif(nargin > 2)
+  elseif (nargin > 2)
     usage ("image (matrix, [zoom])");
   endif
 
-  # Generate random file name
-  rnd_str = num2str(fix(rand*10000));
+# XXX FIXME XXX -- we should use octave_tmp_file_name.
+
+  rnd_str = num2str (fix (rand * 10000));
   ppm_name = ["image.", rnd_str, ".ppm" ];
 
-  saveimage(ppm_name,x,"ppm");
+  saveimage (ppm_name, x, "ppm");
 
-  # Start the viewer
-  # Try xv, then xloadimage.
+# Start the viewer.  Try xv, then xloadimage.
 
-  xv = sprintf("xv -expand %f %s",zoom,ppm_name);
-  xloadimage = sprintf("xloadimage -zoom %f %s",zoom*100, ppm_name);
-  rm = sprintf("rm -f %s",ppm_name);
+  xv = sprintf ("xv -expand %f %s", zoom, ppm_name);
+  xloadimage = sprintf ("xloadimage -zoom %f %s", zoom*100, ppm_name);
+  rm = sprintf ("rm -f %s", ppm_name);
 
-  command = sprintf("( %s || %s && %s ) > /dev/null 2>&1 &", ...
-                    xv, xloadimage, rm);
+  command = sprintf ("( %s || %s && %s ) > /dev/null 2>&1 &", ...
+                     xv, xloadimage, rm);
 
-  shell_cmd(command);
+  system (command);
 
 endfunction
--- a/scripts/image/imagesc.m	Wed Jan 11 02:56:01 1995 +0000
+++ b/scripts/image/imagesc.m	Wed Jan 11 20:30:04 1995 +0000
@@ -1,4 +1,22 @@
-function x = imagesc(x, zoom)
+# Copyright (C) 1995 John W. Eaton
+# 
+# This file is part of Octave.
+# 
+# Octave is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation; either version 2, or (at your option) any
+# later version.
+# 
+# Octave is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with Octave; see the file COPYING.  If not, write to the Free
+# Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+
+function x = imagesc (x, zoom)
 
 # Scale and display a matrix as an image.
 #
@@ -6,37 +24,33 @@
 # scaled so that its entries are indices into the current colormap.
 # The scaled matrix is returned.
 #
-# imagesc(x,zoom) sets the magnification, the default value is 4.
+# imagesc (x, zoom) sets the magnification, the default value is 4.
 #
 # SEE ALSO: image, imshow
 
-# Author:
-#  Tony Richardson
-#  amr@mpl.ucsd.edu
-#  July 1994
+# Written by Tony Richardson (amr@mpl.ucsd.edu) July 1994.
 
   if (nargin < 1 || nargin > 2)
     usage ("image (matrix, [zoom])");
-  endif
-
-  if (nargin == 1)
+  elseif (nargin == 1)
     zoom = 4;
   endif
 
-  [ high, wide ] = size(x);
+  [ high, wide ] = size (x);
 
-  maxval = max(max(x));
-  minval = min(min(x));
+  maxval = max (max (x));
+  minval = min (min (x));
 
-  # Rescale matrix so that all values are in the range 0 to
-  # length(colormap) inclusive
+# Rescale matrix so that all values are in the range 0 to
+# length (colormap) inclusive.
+
   if (maxval == minval)
-    x = ones(high, wide);
+    x = ones (high, wide);
   else
-    # Rescale values to between 1 and length(colormap) inclusive.
-    x = fix((x - minval)/(maxval - minval) * (length(colormap)-1)) + 1;
+# Rescale values to between 1 and length (colormap) inclusive.
+    x = fix ((x - minval) / (maxval - minval) * (length (colormap) - 1)) + 1;
   endif
 
-  image(x,zoom);
+  image (x, zoom);
 
 endfunction
--- a/scripts/image/imshow.m	Wed Jan 11 02:56:01 1995 +0000
+++ b/scripts/image/imshow.m	Wed Jan 11 20:30:04 1995 +0000
@@ -1,34 +1,49 @@
-function imshow(a1,a2,a3)
+# Copyright (C) 1995 John W. Eaton
+# 
+# This file is part of Octave.
+# 
+# Octave is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation; either version 2, or (at your option) any
+# later version.
+# 
+# Octave is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with Octave; see the file COPYING.  If not, write to the Free
+# Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+
+function imshow (a1, a2, a3)
 
 # Display images.
 #
-# imshow(X) displays an indexed image using the current colormap.
+# imshow (X) displays an indexed image using the current colormap.
 #
-# imshow(X,map) displays an indexed image using the specified colormap.
+# imshow (X, map) displays an indexed image using the specified colormap.
 #
-# imshow(I,n) displays a gray scale intensity image.
+# imshow (I, n) displays a gray scale intensity image.
 #
-# imshow(R,G,B) displays an RGB image.
+# imshow (R, G, B) displays an RGB image.
 #
 # SEE ALSO: image, imagesc, colormap, gray2ind, rgb2ind.
 
-# Author:
-#  Tony Richardson
-#  amr@mpl.ucsd.edu
-#  July 1994
+# Written by Tony Richardson (amr@mpl.ucsd.edu) July 1994.
 
-  if (nargin == 0)
-    usage ("imshow requires at least one argument.");
-  elseif(nargin == 2)
-    if(length(a2)==1)
-      [a1 a2] = gray2ind(a1,a2);
+  if (nargin < 0 || nargin > 3)
+    usage ("imshow (args)");
+  elseif (nargin == 2)
+    if (length (a2) == 1)
+      [a1, a2] = gray2ind (a1, a2);
     endif
-    colormap(a2);
-  elseif(nargin == 3)
-    [a1 a2] = rgb2ind(a1,a2,a3);
-    colormap(a2);
+    colormap (a2);
+  elseif (nargin == 3)
+    [a1, a2] = rgb2ind (a1, a2, a3);
+    colormap (a2);
   endif
 
-  image(a1);
+  image (a1);
 
 endfunction
--- a/scripts/image/ind2gray.m	Wed Jan 11 02:56:01 1995 +0000
+++ b/scripts/image/ind2gray.m	Wed Jan 11 20:30:04 1995 +0000
@@ -1,22 +1,45 @@
-function Y = ind2gray(X,map)
+# Copyright (C) 1995 John W. Eaton
+# 
+# This file is part of Octave.
+# 
+# Octave is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation; either version 2, or (at your option) any
+# later version.
+# 
+# Octave is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with Octave; see the file COPYING.  If not, write to the Free
+# Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+
+function Y = ind2gray (X, map)
 
 # Convert an octave indexed image to a gray scale intensity image.
 #
-# Y = ind2gray(X) converts an indexed image to a gray scale intensity
+# Y = ind2gray (X) converts an indexed image to a gray scale intensity
 # image.  The current colormap is used to determine the intensities.
 # The intensity values lie between 0 and 1 inclusive.
 #
-# Y = ind2gray(X,map) uses the specified colormap instead of the current
-# one in the conversion process.
+# Y = ind2gray (X, map) uses the specified colormap instead of the
+# current one in the conversion process.
 #
 # SEE ALSO: gray2ind, rgb2ntsc, image, colormap
 
-  if (nargin == 1)
-    map = colormap;
+# Written by Tony Richardson (amr@mpl.ucsd.edu) July 1994.
+
+  if (nargin < 1 || nargin > 2)
+    usage ("ind2gray (X, map)");
+  elseif (nargin == 1)
+    map = colormap ();
   endif
 
-  # Convert colormap to intensity values.
-  yiq = rgb2ntsc(map);
+# Convert colormap to intensity values.
+
+  yiq = rgb2ntsc (map);
   y = yiq(:,1);
 
 # We need Fortran indexing capability, but be sure to save the user's
@@ -31,9 +54,9 @@
 # Replace indices in the input matrix with indexed values in the output
 # matrix.
 
-    [rows, cols] = size(X);
+    [rows, cols] = size (X);
     Y = y(X(:));
-    Y = reshape(Y,rows,cols);
+    Y = reshape (Y, rows, cols);
 
   unwind_protect_cleanup
     do_fortran_indexing = pref;
--- a/scripts/image/ind2rgb.m	Wed Jan 11 02:56:01 1995 +0000
+++ b/scripts/image/ind2rgb.m	Wed Jan 11 20:30:04 1995 +0000
@@ -1,4 +1,22 @@
-function [R G B] = ind2rgb(X,map)
+# Copyright (C) 1995 John W. Eaton
+# 
+# This file is part of Octave.
+# 
+# Octave is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation; either version 2, or (at your option) any
+# later version.
+# 
+# Octave is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with Octave; see the file COPYING.  If not, write to the Free
+# Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+
+function [R, G, B] = ind2rgb (X, map)
 
 # Convert an indexed image to red, green, and blue color components.
 #
@@ -8,11 +26,17 @@
 #
 # SEE ALSO: rgb2ind, image, imshow, ind2gray, gray2ind.
 
-  if(nargin == 1)
-    map = colormap;
+# Written by Tony Richardson (amr@mpl.ucsd.edu) July 1994.
+
+  if (nargin < 1 || nargin > 2)
+    usage ("ind2rgb (X, map)");
+  elseif (nargin == 1)
+    map = colormap ();
   endif
 
-  [hi wi] = size(X);
+  [hi, wi] = size (X);
+
+# XXX FIXME XXX -- we should check size of X and map.
 
   pref = do_fortran_indexing;
 
@@ -20,13 +44,13 @@
 
     do_fortran_indexing = "true";
 
-    R = map(X(:),1);
-    G = map(X(:),2);
-    B = map(X(:),3);
+    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);
+    R = reshape (R, hi, wi);
+    G = reshape (G, hi, wi);
+    B = reshape (B, hi, wi);
 
   unwind_protect_cleanup
     do_fortran_indexing = pref;
--- a/scripts/image/loadimage.m	Wed Jan 11 02:56:01 1995 +0000
+++ b/scripts/image/loadimage.m	Wed Jan 11 20:30:04 1995 +0000
@@ -1,15 +1,37 @@
-function [X, map] = loadimage(filename)
+# Copyright (C) 1995 John W. Eaton
+# 
+# This file is part of Octave.
+# 
+# Octave is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation; either version 2, or (at your option) any
+# later version.
+# 
+# Octave is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with Octave; see the file COPYING.  If not, write to the Free
+# Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+
+function [X, map] = loadimage (filename)
 
 # Load an image file.
 #
-# [X, map] = loadimage(img_file) loads an image and it's associated color
-# map from file img_file.  The image must be in stored in octave's image
-# format.
+# [X, map] = loadimage (img_file) loads an image and it's associated
+# color map from file img_file.  The image must be in stored in
+# octave's image format.
 #
 # SEE ALSO: saveimage, load, save
 
-  if (nargin == 0)
+# Written by Tony Richardson (amr@mpl.ucsd.edu) July 1994.
+
+  if (nargin != 1)
     usage ("loadimage (filename)");
+  elseif (! isstr (filename))
+    error ("loadimage: expecting filename as a string");
   endif
 
   file = file_in_path (IMAGEPATH, filename);
@@ -20,6 +42,6 @@
 
 # XXX FIXME XXX -- file is assumed to have variables X and map.
   
-  eval(['load ', file]);
+  eval (['load ', file]);
 
 endfunction
--- a/scripts/image/ntsc2rgb.m	Wed Jan 11 02:56:01 1995 +0000
+++ b/scripts/image/ntsc2rgb.m	Wed Jan 11 20:30:04 1995 +0000
@@ -1,6 +1,34 @@
-function rgb = ntsc2rgb(yiq)
+# Copyright (C) 1995 John W. Eaton
+# 
+# This file is part of Octave.
+# 
+# Octave is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation; either version 2, or (at your option) any
+# later version.
+# 
+# Octave is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with Octave; see the file COPYING.  If not, write to the Free
+# Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 
-  trans = [ 1. 1. 1.; 0.95617 -0.27269 -1.10374; 0.62143 -0.64681 1.70062 ];
+function rgb = ntsc2rgb (yiq)
+
+# Image format conversion.
+
+# Written by Tony Richardson (amr@mpl.ucsd.edu) July 1994.
+
+  if (nargin != 1)
+    usage ("ntsc2rgb (yiq)");
+  endif
+
+  trans = [ 1.0,      1.0,      1.0;
+            0.95617, -0.27269, -1.10374;
+            0.62143, -0.64681, 1.70062 ];
 
   rgb = yiq * trans;
 
--- a/scripts/image/ocean.m	Wed Jan 11 02:56:01 1995 +0000
+++ b/scripts/image/ocean.m	Wed Jan 11 20:30:04 1995 +0000
@@ -1,17 +1,49 @@
-function map = ocean(number)
+# Copyright (C) 1995 John W. Eaton
+# 
+# This file is part of Octave.
+# 
+# Octave is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation; either version 2, or (at your option) any
+# later version.
+# 
+# Octave is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with Octave; see the file COPYING.  If not, write to the Free
+# Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 
-  if(nargin == 0)
+function map = ocean (number)
+
+# Colormap.
+
+# Written by Tony Richardson (amr@mpl.ucsd.edu) July 1994.
+
+  if (nargin == 0)
     number = 64;
+  elseif (nargin == 1)
+    if (! is_scalar (number))
+      error ("ocean: argument must be a scalar");
+    endif
+  else
+    usage ("ocean (number)");
   endif
 
-  cutin = fix(number/3);
+  cutin = fix (number/3);
   
-  dr = (number-1)/(cutin);
-  r = prepad([0:dr:(number-1)],number)';
-  dg = (number-1)/(2*cutin);
-  g = prepad([0:dg:(number-1)],number)';
+  dr = (number - 1) / cutin;
+
+  r = prepad ([0:dr:(number-1)], number)';
+
+  dg = (number - 1) / (2 * cutin);
+
+  g = prepad([0:dg:(number-1)], number)';
+
   b = [0:(number-1)]';
 
-  map = [ r g b ]/(number-1);
+  map = [ r, g, b ] / (number - 1);
 
 endfunction
--- a/scripts/image/rgb2ind.m	Wed Jan 11 02:56:01 1995 +0000
+++ b/scripts/image/rgb2ind.m	Wed Jan 11 20:30:04 1995 +0000
@@ -1,22 +1,46 @@
-function [X map] = rgb2ind(R,G,B)
+# Copyright (C) 1995 John W. Eaton
+# 
+# This file is part of Octave.
+# 
+# Octave is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation; either version 2, or (at your option) any
+# later version.
+# 
+# Octave is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with Octave; see the file COPYING.  If not, write to the Free
+# Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+
+function [X, map] = rgb2ind (R, G, B)
 
 # Convert and RGB image to an octave indexed image.
 #
-# [X map] = rgb2ind(R,G,B)
+# [X, map] = rgb2ind (R, G, B)
 #
 # SEE ALSO: ind2rgb, rgb2ntsc.
 #
 # Bugs: The color map may have duplicate entries.
 
-  if(nargin != 3)
-    usage ("[X, map] = rgb2ind(R,G,B)");
+# Written by Tony Richardson (amr@mpl.ucsd.edu) July 1994.
+
+  if (nargin != 3)
+    usage ("[X, map] = rgb2ind (R, G, B)");
   endif
 
-  [hi wi] = size(R);
+  if (size (R) != size (G) || size (R) != size (B))
+    error ("rgb2ind: arguments must all have the same size");
+  endif
 
-  X = zeros(hi,wi);
+  [hi, wi] = size (R);
 
-  map = zeros(hi*wi,3);
+  X = zeros (hi, wi);
+
+  map = zeros (hi*wi, 3);
 
   pref = do_fortran_indexing;
 
--- a/scripts/image/rgb2ntsc.m	Wed Jan 11 02:56:01 1995 +0000
+++ b/scripts/image/rgb2ntsc.m	Wed Jan 11 20:30:04 1995 +0000
@@ -1,6 +1,35 @@
-function yiq = rgb2ntsc(rgb)
+# Copyright (C) 1995 John W. Eaton
+# 
+# This file is part of Octave.
+# 
+# Octave is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation; either version 2, or (at your option) any
+# later version.
+# 
+# Octave is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with Octave; see the file COPYING.  If not, write to the Free
+# Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 
-  trans = [ 0.299 0.596 0.211; 0.587 -0.274 -0.523; 0.114 -0.322 0.312 ];
+function yiq = rgb2ntsc (rgb)
+
+# Image format conversion.
+
+# Written by Tony Richardson (amr@mpl.ucsd.edu) July 1994.
+
+  if (nargin != 1)
+    usage ("rgb2ntsc (rgb)");
+  endif
+
+  trans = [ 0.299,  0.596,  0.211;
+            0.587, -0.274, -0.523;
+            0.114, -0.322,  0.312 ];
+
   yiq = rgb * trans;
 
 endfunction
--- a/scripts/image/saveimage.m	Wed Jan 11 02:56:01 1995 +0000
+++ b/scripts/image/saveimage.m	Wed Jan 11 20:30:04 1995 +0000
@@ -1,74 +1,98 @@
-function saveimage(filename,X,img_form,map)
+# Copyright (C) 1995 John W. Eaton
+# 
+# This file is part of Octave.
+# 
+# Octave is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation; either version 2, or (at your option) any
+# later version.
+# 
+# Octave is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with Octave; see the file COPYING.  If not, write to the Free
+# Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+
+function saveimage (filename, X, img_form, map)
 
 # Save a matrix to disk in image format.
 # 
-# saveimage(filename,x) saves matrix x to file filename in octave's image
-# format.  The current colormap is saved in the file also.
+# saveimage (filename, x) saves matrix x to file filename in octave's
+# image format.  The current colormap is saved in the file also.
 # 
-# saveimage(filename,x,"img") saves the image in the default format and
-# is the same as saveimage(filename,x).
+# saveimage (filename, x, "img") saves the image in the default format
+# and is the same as saveimage (filename, x).
 # 
-# saveimage(filename,x,"ppm") saves the image in ppm format instead of
-# the default octave image format.
+# saveimage (filename, x, "ppm") saves the image in ppm format instead
+# of the default octave image format.
 # 
-# saveimage(filename,x,"ps") saves the image in PostScript format instead
-# of the default octave image format. (Note: images saved in PostScript format
-# can not be read back into octave with loadimage.)
+# saveimage (filename, x, "ps") saves the image in PostScript format
+# instead of the default octave image format. (Note: images saved in
+# PostScript format can not be read back into octave with loadimage.)
 # 
-# saveimage(filename,x,format,map) saves the image along with the specified
-# colormap in the specified format.
+# saveimage (filename, x, format, map) saves the image along with the
+# specified colormap in the specified format.
 # 
-# Note: If the colormap contains only two entries and these entries are black
-# and white, the bitmap ppm and PostScript formats are used.  If the image is
-# a gray scale image (the entries within each row of the colormap are equal)
-# the gray scale ppm and PostScript image formats are used, otherwise the full
-# color formats are used.
+# Note: If the colormap contains only two entries and these entries
+# are black and white, the bitmap ppm and PostScript formats are used.
+# If the image is a gray scale image (the entries within each row of
+# the colormap are equal) the gray scale ppm and PostScript image
+# formats are used, otherwise the full color formats are used.
 # 
 # SEE ALSO: loadimage, save, load, colormap
 
-  if(nargin < 2)
-    error("usage: saveimage(filename,matrix,[format, [colormap]])");
-  elseif(nargin == 2)
-    if(!isstr(filename))
-      error("File name must be a string.");
+# Written by Tony Richardson (amr@mpl.ucsd.edu) July 1994.
+
+  if (nargin < 2 || nargin > 4)
+    usage ("saveimage (filename, matrix, [format, [colormap]])");
+  elseif (nargin == 2)
+    if (! isstr (filename))
+      error ("file name must be a string");
     endif
     map = colormap;
     img_form = "img";
-  elseif(nargin == 3)
-    if(!isstr(img_form))
-      error("Image format specification must be a string");
+  elseif (nargin == 3)
+    if (! isstr (img_form))
+      error ("image format specification must be a string");
     endif
     map = colormap;
   endif
 
-  if (strcmp(img_form,"img") == 1)
+# XXX FIXME XXX -- we should check the remaining args.
+
+# XXX FIXME XXX -- we should use octave_tmp_file_name here.
+
+  if (strcmp (img_form, "img") == 1)
     oct_file = filename;
-  elseif (strcmp(img_form,"ppm") == 1)
-    # We need a temporary octave image file name.
-    oct_file = sprintf("image.%s.img",num2str(fix(rand*10000)));
+  elseif (strcmp (img_form, "ppm") == 1)
+    oct_file = sprintf ("image.%s.img", num2str (fix (rand * 10000)));
     ppm_file = filename;
-  elseif (strcmp(img_form,"ps") == 1)
-    # We need a temporary octave image file name.
-    oct_file = sprintf("image.%s.img",num2str(fix(rand*10000)));
+  elseif (strcmp (img_form, "ps") == 1)
+    oct_file = sprintf ("image.%s.img", num2str (fix (rand *10000)));
     ps_file = filename;
   endif
 
-  # Save image in octave image file format
-  eval(['save ', oct_file, ' map X']);
+# Save image in octave image file format
+
+  eval (['save ', oct_file, ' map X']);
+
+# Convert to another format if requested.
 
-  # Convert to another format if requested.
-  if (strcmp(img_form,"ppm") == 1)
-    octtopnm = sprintf("octtopnm %s > %s",oct_file,filename);
-    rm = sprintf("rm -f %s",oct_file);
-    shell_cmd(octtopnm);
-    shell_cmd(rm);
-  elseif (strcmp(img_form,"ps") == 1)
-    octtopnm = sprintf("octtopnm %s",oct_file);
-    ppmtops = sprintf("pnmtops > %s 2> /dev/null", filename);
+  if (strcmp (img_form, "ppm") == 1)
+    octtopnm = sprintf ("octtopnm %s > %s", oct_file, filename);
+    rm = sprintf("rm -f %s", oct_file);
+    shell_cmd (octtopnm);
+    shell_cmd (rm);
+  elseif (strcmp (img_form, "ps") == 1)
+    octtopnm = sprintf ("octtopnm %s", oct_file);
+    ppmtops = sprintf ("pnmtops > %s 2> /dev/null", filename);
     octtops = [ octtopnm, " | ", ppmtops ];
-    rm = sprintf("rm -f %s",oct_file);
-    shell_cmd(octtops);
-    shell_cmd(rm);
+    rm = sprintf ("rm -f %s", oct_file);
+    shell_cmd (octtops);
+    shell_cmd (rm);
   endif
 
 endfunction