view scripts/image/brighten.m @ 21546:f7f97d7e9294

doc: Wrap m-file docstrings to 79 characters + newline (80 total). * isrecording.m, soundsc.m, delaunay3.m, cell2mat.m, cumtrapz.m, del2.m, inputParser.m, interp1.m, interp3.m, narginchk.m, profile.m, validateattributes.m, delaunayn.m, tsearchn.m, voronoin.m, brighten.m, cmunique.m, colorcube.m, imfinfo.m, imshow.m, edit.m, orderfields.m, run.m, warning_ids.m, ode23.m, ode45.m, odeget.m, integrate_adaptive.m, kahan.m, ode_struct_value_check.m, runge_kutta_23.m, fminunc.m, fsolve.m, fzero.m, pkg.m, build.m, specular.m, view.m, bar.m, barh.m, contour3.m, isosurface.m, line.m, pie.m, pie3.m, quiver3.m, scatter.m, scatter3.m, stem3.m, stemleaf.m, surfl.m, tetramesh.m, isfigure.m, mkpp.m, pchip.m, residue.m, splinefit.m, rmpref.m, unique.m, eigs.m, ilu.m, factor.m, factorial.m, gallery.m, hankel.m, histc.m, ols.m, finv.m, fpdf.m, kruskal_wallis_test.m, weekday.m: Wrap m-file docstrings to 79 characters + newline (80 total).
author Rik <rik@octave.org>
date Sun, 27 Mar 2016 15:50:01 -0700
parents 516bb87ea72e
children 2f9078956a63
line wrap: on
line source

## Copyright (C) 1999-2015 Kai Habel
##
## 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 3 of the License, 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, see
## <http://www.gnu.org/licenses/>.

## -*- texinfo -*-
## @deftypefn  {} {@var{map_out} =} brighten (@var{beta})
## @deftypefnx {} {@var{map_out} =} brighten (@var{map}, @var{beta})
## @deftypefnx {} {@var{map_out} =} brighten (@var{h}, @var{beta})
## @deftypefnx {} {} brighten (@dots{})
## Brighten or darken a colormap.
##
## The argument @var{beta} must be a scalar between -1 and 1, where a negative
## value darkens and a positive value brightens the colormap.
##
## If the @var{map} argument is omitted, the function is applied to the current
## colormap.
##
## The first argument can also be a valid graphics handle @var{h}, in which
## case @code{brighten} is applied to the colormap associated with this handle.
##
## If no output is specified then the result is written to the current
## colormap.
## @seealso{colormap, contrast}
## @end deftypefn

function rmap = brighten (arg1, beta)

  if (nargin < 1 || nargin > 2)
    print_usage ();
  endif

  h = -1;
  if (nargin == 1)
    beta = arg1;
    m = colormap ();
    h = gcf ();
  else
    if (ishandle (arg1))
      h = arg1;
      m = get (h, "colormap");
    elseif (iscolormap (arg1))
      m = arg1;
    else
      error ("brighten: first argument must be a colormap or a graphics handle");
    endif
  endif

  if (! isscalar (beta) || beta <= -1 || beta >= 1)
    error ("brighten: BETA must be a scalar in the range (-1,1)");
  endif

  if (beta > 0)
    gamma = 1 - beta;
  else
    gamma = 1 / (1 + beta);
  endif

  if (nargout == 0)
    if (ishandle (h))
      set (h, "colormap", m .^ gamma);
    else
      colormap (m .^ gamma);
    endif
  else
    rmap = m .^ gamma;
  endif

endfunction


%!demo
%! ## First figure uses default grayscale colormap
%! figure;
%! colormap (gray (64));
%! image (1:64, linspace (0, 1, 64), repmat ((1:64)', 1, 64));
%! axis ([1, 64, 0, 1], "ticy", "xy");
%! title ("default grayscale colormap");
%! pos = get (gcf, "position");
%! pos(1) += pos(3) + 25;
%! ## Second figure uses brightened grayscale colormap
%! figure ("position", pos);
%! colormap (gray (64));
%! image (1:64, linspace (0, 1, 64), repmat ((1:64)', 1, 64));
%! axis ([1, 64, 0, 1], "ticy", "xy");
%! brighten (0.5);
%! title ("grayscale colormap brightened by 0.5");