Mercurial > hg > octave-nkf
annotate scripts/image/private/ind2x.m @ 17176:abf384f5d243
maint: Remove unneeded input validation from internal fcns in private/ directories.
* scripts/general/private/__isequal__.m,
scripts/general/private/__splinen__.m,
scripts/image/private/__imwrite__.m,
scripts/image/private/ind2x.m,
scripts/miscellaneous/private/__xzip__.m,
scripts/miscellaneous/private/display_info_file.m,
scripts/pkg/private/describe.m,
scripts/pkg/private/get_forge_pkg.m,
scripts/pkg/private/unload_packages.m,
scripts/plot/private/__actual_axis_position__.m,
scripts/plot/private/__add_datasource__.m,
scripts/plot/private/__clabel__.m,
scripts/plot/private/__errcomm__.m,
scripts/plot/private/__errplot__.m,
scripts/plot/private/__fltk_print__.m,
scripts/plot/private/__gnuplot_get_var__.m,
scripts/plot/private/__go_draw_axes__.m,
scripts/plot/private/__go_draw_figure__.m,
scripts/plot/private/__interp_cube__.m,
scripts/plot/private/__line__.m,
scripts/plot/private/__next_line_color__.m,
scripts/plot/private/__next_line_style__.m,
scripts/plot/private/__plt__.m,
scripts/plot/private/__pltopt__.m,
scripts/signal/private/rectangle_lw.m,
scripts/signal/private/rectangle_sw.m,
scripts/signal/private/triangle_lw.m,
scripts/signal/private/triangle_sw.m,
scripts/sparse/private/__sprand_impl__.m,
scripts/statistics/models/private/logistic_regression_derivatives.m,
scripts/statistics/models/private/logistic_regression_likelihood.m:
Remove unneeded input validation from internal fcns in private/ directories.
author | Rik <rik@octave.org> |
---|---|
date | Sun, 04 Aug 2013 18:13:08 -0700 |
parents | 4c11e9bcb796 |
children | 1c89599167a6 |
rev | line source |
---|---|
15689
14b7679891dd
ind2sub ind2gray: merge common code in private function, expanding fix for images when integers, input check, and expansion of colormap to ind2gray.
Carnë Draug <carandraug+dev@gmail.com>
parents:
diff
changeset
|
1 ## Copyright (C) 1994-2012 John W. Eaton |
14b7679891dd
ind2sub ind2gray: merge common code in private function, expanding fix for images when integers, input check, and expansion of colormap to ind2gray.
Carnë Draug <carandraug+dev@gmail.com>
parents:
diff
changeset
|
2 ## Copyright (C) 2012 Carnë Draug |
14b7679891dd
ind2sub ind2gray: merge common code in private function, expanding fix for images when integers, input check, and expansion of colormap to ind2gray.
Carnë Draug <carandraug+dev@gmail.com>
parents:
diff
changeset
|
3 ## |
14b7679891dd
ind2sub ind2gray: merge common code in private function, expanding fix for images when integers, input check, and expansion of colormap to ind2gray.
Carnë Draug <carandraug+dev@gmail.com>
parents:
diff
changeset
|
4 ## This file is part of Octave. |
14b7679891dd
ind2sub ind2gray: merge common code in private function, expanding fix for images when integers, input check, and expansion of colormap to ind2gray.
Carnë Draug <carandraug+dev@gmail.com>
parents:
diff
changeset
|
5 ## |
14b7679891dd
ind2sub ind2gray: merge common code in private function, expanding fix for images when integers, input check, and expansion of colormap to ind2gray.
Carnë Draug <carandraug+dev@gmail.com>
parents:
diff
changeset
|
6 ## Octave is free software; you can redistribute it and/or modify it |
14b7679891dd
ind2sub ind2gray: merge common code in private function, expanding fix for images when integers, input check, and expansion of colormap to ind2gray.
Carnë Draug <carandraug+dev@gmail.com>
parents:
diff
changeset
|
7 ## under the terms of the GNU General Public License as published by |
14b7679891dd
ind2sub ind2gray: merge common code in private function, expanding fix for images when integers, input check, and expansion of colormap to ind2gray.
Carnë Draug <carandraug+dev@gmail.com>
parents:
diff
changeset
|
8 ## the Free Software Foundation; either version 3 of the License, or (at |
14b7679891dd
ind2sub ind2gray: merge common code in private function, expanding fix for images when integers, input check, and expansion of colormap to ind2gray.
Carnë Draug <carandraug+dev@gmail.com>
parents:
diff
changeset
|
9 ## your option) any later version. |
14b7679891dd
ind2sub ind2gray: merge common code in private function, expanding fix for images when integers, input check, and expansion of colormap to ind2gray.
Carnë Draug <carandraug+dev@gmail.com>
parents:
diff
changeset
|
10 ## |
14b7679891dd
ind2sub ind2gray: merge common code in private function, expanding fix for images when integers, input check, and expansion of colormap to ind2gray.
Carnë Draug <carandraug+dev@gmail.com>
parents:
diff
changeset
|
11 ## Octave is distributed in the hope that it will be useful, but |
14b7679891dd
ind2sub ind2gray: merge common code in private function, expanding fix for images when integers, input check, and expansion of colormap to ind2gray.
Carnë Draug <carandraug+dev@gmail.com>
parents:
diff
changeset
|
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
14b7679891dd
ind2sub ind2gray: merge common code in private function, expanding fix for images when integers, input check, and expansion of colormap to ind2gray.
Carnë Draug <carandraug+dev@gmail.com>
parents:
diff
changeset
|
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14b7679891dd
ind2sub ind2gray: merge common code in private function, expanding fix for images when integers, input check, and expansion of colormap to ind2gray.
Carnë Draug <carandraug+dev@gmail.com>
parents:
diff
changeset
|
14 ## General Public License for more details. |
14b7679891dd
ind2sub ind2gray: merge common code in private function, expanding fix for images when integers, input check, and expansion of colormap to ind2gray.
Carnë Draug <carandraug+dev@gmail.com>
parents:
diff
changeset
|
15 ## |
14b7679891dd
ind2sub ind2gray: merge common code in private function, expanding fix for images when integers, input check, and expansion of colormap to ind2gray.
Carnë Draug <carandraug+dev@gmail.com>
parents:
diff
changeset
|
16 ## You should have received a copy of the GNU General Public License |
14b7679891dd
ind2sub ind2gray: merge common code in private function, expanding fix for images when integers, input check, and expansion of colormap to ind2gray.
Carnë Draug <carandraug+dev@gmail.com>
parents:
diff
changeset
|
17 ## along with Octave; see the file COPYING. If not, see |
14b7679891dd
ind2sub ind2gray: merge common code in private function, expanding fix for images when integers, input check, and expansion of colormap to ind2gray.
Carnë Draug <carandraug+dev@gmail.com>
parents:
diff
changeset
|
18 ## <http://www.gnu.org/licenses/>. |
14b7679891dd
ind2sub ind2gray: merge common code in private function, expanding fix for images when integers, input check, and expansion of colormap to ind2gray.
Carnë Draug <carandraug+dev@gmail.com>
parents:
diff
changeset
|
19 |
15714
b1cd65881592
Clean up scripts in image directory.
Rik <rik@octave.org>
parents:
15712
diff
changeset
|
20 ## private function for the ind2XXX functions which have a lot of code in common |
15689
14b7679891dd
ind2sub ind2gray: merge common code in private function, expanding fix for images when integers, input check, and expansion of colormap to ind2gray.
Carnë Draug <carandraug+dev@gmail.com>
parents:
diff
changeset
|
21 |
15714
b1cd65881592
Clean up scripts in image directory.
Rik <rik@octave.org>
parents:
15712
diff
changeset
|
22 function [x, map] = ind2x (caller, x, map) |
15689
14b7679891dd
ind2sub ind2gray: merge common code in private function, expanding fix for images when integers, input check, and expansion of colormap to ind2gray.
Carnë Draug <carandraug+dev@gmail.com>
parents:
diff
changeset
|
23 |
14b7679891dd
ind2sub ind2gray: merge common code in private function, expanding fix for images when integers, input check, and expansion of colormap to ind2gray.
Carnë Draug <carandraug+dev@gmail.com>
parents:
diff
changeset
|
24 ## Check if X is an indexed image. |
17176
abf384f5d243
maint: Remove unneeded input validation from internal fcns in private/ directories.
Rik <rik@octave.org>
parents:
16707
diff
changeset
|
25 ## an indexed image is defined has having only 2D, and that's how Matlab |
abf384f5d243
maint: Remove unneeded input validation from internal fcns in private/ directories.
Rik <rik@octave.org>
parents:
16707
diff
changeset
|
26 ## behaves. But we want to support ND images, so we will allow up to 4D |
16707
4c11e9bcb796
ind2rgb: add support for multidimensional indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16434
diff
changeset
|
27 ## and check that the 3rd is a singleton |
4c11e9bcb796
ind2rgb: add support for multidimensional indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16434
diff
changeset
|
28 if (all (ndims (x) != [2 4]) || size (x, 3) != 1 || issparse (x) || |
4c11e9bcb796
ind2rgb: add support for multidimensional indexed images.
Carnë Draug <carandraug@octave.org>
parents:
16434
diff
changeset
|
29 (isfloat (x) && ! isindex (x)) || |
15714
b1cd65881592
Clean up scripts in image directory.
Rik <rik@octave.org>
parents:
15712
diff
changeset
|
30 ! any (strcmp (class (x), {"uint8", "uint16", "single", "double"}))) |
b1cd65881592
Clean up scripts in image directory.
Rik <rik@octave.org>
parents:
15712
diff
changeset
|
31 error ("%s: X must be an indexed image", caller); |
15689
14b7679891dd
ind2sub ind2gray: merge common code in private function, expanding fix for images when integers, input check, and expansion of colormap to ind2gray.
Carnë Draug <carandraug+dev@gmail.com>
parents:
diff
changeset
|
32 endif |
14b7679891dd
ind2sub ind2gray: merge common code in private function, expanding fix for images when integers, input check, and expansion of colormap to ind2gray.
Carnë Draug <carandraug+dev@gmail.com>
parents:
diff
changeset
|
33 |
15714
b1cd65881592
Clean up scripts in image directory.
Rik <rik@octave.org>
parents:
15712
diff
changeset
|
34 ## Check if map is a valid colormap. |
15689
14b7679891dd
ind2sub ind2gray: merge common code in private function, expanding fix for images when integers, input check, and expansion of colormap to ind2gray.
Carnë Draug <carandraug+dev@gmail.com>
parents:
diff
changeset
|
35 if (! iscolormap (map)) |
15714
b1cd65881592
Clean up scripts in image directory.
Rik <rik@octave.org>
parents:
15712
diff
changeset
|
36 error ("%s: MAP must be a valid colormap", caller); |
15689
14b7679891dd
ind2sub ind2gray: merge common code in private function, expanding fix for images when integers, input check, and expansion of colormap to ind2gray.
Carnë Draug <carandraug+dev@gmail.com>
parents:
diff
changeset
|
37 endif |
14b7679891dd
ind2sub ind2gray: merge common code in private function, expanding fix for images when integers, input check, and expansion of colormap to ind2gray.
Carnë Draug <carandraug+dev@gmail.com>
parents:
diff
changeset
|
38 |
14b7679891dd
ind2sub ind2gray: merge common code in private function, expanding fix for images when integers, input check, and expansion of colormap to ind2gray.
Carnë Draug <carandraug+dev@gmail.com>
parents:
diff
changeset
|
39 ## Do we have enough colors in the color map? |
14b7679891dd
ind2sub ind2gray: merge common code in private function, expanding fix for images when integers, input check, and expansion of colormap to ind2gray.
Carnë Draug <carandraug+dev@gmail.com>
parents:
diff
changeset
|
40 ## there's an offset of 1 when the indexed image is an integer class so we fix |
14b7679891dd
ind2sub ind2gray: merge common code in private function, expanding fix for images when integers, input check, and expansion of colormap to ind2gray.
Carnë Draug <carandraug+dev@gmail.com>
parents:
diff
changeset
|
41 ## it now and convert it to float only if really necessary and even then only |
15714
b1cd65881592
Clean up scripts in image directory.
Rik <rik@octave.org>
parents:
15712
diff
changeset
|
42 ## to single precision since that is enough for both uint8 and uint16. |
15689
14b7679891dd
ind2sub ind2gray: merge common code in private function, expanding fix for images when integers, input check, and expansion of colormap to ind2gray.
Carnë Draug <carandraug+dev@gmail.com>
parents:
diff
changeset
|
43 maxidx = max (x(:)); |
14b7679891dd
ind2sub ind2gray: merge common code in private function, expanding fix for images when integers, input check, and expansion of colormap to ind2gray.
Carnë Draug <carandraug+dev@gmail.com>
parents:
diff
changeset
|
44 if (isinteger (x)) |
14b7679891dd
ind2sub ind2gray: merge common code in private function, expanding fix for images when integers, input check, and expansion of colormap to ind2gray.
Carnë Draug <carandraug+dev@gmail.com>
parents:
diff
changeset
|
45 if (maxidx == intmax (class (x))) |
14b7679891dd
ind2sub ind2gray: merge common code in private function, expanding fix for images when integers, input check, and expansion of colormap to ind2gray.
Carnë Draug <carandraug+dev@gmail.com>
parents:
diff
changeset
|
46 x = single (x); |
14b7679891dd
ind2sub ind2gray: merge common code in private function, expanding fix for images when integers, input check, and expansion of colormap to ind2gray.
Carnë Draug <carandraug+dev@gmail.com>
parents:
diff
changeset
|
47 endif |
14b7679891dd
ind2sub ind2gray: merge common code in private function, expanding fix for images when integers, input check, and expansion of colormap to ind2gray.
Carnë Draug <carandraug+dev@gmail.com>
parents:
diff
changeset
|
48 x += 1; |
14b7679891dd
ind2sub ind2gray: merge common code in private function, expanding fix for images when integers, input check, and expansion of colormap to ind2gray.
Carnë Draug <carandraug+dev@gmail.com>
parents:
diff
changeset
|
49 maxidx += 1; |
14b7679891dd
ind2sub ind2gray: merge common code in private function, expanding fix for images when integers, input check, and expansion of colormap to ind2gray.
Carnë Draug <carandraug+dev@gmail.com>
parents:
diff
changeset
|
50 endif |
14b7679891dd
ind2sub ind2gray: merge common code in private function, expanding fix for images when integers, input check, and expansion of colormap to ind2gray.
Carnë Draug <carandraug+dev@gmail.com>
parents:
diff
changeset
|
51 |
15714
b1cd65881592
Clean up scripts in image directory.
Rik <rik@octave.org>
parents:
15712
diff
changeset
|
52 num_colors = rows (map); |
b1cd65881592
Clean up scripts in image directory.
Rik <rik@octave.org>
parents:
15712
diff
changeset
|
53 if (num_colors < maxidx) |
17176
abf384f5d243
maint: Remove unneeded input validation from internal fcns in private/ directories.
Rik <rik@octave.org>
parents:
16707
diff
changeset
|
54 ## Pad with the last color in the map for Matlab compatibility |
15714
b1cd65881592
Clean up scripts in image directory.
Rik <rik@octave.org>
parents:
15712
diff
changeset
|
55 pad = repmat (map(end,:), maxidx - num_colors, 1); |
15689
14b7679891dd
ind2sub ind2gray: merge common code in private function, expanding fix for images when integers, input check, and expansion of colormap to ind2gray.
Carnë Draug <carandraug+dev@gmail.com>
parents:
diff
changeset
|
56 map(end+1:maxidx, :) = pad; |
14b7679891dd
ind2sub ind2gray: merge common code in private function, expanding fix for images when integers, input check, and expansion of colormap to ind2gray.
Carnë Draug <carandraug+dev@gmail.com>
parents:
diff
changeset
|
57 endif |
14b7679891dd
ind2sub ind2gray: merge common code in private function, expanding fix for images when integers, input check, and expansion of colormap to ind2gray.
Carnë Draug <carandraug+dev@gmail.com>
parents:
diff
changeset
|
58 |
14b7679891dd
ind2sub ind2gray: merge common code in private function, expanding fix for images when integers, input check, and expansion of colormap to ind2gray.
Carnë Draug <carandraug+dev@gmail.com>
parents:
diff
changeset
|
59 endfunction |