Mercurial > octave-antonio
annotate scripts/image/contrast.m @ 15683:806ea52af230
Overhaul m-files in image directory to provide better support for images stored as integers.
* NEWS: Add note about overhaul of image scripts to support integer
classes.
* brighten.m: Add demo.
* colormap.m: Better input validation.
* contrast.m: Re-position window in demo.
* gray2ind.m: Redo docstring. Match variables in docstring to function
prototype. Better input validation. Return integer class outputs as
Matlab does. Add %!tests.
* hsv2rgb.m: Add to docstring. Better input validation. Redo algorithm
to get rido of obsolete matrix-fill methods like kron(). Add %!tests.
* image.m: Redo docstring. Match variables in docstring to function
prototype. Better input validation without using for loops.
* imagesc.m: Redo docstring. Match variables in docstring to function
prototype. Remove DEPRECATEDZOOM functionality. Add demos.
* imfinfo.m: Redo docstring.
* ind2gray.m: Redo docstring. Match variables in docstring to function
prototype. Redo algorithm to directly calculate luminance value rather
than getting it from rgb2ntsc. Add %!tests.
* ind2rgb.m: Redo docstring. Better input validation. Add some %!tests.
* ntsc2rgb.m: Redo docstring. Better input validation. Add %!tests.
* rgb2hsv.m: Better input validation. Add %!tests.
* rgb2ind.m: Better input validation. Code algorithm in cleaner method
for ease of understanding.
* rgb2ntsc.m: Redo docstring: Better input validation. Add some %!tests.
author | Rik <rik@octave.org> |
---|---|
date | Tue, 27 Nov 2012 16:38:13 -0800 |
parents | 1f911333ed3d |
children | b1cd65881592 |
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 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7 ## the Free Software Foundation; either version 3 of the License, or (at | |
8 ## your option) any later version. | |
9 ## | |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
16 ## along with Octave; see the file COPYING. If not, see | |
17 ## <http://www.gnu.org/licenses/>. | |
18 | |
19 ## -*- texinfo -*- | |
14260
1f911333ed3d
doc: Update docstrings for functions in image/ directory
Rik <octave@nomad.inbox5.com>
parents:
14253
diff
changeset
|
20 ## @deftypefn {Function File} {@var{map} =} contrast (@var{x}) |
1f911333ed3d
doc: Update docstrings for functions in image/ directory
Rik <octave@nomad.inbox5.com>
parents:
14253
diff
changeset
|
21 ## @deftypefnx {Function File} {@var{map} =} 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 | 26 ## @end deftypefn |
27 | |
28 function map = contrast (x, n) | |
29 | |
30 if (nargin == 1) | |
31 n = rows (colormap); | |
32 elseif (nargin == 2) | |
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 | 35 endif |
36 else | |
37 print_usage (); | |
38 endif | |
39 | |
40 x = x(:); | |
41 minx = min (x); | |
42 map = find (diff (sort ([round(n * ((x - minx) ./ (max(x) - minx))); [0:n]']))); | |
43 minm = min (map); | |
44 map = (map - minm) ./ (max (map) - minm); | |
45 map = [map, map, map]; | |
14245
4506eade9f04
Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
46 |
7633 | 47 endfunction |
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 | 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 | 53 %! imagesc (img); |
54 %! colormap (gray (64)); | |
55 %! title ("Image with default 64 gray levels"); | |
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 | 58 %! figure ("position", pos); |
59 %! colormap (contrast (img, 10)); | |
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 |