Mercurial > octave
annotate scripts/image/frame2im.m @ 22959:8defe99c9650 stable
Move frame2im and im2frame to image/ directory (bug #49939).
* scripts/image/frame2im.m: Moved from plot/util/frame2im.m.
* scripts/image/im2frame.m: Moved from plot/util/im2frame.m.
Corrected BIST test.
* image.txi: Moved docstring for frame2im, im2frame to image chapter.
* plot.txi: Remove docstring for frame2im, im2frame.
author | Rik <rik@octave.org> |
---|---|
date | Tue, 27 Dec 2016 09:43:28 -0800 |
parents | scripts/plot/util/frame2im.m@7b190a2f11cb |
children | 5a8999b1c5f3 e9a0469dedd9 |
rev | line source |
---|---|
22323
bac0d6f07a3e
maint: Update copyright notices for 2016.
John W. Eaton <jwe@octave.org>
parents:
20852
diff
changeset
|
1 ## Copyright (C) 2014-2016 Carnë Draug |
19313
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 -*- |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20173
diff
changeset
|
20 ## @deftypefn {} {[@var{x}, @var{map}] =} frame2im (@var{f}) |
19313
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 |
19406
e723e93ca2a0
doc: Periodic spellcheck of documentation.
Rik <rik@octave.org>
parents:
19313
diff
changeset
|
27 ## struct array. In such cases, @var{x} will be a @nospell{MxNx1xK or MxNx3xK} |
20173
777f26aa8e3e
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
28 ## for indexed and RGB movies respectively, with each frame concatenated |
777f26aa8e3e
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
29 ## along the 4th dimension. |
19313
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 |
22959
8defe99c9650
Move frame2im and im2frame to image/ directory (bug #49939).
Rik <rik@octave.org>
parents:
22627
diff
changeset
|
52 ## support for N-dimensional images if we receive a struct array |
19313
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 |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
60 |
19313
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
61 %!function f = make_rgb_f () |
22627
7b190a2f11cb
maint: Use 2-space indent in definition of BIST %!functions.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
62 %! f = randi ([0 255], 10, 20, 3); |
19313
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 () |
22959
8defe99c9650
Move frame2im and im2frame to image/ directory (bug #49939).
Rik <rik@octave.org>
parents:
22627
diff
changeset
|
66 %! f = randi ([1 100], 10, 20, 2); |
19313
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 |