annotate scripts/image/contrast.m @ 17086:3db796f89695

Rename private core_imfnc functions to follow the __fnc__ convention style.
author Carnë Draug <carandraug@octave.org>
date Fri, 26 Jul 2013 00:47:23 +0100
parents b1cd65881592
children d63878346099
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14138
72c96de7a403 maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1 ## Copyright (C) 2008-2012 David Bateman
7633
ba15376ddfe1 Add the contrast function
David Bateman <dbateman@free.fr>
parents:
diff changeset
2 ##
ba15376ddfe1 Add the contrast function
David Bateman <dbateman@free.fr>
parents:
diff changeset
3 ## This file is part of Octave.
ba15376ddfe1 Add the contrast function
David Bateman <dbateman@free.fr>
parents:
diff changeset
4 ##
ba15376ddfe1 Add the contrast function
David Bateman <dbateman@free.fr>
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
ba15376ddfe1 Add the contrast function
David Bateman <dbateman@free.fr>
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
ba15376ddfe1 Add the contrast function
David Bateman <dbateman@free.fr>
parents:
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
ba15376ddfe1 Add the contrast function
David Bateman <dbateman@free.fr>
parents:
diff changeset
8 ## your option) any later version.
ba15376ddfe1 Add the contrast function
David Bateman <dbateman@free.fr>
parents:
diff changeset
9 ##
ba15376ddfe1 Add the contrast function
David Bateman <dbateman@free.fr>
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
ba15376ddfe1 Add the contrast function
David Bateman <dbateman@free.fr>
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
ba15376ddfe1 Add the contrast function
David Bateman <dbateman@free.fr>
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ba15376ddfe1 Add the contrast function
David Bateman <dbateman@free.fr>
parents:
diff changeset
13 ## General Public License for more details.
ba15376ddfe1 Add the contrast function
David Bateman <dbateman@free.fr>
parents:
diff changeset
14 ##
ba15376ddfe1 Add the contrast function
David Bateman <dbateman@free.fr>
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
ba15376ddfe1 Add the contrast function
David Bateman <dbateman@free.fr>
parents:
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
ba15376ddfe1 Add the contrast function
David Bateman <dbateman@free.fr>
parents:
diff changeset
17 ## <http://www.gnu.org/licenses/>.
ba15376ddfe1 Add the contrast function
David Bateman <dbateman@free.fr>
parents:
diff changeset
18
ba15376ddfe1 Add the contrast function
David Bateman <dbateman@free.fr>
parents:
diff changeset
19 ## -*- texinfo -*-
15714
b1cd65881592 Clean up scripts in image directory.
Rik <rik@octave.org>
parents: 15683
diff changeset
20 ## @deftypefn {Function File} {@var{cmap} =} contrast (@var{x})
b1cd65881592 Clean up scripts in image directory.
Rik <rik@octave.org>
parents: 15683
diff changeset
21 ## @deftypefnx {Function File} {@var{cmap} =} contrast (@var{x}, @var{n})
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 7633
diff changeset
22 ## Return a gray colormap that maximizes the contrast in an image. The
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 7633
diff changeset
23 ## returned colormap will have @var{n} rows. If @var{n} is not defined
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
24 ## then the size of the current colormap is used.
14260
1f911333ed3d doc: Update docstrings for functions in image/ directory
Rik <octave@nomad.inbox5.com>
parents: 14253
diff changeset
25 ## @seealso{colormap, brighten}
7633
ba15376ddfe1 Add the contrast function
David Bateman <dbateman@free.fr>
parents:
diff changeset
26 ## @end deftypefn
ba15376ddfe1 Add the contrast function
David Bateman <dbateman@free.fr>
parents:
diff changeset
27
15714
b1cd65881592 Clean up scripts in image directory.
Rik <rik@octave.org>
parents: 15683
diff changeset
28 function cmap = contrast (x, n)
7633
ba15376ddfe1 Add the contrast function
David Bateman <dbateman@free.fr>
parents:
diff changeset
29
ba15376ddfe1 Add the contrast function
David Bateman <dbateman@free.fr>
parents:
diff changeset
30 if (nargin == 1)
15714
b1cd65881592 Clean up scripts in image directory.
Rik <rik@octave.org>
parents: 15683
diff changeset
31 n = rows (colormap ());
7633
ba15376ddfe1 Add the contrast function
David Bateman <dbateman@free.fr>
parents:
diff changeset
32 elseif (nargin == 2)
ba15376ddfe1 Add the contrast function
David Bateman <dbateman@free.fr>
parents:
diff changeset
33 if (! isscalar (n))
11472
1740012184f9 Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents: 9245
diff changeset
34 error ("contrast: N must be a scalar");
7633
ba15376ddfe1 Add the contrast function
David Bateman <dbateman@free.fr>
parents:
diff changeset
35 endif
ba15376ddfe1 Add the contrast function
David Bateman <dbateman@free.fr>
parents:
diff changeset
36 else
ba15376ddfe1 Add the contrast function
David Bateman <dbateman@free.fr>
parents:
diff changeset
37 print_usage ();
ba15376ddfe1 Add the contrast function
David Bateman <dbateman@free.fr>
parents:
diff changeset
38 endif
ba15376ddfe1 Add the contrast function
David Bateman <dbateman@free.fr>
parents:
diff changeset
39
ba15376ddfe1 Add the contrast function
David Bateman <dbateman@free.fr>
parents:
diff changeset
40 x = x(:);
ba15376ddfe1 Add the contrast function
David Bateman <dbateman@free.fr>
parents:
diff changeset
41 minx = min (x);
15714
b1cd65881592 Clean up scripts in image directory.
Rik <rik@octave.org>
parents: 15683
diff changeset
42 cmap = find (diff (sort ([round(n * ((x - minx) ./ (max(x) - minx))); [0:n]'])));
b1cd65881592 Clean up scripts in image directory.
Rik <rik@octave.org>
parents: 15683
diff changeset
43 minm = min (cmap);
b1cd65881592 Clean up scripts in image directory.
Rik <rik@octave.org>
parents: 15683
diff changeset
44 cmap = (cmap - minm) ./ (max (cmap) - minm);
b1cd65881592 Clean up scripts in image directory.
Rik <rik@octave.org>
parents: 15683
diff changeset
45 cmap = [cmap, cmap, cmap];
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
46
7633
ba15376ddfe1 Add the contrast function
David Bateman <dbateman@free.fr>
parents:
diff changeset
47 endfunction
ba15376ddfe1 Add the contrast function
David Bateman <dbateman@free.fr>
parents:
diff changeset
48
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
49
7633
ba15376ddfe1 Add the contrast function
David Bateman <dbateman@free.fr>
parents:
diff changeset
50 %!demo
15683
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 14260
diff changeset
51 %! figure;
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
52 %! img = reshape (1:100, 10, 10);
14253
f9bd63f5ddd0 contrast.m: Improve demo.
Rik <octave@nomad.inbox5.com>
parents: 14245
diff changeset
53 %! imagesc (img);
f9bd63f5ddd0 contrast.m: Improve demo.
Rik <octave@nomad.inbox5.com>
parents: 14245
diff changeset
54 %! colormap (gray (64));
f9bd63f5ddd0 contrast.m: Improve demo.
Rik <octave@nomad.inbox5.com>
parents: 14245
diff changeset
55 %! title ("Image with default 64 gray levels");
f9bd63f5ddd0 contrast.m: Improve demo.
Rik <octave@nomad.inbox5.com>
parents: 14245
diff changeset
56 %! pos = get (gcf, "position");
15683
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 14260
diff changeset
57 %! pos(1) += pos(3) + 25;
14253
f9bd63f5ddd0 contrast.m: Improve demo.
Rik <octave@nomad.inbox5.com>
parents: 14245
diff changeset
58 %! figure ("position", pos);
f9bd63f5ddd0 contrast.m: Improve demo.
Rik <octave@nomad.inbox5.com>
parents: 14245
diff changeset
59 %! colormap (contrast (img, 10));
f9bd63f5ddd0 contrast.m: Improve demo.
Rik <octave@nomad.inbox5.com>
parents: 14245
diff changeset
60 %! imagesc (img);
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
61 %! title ("Image with contrast enhanced");
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
62
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
63 %!assert (contrast (1:100,10), [([0:9]/9)',([0:9]/9)',([0:9]/9)'], 1e-10)
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
64