Mercurial > hg > octave-nkf
comparison scripts/image/rgb2ind.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 | a1b634240352 |
comparison
equal
deleted
inserted
replaced
15682:48e3841a7510 | 15683:806ea52af230 |
---|---|
22 ## Convert an image in red-green-blue (RGB) space to an indexed image. | 22 ## Convert an image in red-green-blue (RGB) space to an indexed image. |
23 ## @seealso{ind2rgb, rgb2hsv, rgb2ntsc} | 23 ## @seealso{ind2rgb, rgb2hsv, rgb2ntsc} |
24 ## @end deftypefn | 24 ## @end deftypefn |
25 | 25 |
26 ## Bugs: The color map may have duplicate entries. | 26 ## Bugs: The color map may have duplicate entries. |
27 | 27 ## FIXME: This function has a very different syntax than the Matlab one of the same name. |
28 ## Octave function does no support N, MAP, DITHER, or TOL arguments | |
28 ## Author: Tony Richardson <arichard@stark.cc.oh.us> | 29 ## Author: Tony Richardson <arichard@stark.cc.oh.us> |
29 ## Created: July 1994 | 30 ## Created: July 1994 |
30 ## Adapted-By: jwe | 31 ## Adapted-By: jwe |
31 | 32 |
32 function [x, map] = rgb2ind (R, G, B) | 33 function [x, map] = rgb2ind (R, G, B) |
35 print_usage (); | 36 print_usage (); |
36 endif | 37 endif |
37 | 38 |
38 if (nargin == 1) | 39 if (nargin == 1) |
39 rgb = R; | 40 rgb = R; |
40 if (length (size (rgb)) == 3 && size (rgb, 3) == 3) | 41 if (ndims (rgb) != 3 || size (rgb, 3) != 3) |
42 error ("rgb2ind: argument is not an RGB image"); | |
43 else | |
41 R = rgb(:,:,1); | 44 R = rgb(:,:,1); |
42 G = rgb(:,:,2); | 45 G = rgb(:,:,2); |
43 B = rgb(:,:,3); | 46 B = rgb(:,:,3); |
44 else | |
45 error ("rgb2ind: argument is not an RGB image"); | |
46 endif | 47 endif |
48 elseif (! size_equal (R, G, B)) | |
49 error ("rgb2ind: R, G, and B must have the same size"); | |
47 endif | 50 endif |
48 | 51 |
49 if (! size_equal (R, G) || ! size_equal (R, B)) | 52 x = reshape (1:numel (R), size (R)); |
50 error ("rgb2ind: arguments must all have the same size"); | |
51 endif | |
52 | 53 |
53 [hi, wi] = size (R); | 54 map = [R(:), G(:), B(:)]; |
54 | |
55 x = zeros (hi, wi); | |
56 | |
57 map = zeros (hi*wi, 3); | |
58 | |
59 map(:,1) = R(:); | |
60 map(:,2) = G(:); | |
61 map(:,3) = B(:); | |
62 | |
63 x(:) = 1:(hi*wi); | |
64 | 55 |
65 endfunction | 56 endfunction |
57 | |
58 | |
59 %% FIXME: Need some functional tests or %!demo blocks | |
60 | |
61 %% Test input validation | |
62 %!error rgb2ind () | |
63 %!error rgb2ind (1,2) | |
64 %!error rgb2ind (1,2,3,4) | |
65 |