Mercurial > hg > octave-avbm
comparison scripts/image/rgb2ind.m @ 15714:b1cd65881592
Clean up scripts in image directory.
Use Octave coding conventions. Redo docstrings. Add %!tests.
* brighten.m: Put input validation first. Use iscolormap to simplify
input checking.
* cmunique.m: Use faster method of validating input class.
* colormap.m: Tweak docstring. Improve input validation.
* contrast.m: Tweak docstring. Use cmap instead of map as variable
name for clarity.
* gray2ind.m: Wrap long lines. Use faster method of validating input class.
Delete unreachable code for n>65536.
* hsv2rgb.m: Use faster method of validating input class.
* imwrite.m: Tweak FIXME notes.
* ind2gray.m: Use correct caller name for ind2x. Update %!tests
with new 2-input calling convention.
* ind2rgb.m: Tweak docstring. Update %!tests with new 2-input
calling convention.
* iscolormap.m: Tweak docstring. Re-order validation tests.
* ntsc2rgb.m: Use faster method of validating input class. Better input
validation. Add %!tests.
* private/ind2x.m: Use more descriptive variable names.
* rgb2hsv.m: Tweak docstring. Use faster method of validating input class.
* rgb2ind.m: Tweak docstring. Wrap long lines.
* rgb2ntsc.m: Use faster method of validating input class. Improve input
validation. Add %!tests.
* rgbplot.m: Match variable names in docstring to those in function
prototype.
author | Rik <rik@octave.org> |
---|---|
date | Sun, 02 Dec 2012 10:02:57 -0800 |
parents | a1b634240352 |
children | 6ae93518356c |
comparison
equal
deleted
inserted
replaced
15713:168e380c8f18 | 15714:b1cd65881592 |
---|---|
18 ## <http://www.gnu.org/licenses/>. | 18 ## <http://www.gnu.org/licenses/>. |
19 | 19 |
20 ## -*- texinfo -*- | 20 ## -*- texinfo -*- |
21 ## @deftypefn {Function File} {[@var{x}, @var{map}] =} rgb2ind (@var{rgb}) | 21 ## @deftypefn {Function File} {[@var{x}, @var{map}] =} rgb2ind (@var{rgb}) |
22 ## @deftypefnx {Function File} {[@var{x}, @var{map}] =} rgb2ind (@var{R}, @var{G}, @var{B}) | 22 ## @deftypefnx {Function File} {[@var{x}, @var{map}] =} rgb2ind (@var{R}, @var{G}, @var{B}) |
23 ## Convert an image in red-green-blue (RGB) space to an indexed image. | 23 ## Convert an image in red-green-blue (RGB) color space to an indexed image. |
24 ## @seealso{ind2rgb, rgb2hsv, rgb2ntsc} | 24 ## @seealso{ind2rgb, rgb2hsv, rgb2ntsc} |
25 ## @end deftypefn | 25 ## @end deftypefn |
26 | 26 |
27 ## FIXME: This function has a very different syntax than the Matlab one of the same name. | 27 ## FIXME: This function has a very different syntax than the Matlab |
28 ## Octave function does no support N, MAP, DITHER, or TOL arguments | 28 ## one of the same name. |
29 ## Octave function does not support N, MAP, DITHER, or TOL arguments. | |
30 | |
29 ## Author: Tony Richardson <arichard@stark.cc.oh.us> | 31 ## Author: Tony Richardson <arichard@stark.cc.oh.us> |
30 ## Created: July 1994 | 32 ## Created: July 1994 |
31 ## Adapted-By: jwe | 33 ## Adapted-By: jwe |
32 | 34 |
33 function [x, map] = rgb2ind (R, G, B) | 35 function [x, map] = rgb2ind (R, G, B) |
49 error ("rgb2ind: R, G, and B must have the same size"); | 51 error ("rgb2ind: R, G, and B must have the same size"); |
50 endif | 52 endif |
51 | 53 |
52 x = reshape (1:numel (R), size (R)); | 54 x = reshape (1:numel (R), size (R)); |
53 | 55 |
54 map = unique([R(:) G(:) B(:)], "rows"); | 56 map = unique ([R(:) G(:) B(:)], "rows"); |
55 [~, x] = ismember ([R(:) G(:) B(:)], map, "rows"); | 57 [~, x] = ismember ([R(:) G(:) B(:)], map, "rows"); |
56 x = reshape (x, size (R)); | 58 x = reshape (x, size (R)); |
57 | 59 |
58 ## a colormap is of class double and values between 0 and 1 | 60 ## a colormap is of class double and values between 0 and 1 |
59 switch class (R) | 61 switch class (R) |
76 elseif (rows (map) < 65536) | 78 elseif (rows (map) < 65536) |
77 x = uint16 (x - 1); | 79 x = uint16 (x - 1); |
78 else | 80 else |
79 ## leave it as double | 81 ## leave it as double |
80 endif | 82 endif |
83 | |
81 endfunction | 84 endfunction |
85 | |
82 | 86 |
83 %% FIXME: Need some functional tests or %!demo blocks | 87 %% FIXME: Need some functional tests or %!demo blocks |
84 | 88 |
85 %% Test input validation | 89 %% Test input validation |
86 %!error rgb2ind () | 90 %!error rgb2ind () |
87 %!error rgb2ind (1,2) | 91 %!error rgb2ind (1,2) |
88 %!error rgb2ind (1,2,3,4) | 92 %!error rgb2ind (1,2,3,4) |
93 |