octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: The contrast function


From: David Bateman
Subject: Re: The contrast function
Date: Tue, 25 Mar 2008 16:42:20 +0100
User-agent: Thunderbird 2.0.0.12 (X11/20080306)

John W. Eaton wrote:
> It does seem like a bug that 1 is always included but you can only
> approach 0 as N -> Inf (if I understand correctly).  Unless there is
> some good reason for doing that, I'd say go with what you have.
>
> jwe
>
>   
Ok, then changeset attached, with a minor modification.

D.

-- 
David Bateman                                address@hidden
Motorola Labs - Paris                        +33 1 69 35 48 04 (Ph) 
Parc Les Algorithmes, Commune de St Aubin    +33 6 72 01 06 33 (Mob) 
91193 Gif-Sur-Yvette FRANCE                  +33 1 69 35 77 01 (Fax) 

The information contained in this communication has been classified as: 

[x] General Business Information 
[ ] Motorola Internal Use Only 
[ ] Motorola Confidential Proprietary

# HG changeset patch
# User David Bateman <address@hidden>
# Date 1206458394 -3600
# Node ID a2e7f6d4c96388ac926ea0846e8e01226208a062
# Parent  b55c7ad8269da1e201e6c4427c4cf548913fb35b
Add the contrast function

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@
 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
+## <http://www.gnu.org/licenses/>.
+
+## -*- 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))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]