annotate scripts/image/imshow.m @ 18747:0585787aa8ae

imshow.m: Overhaul function and support integer images (bug #41240). * imshow.m: Check that input colormaps are valid. Rename variable "true_color" to "truecolor". Add checking for "parent" property, although it is unimplemented. Fix off-by-1 error when reporting a bad argument during input validation. Don't accept invalid image formats uint32, int32. Don't check for NaNs on integer data (which doesn't have any). Don't change image data in order to clamp it to the display_range variable; Just use 'scaled' image and have the display routines do this. Use image(), imagesc() to simplify things. Rename variable "tmp" to "htmp" since that is what other routines use. Add %!error tests for input validation.
author Rik <rik@octave.org>
date Thu, 01 May 2014 12:31:06 -0700
parents d57a83f2d73e
children c79696701468
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17744
d63878346099 maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents: 17734
diff changeset
1 ## Copyright (C) 1994-2013 John W. Eaton
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
2 ##
2313
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
3 ## This file is part of Octave.
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
4 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
6 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6757
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6757
diff changeset
8 ## your option) any later version.
2313
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
9 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
13 ## General Public License for more details.
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
14 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
15 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6757
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6757
diff changeset
17 ## <http://www.gnu.org/licenses/>.
1024
56520a75b5b3 [project @ 1995-01-11 20:30:04 by jwe]
jwe
parents: 904
diff changeset
18
3381
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3373
diff changeset
19 ## -*- texinfo -*-
10793
be55736a0783 Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents: 10648
diff changeset
20 ## @deftypefn {Function File} {} imshow (@var{im})
5934
8702f00329bf [project @ 2006-08-17 20:29:51 by jwe]
jwe
parents: 5642
diff changeset
21 ## @deftypefnx {Function File} {} imshow (@var{im}, @var{limits})
8702f00329bf [project @ 2006-08-17 20:29:51 by jwe]
jwe
parents: 5642
diff changeset
22 ## @deftypefnx {Function File} {} imshow (@var{im}, @var{map})
7074
87151f298e6a [project @ 2007-10-26 17:57:34 by jwe]
jwe
parents: 7017
diff changeset
23 ## @deftypefnx {Function File} {} imshow (@var{rgb}, @dots{})
5934
8702f00329bf [project @ 2006-08-17 20:29:51 by jwe]
jwe
parents: 5642
diff changeset
24 ## @deftypefnx {Function File} {} imshow (@var{filename})
6309
6a60e68fc4b1 [project @ 2007-02-15 09:49:27 by jwe]
jwe
parents: 6219
diff changeset
25 ## @deftypefnx {Function File} {} imshow (@dots{}, @var{string_param1}, @var{value1}, @dots{})
14001
5f0bb45e615c doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents: 13738
diff changeset
26 ## @deftypefnx {Function File} {@var{h} =} imshow (@dots{})
6368
ec2a523713b5 [project @ 2007-02-28 22:07:24 by jwe]
jwe
parents: 6310
diff changeset
27 ## Display the image @var{im}, where @var{im} can be a 2-dimensional
14897
8e2a6fc55787 doc: Use 'grayscale' rather than 'gray-scale' in documentation.
Rik <rik@octave.org>
parents: 14366
diff changeset
28 ## (grayscale image) or a 3-dimensional (RGB image) matrix.
5934
8702f00329bf [project @ 2006-08-17 20:29:51 by jwe]
jwe
parents: 5642
diff changeset
29 ##
8702f00329bf [project @ 2006-08-17 20:29:51 by jwe]
jwe
parents: 5642
diff changeset
30 ## If @var{limits} is a 2-element vector @code{[@var{low}, @var{high}]},
8702f00329bf [project @ 2006-08-17 20:29:51 by jwe]
jwe
parents: 5642
diff changeset
31 ## the image is shown using a display range between @var{low} and
8702f00329bf [project @ 2006-08-17 20:29:51 by jwe]
jwe
parents: 5642
diff changeset
32 ## @var{high}. If an empty matrix is passed for @var{limits}, the
8702f00329bf [project @ 2006-08-17 20:29:51 by jwe]
jwe
parents: 5642
diff changeset
33 ## display range is computed as the range between the minimal and the
8702f00329bf [project @ 2006-08-17 20:29:51 by jwe]
jwe
parents: 5642
diff changeset
34 ## maximal value in the image.
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3381
diff changeset
35 ##
5934
8702f00329bf [project @ 2006-08-17 20:29:51 by jwe]
jwe
parents: 5642
diff changeset
36 ## If @var{map} is a valid color map, the image will be shown as an indexed
8702f00329bf [project @ 2006-08-17 20:29:51 by jwe]
jwe
parents: 5642
diff changeset
37 ## image using the supplied color map.
8702f00329bf [project @ 2006-08-17 20:29:51 by jwe]
jwe
parents: 5642
diff changeset
38 ##
8702f00329bf [project @ 2006-08-17 20:29:51 by jwe]
jwe
parents: 5642
diff changeset
39 ## If a file name is given instead of an image, the file will be read and
8702f00329bf [project @ 2006-08-17 20:29:51 by jwe]
jwe
parents: 5642
diff changeset
40 ## shown.
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3381
diff changeset
41 ##
5934
8702f00329bf [project @ 2006-08-17 20:29:51 by jwe]
jwe
parents: 5642
diff changeset
42 ## If given, the parameter @var{string_param1} has value
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
43 ## @var{value1}. @var{string_param1} can be any of the following:
14366
b76f0740940e doc: Periodic grammar check of documentation.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
44 ##
11595
5ec6aa05638d Prevent doubled quotes around @table items in Info.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
45 ## @table @asis
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 14897
diff changeset
46 ## @item @qcode{"displayrange"}
5934
8702f00329bf [project @ 2006-08-17 20:29:51 by jwe]
jwe
parents: 5642
diff changeset
47 ## @var{value1} is the display range as described above.
17734
64ad713b3a64 imshow.m: Add support for "xdata" and "ydata" options, make option parser case insensitive
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 17281
diff changeset
48 ##
17753
887df64e54e4 doc: Final grammarcheck of docstrings for 3.8 release.
Rik <rik@octave.org>
parents: 17744
diff changeset
49 ## @item @qcode{"xdata"}
17734
64ad713b3a64 imshow.m: Add support for "xdata" and "ydata" options, make option parser case insensitive
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 17281
diff changeset
50 ## If @var{value1} is a two element vector, it must contain horizontal axis
64ad713b3a64 imshow.m: Add support for "xdata" and "ydata" options, make option parser case insensitive
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 17281
diff changeset
51 ## limits in the form [xmin xmax]; Otherwise @var{value1} must be a
64ad713b3a64 imshow.m: Add support for "xdata" and "ydata" options, make option parser case insensitive
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 17281
diff changeset
52 ## vector and only the first and last elements will be used for xmin and
64ad713b3a64 imshow.m: Add support for "xdata" and "ydata" options, make option parser case insensitive
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 17281
diff changeset
53 ## xmax respectively.
64ad713b3a64 imshow.m: Add support for "xdata" and "ydata" options, make option parser case insensitive
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 17281
diff changeset
54 ##
17753
887df64e54e4 doc: Final grammarcheck of docstrings for 3.8 release.
Rik <rik@octave.org>
parents: 17744
diff changeset
55 ## @item @qcode{"ydata"}
17734
64ad713b3a64 imshow.m: Add support for "xdata" and "ydata" options, make option parser case insensitive
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 17281
diff changeset
56 ## If @var{value1} is a two element vector, it must contain vertical axis
64ad713b3a64 imshow.m: Add support for "xdata" and "ydata" options, make option parser case insensitive
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 17281
diff changeset
57 ## limits in the form [ymin ymax]; Otherwise @var{value1} must be a
64ad713b3a64 imshow.m: Add support for "xdata" and "ydata" options, make option parser case insensitive
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 17281
diff changeset
58 ## vector and only the first and last elements will be used for ymin and
64ad713b3a64 imshow.m: Add support for "xdata" and "ydata" options, make option parser case insensitive
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 17281
diff changeset
59 ## ymax respectively.
64ad713b3a64 imshow.m: Add support for "xdata" and "ydata" options, make option parser case insensitive
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 17281
diff changeset
60 ##
5934
8702f00329bf [project @ 2006-08-17 20:29:51 by jwe]
jwe
parents: 5642
diff changeset
61 ## @end table
14001
5f0bb45e615c doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents: 13738
diff changeset
62 ##
5f0bb45e615c doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents: 13738
diff changeset
63 ## The optional return value @var{h} is a graphics handle to the image.
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5443
diff changeset
64 ## @seealso{image, imagesc, colormap, gray2ind, rgb2ind}
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3202
diff changeset
65 ## @end deftypefn
904
3470f1e25a79 [project @ 1994-11-09 21:22:15 by jwe]
jwe
parents: 559
diff changeset
66
7074
87151f298e6a [project @ 2007-10-26 17:57:34 by jwe]
jwe
parents: 7017
diff changeset
67 ## Author: Stefan van der Walt <stefan@sun.ac.za>
5934
8702f00329bf [project @ 2006-08-17 20:29:51 by jwe]
jwe
parents: 5642
diff changeset
68 ## Author: Soren Hauberg <hauberg at gmail dot com>
2312
204cc7db6f4a [project @ 1996-07-11 21:20:36 by jwe]
jwe
parents: 2311
diff changeset
69 ## Adapted-By: jwe
559
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
70
7074
87151f298e6a [project @ 2007-10-26 17:57:34 by jwe]
jwe
parents: 7017
diff changeset
71 function h = imshow (im, varargin)
559
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
72
5934
8702f00329bf [project @ 2006-08-17 20:29:51 by jwe]
jwe
parents: 5642
diff changeset
73 if (nargin == 0)
8702f00329bf [project @ 2006-08-17 20:29:51 by jwe]
jwe
parents: 5642
diff changeset
74 print_usage ();
5318
9a72639b62a7 [project @ 2005-04-28 18:44:27 by jwe]
jwe
parents: 5307
diff changeset
75 endif
9a72639b62a7 [project @ 2005-04-28 18:44:27 by jwe]
jwe
parents: 5307
diff changeset
76
7328
d0784e593d39 [project @ 2007-12-20 07:24:02 by jwe]
jwe
parents: 7321
diff changeset
77 display_range = NA;
18747
0585787aa8ae imshow.m: Overhaul function and support integer images (bug #41240).
Rik <rik@octave.org>
parents: 18746
diff changeset
78 truecolor = false;
7074
87151f298e6a [project @ 2007-10-26 17:57:34 by jwe]
jwe
parents: 7017
diff changeset
79 indexed = false;
17734
64ad713b3a64 imshow.m: Add support for "xdata" and "ydata" options, make option parser case insensitive
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 17281
diff changeset
80 xdata = ydata = [];
7074
87151f298e6a [project @ 2007-10-26 17:57:34 by jwe]
jwe
parents: 7017
diff changeset
81
5935
01ff100fcd64 [project @ 2006-08-17 20:40:58 by jwe]
jwe
parents: 5934
diff changeset
82 ## Get the image.
5934
8702f00329bf [project @ 2006-08-17 20:29:51 by jwe]
jwe
parents: 5642
diff changeset
83 if (ischar (im))
7931
de26beacb20f imread.m: simplify; loadimage.m: deprecate
John W. Eaton <jwe@octave.org>
parents: 7930
diff changeset
84 [im, map] = imread (im);
7074
87151f298e6a [project @ 2007-10-26 17:57:34 by jwe]
jwe
parents: 7017
diff changeset
85 indexed = true;
87151f298e6a [project @ 2007-10-26 17:57:34 by jwe]
jwe
parents: 7017
diff changeset
86 colormap (map);
87151f298e6a [project @ 2007-10-26 17:57:34 by jwe]
jwe
parents: 7017
diff changeset
87 endif
87151f298e6a [project @ 2007-10-26 17:57:34 by jwe]
jwe
parents: 7017
diff changeset
88
10286
8cf666139297 imshow for logical matrices
John W. Eaton <jwe@octave.org>
parents: 9273
diff changeset
89 nd = ndims (im);
8cf666139297 imshow for logical matrices
John W. Eaton <jwe@octave.org>
parents: 9273
diff changeset
90
8cf666139297 imshow for logical matrices
John W. Eaton <jwe@octave.org>
parents: 9273
diff changeset
91 if (! ((isnumeric (im) || islogical (im)) && (nd == 2 || nd == 3)))
11472
1740012184f9 Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents: 11324
diff changeset
92 error ("imshow: IM must be an image or the filename of an image");
5318
9a72639b62a7 [project @ 2005-04-28 18:44:27 by jwe]
jwe
parents: 5307
diff changeset
93 endif
7074
87151f298e6a [project @ 2007-10-26 17:57:34 by jwe]
jwe
parents: 7017
diff changeset
94
10286
8cf666139297 imshow for logical matrices
John W. Eaton <jwe@octave.org>
parents: 9273
diff changeset
95 if (nd == 2)
7074
87151f298e6a [project @ 2007-10-26 17:57:34 by jwe]
jwe
parents: 7017
diff changeset
96 if (! indexed)
87151f298e6a [project @ 2007-10-26 17:57:34 by jwe]
jwe
parents: 7017
diff changeset
97 colormap (gray ());
87151f298e6a [project @ 2007-10-26 17:57:34 by jwe]
jwe
parents: 7017
diff changeset
98 endif
87151f298e6a [project @ 2007-10-26 17:57:34 by jwe]
jwe
parents: 7017
diff changeset
99 elseif (size (im, 3) == 3)
87151f298e6a [project @ 2007-10-26 17:57:34 by jwe]
jwe
parents: 7017
diff changeset
100 if (ismember (class (im), {"uint8", "uint16", "double", "single"}))
18747
0585787aa8ae imshow.m: Overhaul function and support integer images (bug #41240).
Rik <rik@octave.org>
parents: 18746
diff changeset
101 truecolor = true;
7074
87151f298e6a [project @ 2007-10-26 17:57:34 by jwe]
jwe
parents: 7017
diff changeset
102 else
18747
0585787aa8ae imshow.m: Overhaul function and support integer images (bug #41240).
Rik <rik@octave.org>
parents: 18746
diff changeset
103 error ("imshow: TrueColor image must be uint8, uint16, double, or single");
7074
87151f298e6a [project @ 2007-10-26 17:57:34 by jwe]
jwe
parents: 7017
diff changeset
104 endif
87151f298e6a [project @ 2007-10-26 17:57:34 by jwe]
jwe
parents: 7017
diff changeset
105 else
87151f298e6a [project @ 2007-10-26 17:57:34 by jwe]
jwe
parents: 7017
diff changeset
106 error ("imshow: expecting MxN or MxNx3 matrix for image");
5318
9a72639b62a7 [project @ 2005-04-28 18:44:27 by jwe]
jwe
parents: 5307
diff changeset
107 endif
9a72639b62a7 [project @ 2005-04-28 18:44:27 by jwe]
jwe
parents: 5307
diff changeset
108
7074
87151f298e6a [project @ 2007-10-26 17:57:34 by jwe]
jwe
parents: 7017
diff changeset
109 narg = 1;
87151f298e6a [project @ 2007-10-26 17:57:34 by jwe]
jwe
parents: 7017
diff changeset
110 while (narg <= numel (varargin))
87151f298e6a [project @ 2007-10-26 17:57:34 by jwe]
jwe
parents: 7017
diff changeset
111 arg = varargin{narg++};
87151f298e6a [project @ 2007-10-26 17:57:34 by jwe]
jwe
parents: 7017
diff changeset
112 if (isnumeric (arg))
7331
3ed85de5922c [project @ 2007-12-21 17:40:20 by jwe]
jwe
parents: 7328
diff changeset
113 if (numel (arg) == 2 || isempty (arg))
10433
2c01d24459fb Detabify scripts in 'scripts/image/'
Soren Hauberg <hauberg@gmail.com>
parents: 10286
diff changeset
114 display_range = arg;
7074
87151f298e6a [project @ 2007-10-26 17:57:34 by jwe]
jwe
parents: 7017
diff changeset
115 elseif (columns (arg) == 3)
10433
2c01d24459fb Detabify scripts in 'scripts/image/'
Soren Hauberg <hauberg@gmail.com>
parents: 10286
diff changeset
116 indexed = true;
18747
0585787aa8ae imshow.m: Overhaul function and support integer images (bug #41240).
Rik <rik@octave.org>
parents: 18746
diff changeset
117 if (iscolormap (arg))
0585787aa8ae imshow.m: Overhaul function and support integer images (bug #41240).
Rik <rik@octave.org>
parents: 18746
diff changeset
118 colormap (arg);
0585787aa8ae imshow.m: Overhaul function and support integer images (bug #41240).
Rik <rik@octave.org>
parents: 18746
diff changeset
119 else
0585787aa8ae imshow.m: Overhaul function and support integer images (bug #41240).
Rik <rik@octave.org>
parents: 18746
diff changeset
120 error ("imshow: invalid colormap MAP");
0585787aa8ae imshow.m: Overhaul function and support integer images (bug #41240).
Rik <rik@octave.org>
parents: 18746
diff changeset
121 endif
7074
87151f298e6a [project @ 2007-10-26 17:57:34 by jwe]
jwe
parents: 7017
diff changeset
122 elseif (! isempty (arg))
18747
0585787aa8ae imshow.m: Overhaul function and support integer images (bug #41240).
Rik <rik@octave.org>
parents: 18746
diff changeset
123 error ("imshow: argument number %d is invalid", narg);
7074
87151f298e6a [project @ 2007-10-26 17:57:34 by jwe]
jwe
parents: 7017
diff changeset
124 endif
87151f298e6a [project @ 2007-10-26 17:57:34 by jwe]
jwe
parents: 7017
diff changeset
125 elseif (ischar (arg))
17734
64ad713b3a64 imshow.m: Add support for "xdata" and "ydata" options, make option parser case insensitive
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 17281
diff changeset
126 switch (tolower (arg))
18747
0585787aa8ae imshow.m: Overhaul function and support integer images (bug #41240).
Rik <rik@octave.org>
parents: 18746
diff changeset
127 case "colormap"
0585787aa8ae imshow.m: Overhaul function and support integer images (bug #41240).
Rik <rik@octave.org>
parents: 18746
diff changeset
128 map = varargin{narg++};
0585787aa8ae imshow.m: Overhaul function and support integer images (bug #41240).
Rik <rik@octave.org>
parents: 18746
diff changeset
129 if (iscolormap (map))
0585787aa8ae imshow.m: Overhaul function and support integer images (bug #41240).
Rik <rik@octave.org>
parents: 18746
diff changeset
130 colormap (map);
0585787aa8ae imshow.m: Overhaul function and support integer images (bug #41240).
Rik <rik@octave.org>
parents: 18746
diff changeset
131 else
0585787aa8ae imshow.m: Overhaul function and support integer images (bug #41240).
Rik <rik@octave.org>
parents: 18746
diff changeset
132 error ("imshow: invalid colormap");
0585787aa8ae imshow.m: Overhaul function and support integer images (bug #41240).
Rik <rik@octave.org>
parents: 18746
diff changeset
133 endif
0585787aa8ae imshow.m: Overhaul function and support integer images (bug #41240).
Rik <rik@octave.org>
parents: 18746
diff changeset
134 case "displayrange"
10433
2c01d24459fb Detabify scripts in 'scripts/image/'
Soren Hauberg <hauberg@gmail.com>
parents: 10286
diff changeset
135 display_range = varargin{narg++};
18747
0585787aa8ae imshow.m: Overhaul function and support integer images (bug #41240).
Rik <rik@octave.org>
parents: 18746
diff changeset
136 case "parent"
0585787aa8ae imshow.m: Overhaul function and support integer images (bug #41240).
Rik <rik@octave.org>
parents: 18746
diff changeset
137 warning ("imshow: parent argument is not implemented");
0585787aa8ae imshow.m: Overhaul function and support integer images (bug #41240).
Rik <rik@octave.org>
parents: 18746
diff changeset
138 case {"truesize", "initialmagnification"}
0585787aa8ae imshow.m: Overhaul function and support integer images (bug #41240).
Rik <rik@octave.org>
parents: 18746
diff changeset
139 warning ("image: zoom argument ignored -- use GUI features");
0585787aa8ae imshow.m: Overhaul function and support integer images (bug #41240).
Rik <rik@octave.org>
parents: 18746
diff changeset
140 case "xdata"
17734
64ad713b3a64 imshow.m: Add support for "xdata" and "ydata" options, make option parser case insensitive
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 17281
diff changeset
141 xdata = varargin{narg++};
64ad713b3a64 imshow.m: Add support for "xdata" and "ydata" options, make option parser case insensitive
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 17281
diff changeset
142 if (! isvector (xdata))
64ad713b3a64 imshow.m: Add support for "xdata" and "ydata" options, make option parser case insensitive
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 17281
diff changeset
143 error ("imshow: xdata must be a vector")
64ad713b3a64 imshow.m: Add support for "xdata" and "ydata" options, make option parser case insensitive
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 17281
diff changeset
144 endif
64ad713b3a64 imshow.m: Add support for "xdata" and "ydata" options, make option parser case insensitive
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 17281
diff changeset
145 xdata = [xdata(1) xdata(end)];
18747
0585787aa8ae imshow.m: Overhaul function and support integer images (bug #41240).
Rik <rik@octave.org>
parents: 18746
diff changeset
146 case "ydata"
17734
64ad713b3a64 imshow.m: Add support for "xdata" and "ydata" options, make option parser case insensitive
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 17281
diff changeset
147 ydata = varargin{narg++};
18546
8e384416ebb3 imshow.m: Fix bad input validation of ydata (bug #41773).
Rik <rik@octave.org>
parents: 17753
diff changeset
148 if (! isvector (ydata))
18747
0585787aa8ae imshow.m: Overhaul function and support integer images (bug #41240).
Rik <rik@octave.org>
parents: 18746
diff changeset
149 error ("imshow: ydata must be a vector")
17734
64ad713b3a64 imshow.m: Add support for "xdata" and "ydata" options, make option parser case insensitive
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 17281
diff changeset
150 endif
64ad713b3a64 imshow.m: Add support for "xdata" and "ydata" options, make option parser case insensitive
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 17281
diff changeset
151 ydata = [ydata(1) ydata(end)];
10433
2c01d24459fb Detabify scripts in 'scripts/image/'
Soren Hauberg <hauberg@gmail.com>
parents: 10286
diff changeset
152 otherwise
2c01d24459fb Detabify scripts in 'scripts/image/'
Soren Hauberg <hauberg@gmail.com>
parents: 10286
diff changeset
153 warning ("imshow: unrecognized property %s", arg);
2c01d24459fb Detabify scripts in 'scripts/image/'
Soren Hauberg <hauberg@gmail.com>
parents: 10286
diff changeset
154 narg++;
7074
87151f298e6a [project @ 2007-10-26 17:57:34 by jwe]
jwe
parents: 7017
diff changeset
155 endswitch
87151f298e6a [project @ 2007-10-26 17:57:34 by jwe]
jwe
parents: 7017
diff changeset
156 else
18747
0585787aa8ae imshow.m: Overhaul function and support integer images (bug #41240).
Rik <rik@octave.org>
parents: 18746
diff changeset
157 error ("imshow: argument number %d is invalid", narg);
7074
87151f298e6a [project @ 2007-10-26 17:57:34 by jwe]
jwe
parents: 7017
diff changeset
158 endif
87151f298e6a [project @ 2007-10-26 17:57:34 by jwe]
jwe
parents: 7017
diff changeset
159 endwhile
87151f298e6a [project @ 2007-10-26 17:57:34 by jwe]
jwe
parents: 7017
diff changeset
160
13738
7ee61e56eaed Periodic merge of stable to default
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13705
diff changeset
161 ## Check for complex images.
7ee61e56eaed Periodic merge of stable to default
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13705
diff changeset
162 if (iscomplex (im))
7ee61e56eaed Periodic merge of stable to default
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13705
diff changeset
163 warning ("imshow: only showing real part of complex image");
7ee61e56eaed Periodic merge of stable to default
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13705
diff changeset
164 im = real (im);
7ee61e56eaed Periodic merge of stable to default
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13705
diff changeset
165 endif
7ee61e56eaed Periodic merge of stable to default
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13705
diff changeset
166
8117
40aa36406a94 Fix for display_range in imshow
Kris Thielemans
parents: 7931
diff changeset
167 ## Set default display range if display_range not set yet.
7328
d0784e593d39 [project @ 2007-12-20 07:24:02 by jwe]
jwe
parents: 7321
diff changeset
168 if (isempty (display_range))
7074
87151f298e6a [project @ 2007-10-26 17:57:34 by jwe]
jwe
parents: 7017
diff changeset
169 display_range = [min(im(:)), max(im(:))];
8117
40aa36406a94 Fix for display_range in imshow
Kris Thielemans
parents: 7931
diff changeset
170 elseif (isna (display_range))
7074
87151f298e6a [project @ 2007-10-26 17:57:34 by jwe]
jwe
parents: 7017
diff changeset
171 t = class (im);
87151f298e6a [project @ 2007-10-26 17:57:34 by jwe]
jwe
parents: 7017
diff changeset
172 switch (t)
87151f298e6a [project @ 2007-10-26 17:57:34 by jwe]
jwe
parents: 7017
diff changeset
173 case {"double", "single", "logical"}
10433
2c01d24459fb Detabify scripts in 'scripts/image/'
Soren Hauberg <hauberg@gmail.com>
parents: 10286
diff changeset
174 display_range = [0, 1];
18747
0585787aa8ae imshow.m: Overhaul function and support integer images (bug #41240).
Rik <rik@octave.org>
parents: 18746
diff changeset
175 case {"uint8", "uint16", "int16"}
11597
a066673566da set clim to [0,1] so that scaled cdatamapping works as intended.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11595
diff changeset
176 display_range = [intmin(t), intmax(t)];
7074
87151f298e6a [project @ 2007-10-26 17:57:34 by jwe]
jwe
parents: 7017
diff changeset
177 otherwise
10433
2c01d24459fb Detabify scripts in 'scripts/image/'
Soren Hauberg <hauberg@gmail.com>
parents: 10286
diff changeset
178 error ("imshow: invalid data type for image");
7074
87151f298e6a [project @ 2007-10-26 17:57:34 by jwe]
jwe
parents: 7017
diff changeset
179 endswitch
87151f298e6a [project @ 2007-10-26 17:57:34 by jwe]
jwe
parents: 7017
diff changeset
180 endif
5934
8702f00329bf [project @ 2006-08-17 20:29:51 by jwe]
jwe
parents: 5642
diff changeset
181
18747
0585787aa8ae imshow.m: Overhaul function and support integer images (bug #41240).
Rik <rik@octave.org>
parents: 18746
diff changeset
182 if (isfloat (im))
0585787aa8ae imshow.m: Overhaul function and support integer images (bug #41240).
Rik <rik@octave.org>
parents: 18746
diff changeset
183 nans = isnan (im(:));
0585787aa8ae imshow.m: Overhaul function and support integer images (bug #41240).
Rik <rik@octave.org>
parents: 18746
diff changeset
184 if (any (nans))
0585787aa8ae imshow.m: Overhaul function and support integer images (bug #41240).
Rik <rik@octave.org>
parents: 18746
diff changeset
185 warning ("Octave:imshow-NaN",
0585787aa8ae imshow.m: Overhaul function and support integer images (bug #41240).
Rik <rik@octave.org>
parents: 18746
diff changeset
186 "imshow: pixels with NaN or NA values are set to minimum pixel value");
0585787aa8ae imshow.m: Overhaul function and support integer images (bug #41240).
Rik <rik@octave.org>
parents: 18746
diff changeset
187 im(nans) = display_range(1);
0585787aa8ae imshow.m: Overhaul function and support integer images (bug #41240).
Rik <rik@octave.org>
parents: 18746
diff changeset
188 endif
6219
ba9db82d85a8 [project @ 2006-12-27 17:53:34 by jwe]
jwe
parents: 6157
diff changeset
189 endif
ba9db82d85a8 [project @ 2006-12-27 17:53:34 by jwe]
jwe
parents: 6157
diff changeset
190
18747
0585787aa8ae imshow.m: Overhaul function and support integer images (bug #41240).
Rik <rik@octave.org>
parents: 18746
diff changeset
191 ## FIXME: Commented out 2014/05/01. imagesc and 'clim' will automatically
0585787aa8ae imshow.m: Overhaul function and support integer images (bug #41240).
Rik <rik@octave.org>
parents: 18746
diff changeset
192 ## take care of displaying out-of-range data clamped to the limits.
0585787aa8ae imshow.m: Overhaul function and support integer images (bug #41240).
Rik <rik@octave.org>
parents: 18746
diff changeset
193 ## Eventually, this can be deleted if no problems arise.
11597
a066673566da set clim to [0,1] so that scaled cdatamapping works as intended.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11595
diff changeset
194 ## Clamp the image to the range boundaries
18747
0585787aa8ae imshow.m: Overhaul function and support integer images (bug #41240).
Rik <rik@octave.org>
parents: 18746
diff changeset
195 ##if (! (truecolor || indexed || islogical (im)))
0585787aa8ae imshow.m: Overhaul function and support integer images (bug #41240).
Rik <rik@octave.org>
parents: 18746
diff changeset
196 ## low = display_range(1);
0585787aa8ae imshow.m: Overhaul function and support integer images (bug #41240).
Rik <rik@octave.org>
parents: 18746
diff changeset
197 ## high = display_range(2);
0585787aa8ae imshow.m: Overhaul function and support integer images (bug #41240).
Rik <rik@octave.org>
parents: 18746
diff changeset
198 ## im(im < low) = low;
0585787aa8ae imshow.m: Overhaul function and support integer images (bug #41240).
Rik <rik@octave.org>
parents: 18746
diff changeset
199 ## im(im > high) = high;
0585787aa8ae imshow.m: Overhaul function and support integer images (bug #41240).
Rik <rik@octave.org>
parents: 18746
diff changeset
200 ##endif
6368
ec2a523713b5 [project @ 2007-02-28 22:07:24 by jwe]
jwe
parents: 6310
diff changeset
201
18747
0585787aa8ae imshow.m: Overhaul function and support integer images (bug #41240).
Rik <rik@octave.org>
parents: 18746
diff changeset
202 if (truecolor || indexed)
0585787aa8ae imshow.m: Overhaul function and support integer images (bug #41240).
Rik <rik@octave.org>
parents: 18746
diff changeset
203 htmp = image (xdata, ydata, im);
5934
8702f00329bf [project @ 2006-08-17 20:29:51 by jwe]
jwe
parents: 5642
diff changeset
204 else
18747
0585787aa8ae imshow.m: Overhaul function and support integer images (bug #41240).
Rik <rik@octave.org>
parents: 18746
diff changeset
205 htmp = imagesc (xdata, ydata, im, display_range);
5934
8702f00329bf [project @ 2006-08-17 20:29:51 by jwe]
jwe
parents: 5642
diff changeset
206 endif
18747
0585787aa8ae imshow.m: Overhaul function and support integer images (bug #41240).
Rik <rik@octave.org>
parents: 18746
diff changeset
207 set (gca (), "visible", "off");
7511
f028e7aa77a7 imshow.m: use axis ("image")
John W. Eaton <jwe@octave.org>
parents: 7331
diff changeset
208 axis ("image");
7074
87151f298e6a [project @ 2007-10-26 17:57:34 by jwe]
jwe
parents: 7017
diff changeset
209
87151f298e6a [project @ 2007-10-26 17:57:34 by jwe]
jwe
parents: 7017
diff changeset
210 if (nargout > 0)
18747
0585787aa8ae imshow.m: Overhaul function and support integer images (bug #41240).
Rik <rik@octave.org>
parents: 18746
diff changeset
211 h = htmp;
7074
87151f298e6a [project @ 2007-10-26 17:57:34 by jwe]
jwe
parents: 7017
diff changeset
212 endif
87151f298e6a [project @ 2007-10-26 17:57:34 by jwe]
jwe
parents: 7017
diff changeset
213
559
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
214 endfunction
4836
518e495e489f [project @ 2004-03-12 18:16:03 by jwe]
jwe
parents: 3457
diff changeset
215
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
216
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
217 %!demo
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
218 %! clf;
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
219 %! imshow ("default.img");
4836
518e495e489f [project @ 2004-03-12 18:16:03 by jwe]
jwe
parents: 3457
diff changeset
220
518e495e489f [project @ 2004-03-12 18:16:03 by jwe]
jwe
parents: 3457
diff changeset
221 %!demo
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
222 %! clf;
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
223 %! imshow ("default.img");
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
224 %! colormap (autumn (64));
7074
87151f298e6a [project @ 2007-10-26 17:57:34 by jwe]
jwe
parents: 7017
diff changeset
225
87151f298e6a [project @ 2007-10-26 17:57:34 by jwe]
jwe
parents: 7017
diff changeset
226 %!demo
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
227 %! clf;
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
228 %! [I, M] = imread ("default.img");
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
229 %! imshow (I, M);
4836
518e495e489f [project @ 2004-03-12 18:16:03 by jwe]
jwe
parents: 3457
diff changeset
230
518e495e489f [project @ 2004-03-12 18:16:03 by jwe]
jwe
parents: 3457
diff changeset
231 %!demo
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
232 %! clf;
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
233 %! [I, M] = imread ("default.img");
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
234 %! [R, G, B] = ind2rgb (I, M);
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
235 %! imshow (cat (3, R, G*0.5, B*0.8));
5318
9a72639b62a7 [project @ 2005-04-28 18:44:27 by jwe]
jwe
parents: 5307
diff changeset
236
9a72639b62a7 [project @ 2005-04-28 18:44:27 by jwe]
jwe
parents: 5307
diff changeset
237 %!demo
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
238 %! clf;
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
239 %! imshow (rand (100, 100));
5318
9a72639b62a7 [project @ 2005-04-28 18:44:27 by jwe]
jwe
parents: 5307
diff changeset
240
9a72639b62a7 [project @ 2005-04-28 18:44:27 by jwe]
jwe
parents: 5307
diff changeset
241 %!demo
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
242 %! clf;
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
243 %! imshow (rand (100, 100, 3));
7074
87151f298e6a [project @ 2007-10-26 17:57:34 by jwe]
jwe
parents: 7017
diff changeset
244
87151f298e6a [project @ 2007-10-26 17:57:34 by jwe]
jwe
parents: 7017
diff changeset
245 %!demo
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
246 %! clf;
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
247 %! imshow (100*rand (100, 100, 3));
7074
87151f298e6a [project @ 2007-10-26 17:57:34 by jwe]
jwe
parents: 7017
diff changeset
248
87151f298e6a [project @ 2007-10-26 17:57:34 by jwe]
jwe
parents: 7017
diff changeset
249 %!demo
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
250 %! clf;
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
251 %! imshow (rand (100, 100));
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
252 %! colormap (jet (64));
7074
87151f298e6a [project @ 2007-10-26 17:57:34 by jwe]
jwe
parents: 7017
diff changeset
253
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
254 %% Test input validation
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
255 %!error imshow ()
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
256 %!error <IM must be an image> imshow ({"cell"})
18747
0585787aa8ae imshow.m: Overhaul function and support integer images (bug #41240).
Rik <rik@octave.org>
parents: 18746
diff changeset
257 %!error <TrueColor image must be uint8> imshow (ones (3,3,3, "uint32"))
0585787aa8ae imshow.m: Overhaul function and support integer images (bug #41240).
Rik <rik@octave.org>
parents: 18746
diff changeset
258 %!error <TrueColor image must be uint8> imshow (ones (3,3,3, "int16"))
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
259 %!error <expecting MxN or MxNx3 matrix> imshow (ones (4,4,4))
18747
0585787aa8ae imshow.m: Overhaul function and support integer images (bug #41240).
Rik <rik@octave.org>
parents: 18746
diff changeset
260 %!error <invalid colormap MAP> imshow ([1,1], [2 0 0])
0585787aa8ae imshow.m: Overhaul function and support integer images (bug #41240).
Rik <rik@octave.org>
parents: 18746
diff changeset
261 %!error <argument number 2 is invalid> imshow ([1,1], [1 0 0 0])
0585787aa8ae imshow.m: Overhaul function and support integer images (bug #41240).
Rik <rik@octave.org>
parents: 18746
diff changeset
262 %!error <invalid colormap> imshow ([1,1], "colormap", [2 0 0])
0585787aa8ae imshow.m: Overhaul function and support integer images (bug #41240).
Rik <rik@octave.org>
parents: 18746
diff changeset
263 %!error <xdata must be a vector> imshow ([1,1], "xdata", ones (2,2))
0585787aa8ae imshow.m: Overhaul function and support integer images (bug #41240).
Rik <rik@octave.org>
parents: 18746
diff changeset
264 %!error <ydata must be a vector> imshow ([1,1], "ydata", ones (2,2))
0585787aa8ae imshow.m: Overhaul function and support integer images (bug #41240).
Rik <rik@octave.org>
parents: 18746
diff changeset
265 %!warning <unrecognized property foobar> imshow ([1,1], "foobar")
0585787aa8ae imshow.m: Overhaul function and support integer images (bug #41240).
Rik <rik@octave.org>
parents: 18746
diff changeset
266 %!error <argument number 2 is invalid> imshow ([1,1], {1})
0585787aa8ae imshow.m: Overhaul function and support integer images (bug #41240).
Rik <rik@octave.org>
parents: 18746
diff changeset
267 %!warning <only showing real part of complex image> imshow ([1+i,1-i])
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
268