Mercurial > hg > octave-nkf
annotate scripts/plot/util/frame2im.m @ 20177:15e5eb7a0c1d
make dist: add updated zoom images to EXTRADIST (bug #44579)
* libgui/graphics/module.mk: add graphics/images/zoom-in.png, graphics/images/zoom-out.png, remove graphics/images/zoom.png
author | John Donoghue |
---|---|
date | Thu, 19 Mar 2015 08:37:47 -0400 |
parents | 9fc020886ae9 |
children | 777f26aa8e3e |
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 |
20038
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
60 |
19504
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
61 %!function f = make_rgb_f () |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
62 %! f = randi ([0 255], 10, 20, 3); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
63 %!endfunction |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
64 |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
65 %!function f = make_ind_f () |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
66 %! f = randi ([1 100], 10, 20, 3); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
67 %!endfunction |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
68 |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
69 %!test |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
70 %! x = make_ind_f (); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
71 %! cmap = jet (100); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
72 %! frame = struct ("cdata", x, "colormap", cmap); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
73 %! [rx, rcmap] = frame2im (frame); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
74 %! assert (rx, x); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
75 %! assert (rcmap, cmap); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
76 |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
77 %!test |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
78 %! rgb = make_rgb_f (); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
79 %! frame = struct ("cdata", rgb, "colormap", []); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
80 %! [rrgb, rcmap] = frame2im (frame); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
81 %! assert (rrgb, rgb); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
82 %! assert (rcmap, []); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
83 |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
84 %!test |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
85 %! f1 = make_rgb_f (); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
86 %! f2 = make_rgb_f (); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
87 %! f3 = make_rgb_f (); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
88 %! f4 = make_rgb_f (); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
89 %! rgb = {f1, f2, f3, f4}; |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
90 %! movie = struct ("cdata", rgb, "colormap", []); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
91 %! [rx, rcmap] = frame2im (movie); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
92 %! assert (rx, cat (4, f1, f2, f3, f4)); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
93 %! assert (rcmap, []); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
94 |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
95 %!test |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
96 %! f1 = make_ind_f (); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
97 %! f2 = make_ind_f (); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
98 %! f3 = make_ind_f (); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
99 %! f4 = make_ind_f (); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
100 %! ind = {f1, f2, f3, f4}; |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
101 %! cmap = jet (100); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
102 %! movie = struct ("cdata", ind, "colormap", cmap); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
103 %! [rx, rcmap] = frame2im (movie); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
104 %! assert (rx, cat (4, f1, f2, f3, f4)); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
105 %! assert (rcmap, cmap); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
106 |