Mercurial > octave
annotate scripts/image/frame2im.m @ 33596:96a203bc7e17 bytecode-interpreter tip
maint: Merge default to bytecode-interpreter
author | Nicholas R. Jankowski <jankowski.nicholas@gmail.com> |
---|---|
date | Fri, 17 May 2024 22:49:58 -0400 |
parents | 2e484f9f1f18 |
children |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 ######################################################################## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 ## |
32632
2e484f9f1f18
maint: update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
31706
diff
changeset
|
3 ## Copyright (C) 2014-2024 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
4 ## |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 ## See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 ## distribution or <https://octave.org/copyright/>. |
19313
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
7 ## |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
8 ## This file is part of Octave. |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
9 ## |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23535
diff
changeset
|
10 ## Octave is free software: you can redistribute it and/or modify it |
19313
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
11 ## under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23535
diff
changeset
|
12 ## the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22627
diff
changeset
|
13 ## (at your option) any later version. |
19313
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 ## 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
|
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22627
diff
changeset
|
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22627
diff
changeset
|
18 ## GNU General Public License for more details. |
19313
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
19 ## |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
20 ## 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
|
21 ## along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23535
diff
changeset
|
22 ## <https://www.gnu.org/licenses/>. |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 ## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 ######################################################################## |
19313
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 ## -*- texinfo -*- |
22765
01aae08a0105
maint: Rename variables to match documentation in m-files.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
27 ## @deftypefn {} {[@var{x}, @var{map}] =} frame2im (@var{frame}) |
19313
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
28 ## Convert movie frame to indexed image. |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
29 ## |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
30 ## 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
|
31 ## @qcode{"colormap"}. |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
32 ## |
22765
01aae08a0105
maint: Rename variables to match documentation in m-files.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
33 ## Support for N-dimensional images or movies is given when @var{frame} is a |
19406
e723e93ca2a0
doc: Periodic spellcheck of documentation.
Rik <rik@octave.org>
parents:
19313
diff
changeset
|
34 ## 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
|
35 ## 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
|
36 ## along the 4th dimension. |
19313
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
37 ## |
23535
2aab625b502c
Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
23220
diff
changeset
|
38 ## @seealso{im2frame, getframe} |
19313
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
39 ## @end deftypefn |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
40 |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
41 function [x, map] = frame2im (frame) |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
42 |
28891
de5f2f9a64ff
maint: Use same coding style when checking for a minimum of 1 input.
Rik <rik@octave.org>
parents:
27978
diff
changeset
|
43 if (nargin < 1) |
19313
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
44 print_usage (); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
45 elseif (! all (isfield (frame, {"cdata", "colormap"}))) |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
46 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
|
47 endif |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
48 |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
49 n = numel (frame); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
50 if (n == 0) |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
51 error ("frame2im: FRAME is empty"); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
52 else |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
53 x = [frame.cdata]; |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
54 map = frame(1).colormap; |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
55 endif |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
56 |
22959
8defe99c9650
Move frame2im and im2frame to image/ directory (bug #49939).
Rik <rik@octave.org>
parents:
22627
diff
changeset
|
57 ## 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
|
58 if (n > 1) |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
59 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
|
60 x = permute (x, [1 2 4 3]); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
61 endif |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
62 |
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 |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
65 |
19313
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
66 %!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
|
67 %! f = randi ([0 255], 10, 20, 3); |
19313
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
68 %!endfunction |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
69 |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
70 %!function f = make_ind_f () |
22959
8defe99c9650
Move frame2im and im2frame to image/ directory (bug #49939).
Rik <rik@octave.org>
parents:
22627
diff
changeset
|
71 %! f = randi ([1 100], 10, 20, 2); |
19313
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
72 %!endfunction |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
73 |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
74 %!test |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
75 %! x = make_ind_f (); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
76 %! cmap = jet (100); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
77 %! frame = struct ("cdata", x, "colormap", cmap); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
78 %! [rx, rcmap] = frame2im (frame); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
79 %! assert (rx, x); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
80 %! assert (rcmap, cmap); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
81 |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
82 %!test |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
83 %! rgb = make_rgb_f (); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
84 %! frame = struct ("cdata", rgb, "colormap", []); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
85 %! [rrgb, rcmap] = frame2im (frame); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
86 %! assert (rrgb, rgb); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
87 %! assert (rcmap, []); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
88 |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
89 %!test |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
90 %! f1 = make_rgb_f (); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
91 %! f2 = make_rgb_f (); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
92 %! f3 = make_rgb_f (); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
93 %! f4 = make_rgb_f (); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
94 %! rgb = {f1, f2, f3, f4}; |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
95 %! movie = struct ("cdata", rgb, "colormap", []); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
96 %! [rx, rcmap] = frame2im (movie); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
97 %! assert (rx, cat (4, f1, f2, f3, f4)); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
98 %! assert (rcmap, []); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
99 |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
100 %!test |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
101 %! f1 = make_ind_f (); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
102 %! f2 = make_ind_f (); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
103 %! f3 = make_ind_f (); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
104 %! f4 = make_ind_f (); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
105 %! ind = {f1, f2, f3, f4}; |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
106 %! cmap = jet (100); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
107 %! movie = struct ("cdata", ind, "colormap", cmap); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
108 %! [rx, rcmap] = frame2im (movie); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
109 %! assert (rx, cat (4, f1, f2, f3, f4)); |
39a69f54417e
New functions im2frame and frame2im.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
110 %! assert (rcmap, cmap); |