changeset 11279:442cb00e506b octave-forge

rgbplot: add new style option to also display composite colormap
author carandraug
date Sun, 02 Dec 2012 16:57:32 +0000
parents 2deb6b24d293
children dfa97ff7d23d
files main/image/NEWS main/image/inst/rgbplot.m main/image/inst/wavelength2rgb.m
diffstat 3 files changed, 42 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/main/image/NEWS	Fri Nov 30 20:13:45 2012 +0000
+++ b/main/image/NEWS	Sun Dec 02 16:57:32 2012 +0000
@@ -15,6 +15,9 @@
     one vector in the column direction and another vector in the row direction,
     has been removed. Please use conv2 for such cases.
 
+ ** The function `rgbplot' accepts a style option which alows for a composite
+    display of a colormap.
+
 Summary of important user-visible changes for image 2.0.0:
 -------------------------------------------------------------------
 
--- a/main/image/inst/rgbplot.m	Fri Nov 30 20:13:45 2012 +0000
+++ b/main/image/inst/rgbplot.m	Sun Dec 02 16:57:32 2012 +0000
@@ -1,4 +1,5 @@
 ## Copyright (C) 2012 Rik Wehbring
+## Copyright (C) 2012 Carnë Draug
 ##
 ## This file is part of Octave.
 ##
@@ -18,30 +19,53 @@
 
 ## -*- texinfo -*-
 ## @deftypefn  {Function File} {} rgbplot (@var{cmap})
+## @deftypefnx {Function File} {} rgbplot (@var{cmap}, @var{style})
 ## @deftypefnx {Function File} {@var{h} =} rgbplot (@dots{})
 ## Plot the components of a colormap.
 ##
-## The first column is plotted in red, the second column in green, and
-## the third column in blue.  The values are between 0 and 1 and represent
-## the intensity of the RGB components in the given indexed color.
+## Two different @var{style}s are available for displaying the @var{cmap}:
+## @table @asis
+## @item profile (default)
+## Plots the RGB line profile of the colormap for each of the channels (red,
+## green and blue) with the plot lines colored appropriately.  Each line
+## represents the intensity of each RGB components across the colormap.
+##
+## @item composite
+## Draws the colormap across the X axis so that the actual colors are visible
+## rather than the individual color components.
+##
+## @end table
+##
+## Run @code{demo rgbplot} for a comparison display.
 ##
 ## The optional return value @var{h} is a graphics handle to the created plot.
 ##
 ## @seealso{colormap}
 ## @end deftypefn
 
-function retval = rgbplot (cmap)
+function retval = rgbplot (cmap, style)
 
-  if (nargin != 1)
+  if (nargin < 1 || nargin > 2)
     print_usage ();
   endif
 
   if (! iscolormap (cmap))
     error ("rgbplot: CMAP must be a colormap");
+  elseif (! ischar (style))
+    error ("rgbplot: STYLE must be a string");
   endif
 
-  h = plot (cmap(:,1),"r", cmap(:,2),"g", cmap(:,3),"b");
-  set (gca, 'ytick', 0:0.1:1);
+  switch tolower (style)
+    case "profile"
+      h = plot (cmap(:,1),"r", cmap(:,2),"g", cmap(:,3),"b");
+      set (gca, 'ytick', 0:0.1:1);
+    case "composite"
+      h = image (1:rows(cmap));
+      set (gca, 'ytick', []);
+      colormap (cmap);
+    otherwise
+      error ("rgbplot: unknown style `%s'", style);
+  endswitch
   xlabel ("color index");
 
   if (nargout > 0)
@@ -50,10 +74,12 @@
 
 endfunction
 
-
 %!demo
 %! clf;
-%! rgbplot (ocean);
+%! subplot (1, 2, 1);
+%! rgbplot (ocean, "profile");
+%! subplot (1, 2, 2)
+%! rgbplot (ocean, "composite");
 
 %%test input validation
 %!error rgbplot ()
--- a/main/image/inst/wavelength2rgb.m	Fri Nov 30 20:13:45 2012 +0000
+++ b/main/image/inst/wavelength2rgb.m	Sun Dec 02 16:57:32 2012 +0000
@@ -170,6 +170,7 @@
 
 %!demo
 %!
-%! RGB = wavelength2rgb (350:800); # RGB values for wavelengths between 350 and 800 nm
-%! RGB = RGB .* ones (300, 1, 1);  # make it 300 rows for display
-%! imshow (RGB)
+%! ##draw RGB values for wavelengths between 350 and 800 nm
+%! RGB = wavelength2rgb (350:800);
+%! rgbplot (RGB, "composite");
+%! axis off;