# HG changeset patch # User David Bateman # Date 1206461006 14400 # Node ID ba15376ddfe133d637cc4296e3bb36be69a0193a # Parent d6e63a15cc753588a09ca9ff7761485e265b03ae Add the contrast function diff --git a/scripts/ChangeLog b/scripts/ChangeLog --- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,7 @@ +2008-03-25 David Bateman + + * image/contrast.m: New function. + 2008-03-24 Thomas Weber * pkg/pkg.m: Allow installation of already extracted packages. diff --git a/scripts/image/Makefile.in b/scripts/image/Makefile.in --- a/scripts/image/Makefile.in +++ b/scripts/image/Makefile.in @@ -34,10 +34,10 @@ INSTALL_DATA = @INSTALL_DATA@ SOURCES = __img__.m __img_via_file__.m autumn.m bone.m brighten.m colormap.m \ - cool.m copper.m flag.m gmap40.m gray.m gray2ind.m hot.m hsv.m hsv2rgb.m \ - image.m image_viewer.m imagesc.m imshow.m ind2gray.m ind2rgb.m jet.m \ - loadimage.m ntsc2rgb.m ocean.m pink.m prism.m rainbow.m rgb2hsv.m rgb2ind.m \ - rgb2ntsc.m saveimage.m spring.m summer.m white.m winter.m + contrast.m cool.m copper.m flag.m gmap40.m gray.m gray2ind.m hot.m hsv.m \ + hsv2rgb.m image.m image_viewer.m imagesc.m imshow.m ind2gray.m ind2rgb.m \ + jet.m loadimage.m ntsc2rgb.m ocean.m pink.m prism.m rainbow.m rgb2hsv.m \ + rgb2ind.m rgb2ntsc.m saveimage.m spring.m summer.m white.m winter.m IMAGES = default.img diff --git a/scripts/image/contrast.m b/scripts/image/contrast.m new file mode 100644 --- /dev/null +++ b/scripts/image/contrast.m @@ -0,0 +1,50 @@ +## Copyright (C) 2008 David Bateman +## +## 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 +## . + +## -*- texinfo -*- +## @deftypefn {Function File} {} contrast (@var{x}, @var{n}) +## Return a gray colormap that maximizes the contrast in an image. The +## returned colormap will have @var{n} rows. If @var{n} is not defined +## then the size of the current colormap is used instead. +## @seealso{colormap} +## @end deftypefn + +function map = contrast (x, n) + + if (nargin == 1) + n = rows (colormap); + elseif (nargin == 2) + if (! isscalar (n)) + error ("contrast: n must be a scalar"); + endif + else + print_usage (); + endif + + x = x(:); + minx = min (x); + map = find (diff (sort ([round(n * ((x - minx) ./ (max(x) - minx))); [0:n]']))); + minm = min (map); + map = (map - minm) ./ (max (map) - minm); + map = [map, map, map]; +endfunction + +%!assert (contrast(1:100,10),[([0:9]/9)',([0:9]/9)',([0:9]/9)'],1e-10) +%!demo +%! image (reshape (1:100, 10, 10)) +%! colormap (contrast (1:100,10))