annotate scripts/plot/util/frame2im.m @ 19898:4197fc428c7d

maint: Update copyright notices for 2015.
author John W. Eaton <jwe@octave.org>
date Wed, 11 Feb 2015 14:19:08 -0500
parents e723e93ca2a0
children 9fc020886ae9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19898
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19603
diff changeset
1 ## Copyright (C) 2014-2015 Carnë Draug
19504
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
2 ##
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
3 ## This file is part of Octave.
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
4 ##
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
8 ## your option) any later version.
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
9 ##
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
13 ## General Public License for more details.
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
14 ##
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
17 ## <http://www.gnu.org/licenses/>.
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
18
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
19 ## -*- texinfo -*-
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
20 ## @deftypefn {Function File} {[@var{x}, @var{map}] =} frame2im (@var{f})
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
21 ## Convert movie frame to indexed image.
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
22 ##
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
23 ## A movie frame is simply a struct with the fields @qcode{"cdata"} and
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
24 ## @qcode{"colormap"}.
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
25 ##
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
26 ## Support for N-dimensional images or movies is given when @var{f} is a
19603
e723e93ca2a0 doc: Periodic spellcheck of documentation.
Rik <rik@octave.org>
parents: 19504
diff changeset
27 ## struct array. In such cases, @var{x} will be a @nospell{MxNx1xK or MxNx3xK}
e723e93ca2a0 doc: Periodic spellcheck of documentation.
Rik <rik@octave.org>
parents: 19504
diff changeset
28 ## for indexed and RGB movies respectively, with each frame concatenated on
19504
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
29 ## the 4th dimension.
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
30 ##
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
31 ## @seealso{im2frame}
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
32 ## @end deftypefn
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
33
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
34 ## Author: Carnë Draug <carandraug@octave.org>
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
35
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
36 function [x, map] = frame2im (frame)
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
37
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
38 if (nargin != 1)
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
39 print_usage ();
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
40 elseif (! all (isfield (frame, {"cdata", "colormap"})))
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
41 error ("frame2im: F must be a struct with the fields colormap and cdata");
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
42 endif
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
43
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
44 n = numel (frame);
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
45 if (n == 0)
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
46 error ("frame2im: FRAME is empty");
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
47 else
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
48 x = [frame.cdata];
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
49 map = frame(1).colormap;
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
50 endif
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
51
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
52 ## support for N dimensional images if we receive a struct array
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
53 if (n > 1)
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
54 x = reshape (x, rows (x), columns (x) / n, n, size (frame(1).cdata, 3));
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
55 x = permute (x, [1 2 4 3]);
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
56 endif
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
57
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
58 endfunction
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
59
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
60 %!function f = make_rgb_f ()
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
61 %! f = randi ([0 255], 10, 20, 3);
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
62 %!endfunction
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
63
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
64 %!function f = make_ind_f ()
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
65 %! f = randi ([1 100], 10, 20, 3);
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
66 %!endfunction
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
67
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
68 %!test
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
69 %! x = make_ind_f ();
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
70 %! cmap = jet (100);
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
71 %! frame = struct ("cdata", x, "colormap", cmap);
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
72 %! [rx, rcmap] = frame2im (frame);
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
73 %! assert (rx, x);
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
74 %! assert (rcmap, cmap);
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
75
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
76 %!test
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
77 %! rgb = make_rgb_f ();
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
78 %! frame = struct ("cdata", rgb, "colormap", []);
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
79 %! [rrgb, rcmap] = frame2im (frame);
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
80 %! assert (rrgb, rgb);
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
81 %! assert (rcmap, []);
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
82
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
83 %!test
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
84 %! f1 = make_rgb_f ();
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
85 %! f2 = make_rgb_f ();
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
86 %! f3 = make_rgb_f ();
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
87 %! f4 = make_rgb_f ();
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
88 %! rgb = {f1, f2, f3, f4};
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
89 %! movie = struct ("cdata", rgb, "colormap", []);
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
90 %! [rx, rcmap] = frame2im (movie);
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
91 %! assert (rx, cat (4, f1, f2, f3, f4));
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
92 %! assert (rcmap, []);
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
93
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
94 %!test
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
95 %! f1 = make_ind_f ();
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
96 %! f2 = make_ind_f ();
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
97 %! f3 = make_ind_f ();
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
98 %! f4 = make_ind_f ();
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
99 %! ind = {f1, f2, f3, f4};
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
100 %! cmap = jet (100);
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
101 %! movie = struct ("cdata", ind, "colormap", cmap);
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
102 %! [rx, rcmap] = frame2im (movie);
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
103 %! assert (rx, cat (4, f1, f2, f3, f4));
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
104 %! assert (rcmap, cmap);
39a69f54417e New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff changeset
105