# HG changeset patch # User Carnë Draug # Date 1415308204 0 # Node ID 39a69f54417e1ec178061a6f47d5d01530513423 # Parent 912158cf524d4ff189051870d8b619e13a00f924 New functions im2frame and frame2im. * plot/util/im2frame.m, plot/util/frame2im.m: new function files. * __unimplemented__.m: remove functions from list. * plot/util/module.mk: add files to build system. * interpreter/plot.txi: add entries for these functions in the advanced plotting section, next to comet which creates animated plots. * NEWS: add functions to list of new functions for 4.2.0. diff -r 912158cf524d -r 39a69f54417e NEWS --- a/NEWS Wed Nov 05 12:45:44 2014 -0500 +++ b/NEWS Thu Nov 06 21:10:04 2014 +0000 @@ -96,10 +96,12 @@ bandwidth dir_in_loadpath flip + frame2im hgload hgsave ichol ilu + im2frame isbanded isdiag istril diff -r 912158cf524d -r 39a69f54417e doc/interpreter/plot.txi --- a/doc/interpreter/plot.txi Wed Nov 05 12:45:44 2014 -0500 +++ b/doc/interpreter/plot.txi Thu Nov 06 21:10:04 2014 +0000 @@ -237,6 +237,10 @@ @DOCSTRING(comet3) +@DOCSTRING(frame2im) + +@DOCSTRING(im2frame) + @node Axis Configuration @subsubsection Axis Configuration diff -r 912158cf524d -r 39a69f54417e scripts/help/__unimplemented__.m --- a/scripts/help/__unimplemented__.m Wed Nov 05 12:45:44 2014 -0500 +++ b/scripts/help/__unimplemented__.m Thu Nov 06 21:10:04 2014 +0000 @@ -637,7 +637,6 @@ "fitsread", "fitswrite", "flow", - "frame2im", "freqspace", "funm", "gammaincinv", @@ -664,7 +663,6 @@ "hgexport", "hgsetget", "hgtransform", - "im2frame", "im2java", "imapprox", "import", diff -r 912158cf524d -r 39a69f54417e scripts/plot/util/frame2im.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/plot/util/frame2im.m Thu Nov 06 21:10:04 2014 +0000 @@ -0,0 +1,105 @@ +## Copyright (C) 2014 Carnë Draug +## +## This file is part of Octave. +## +## Octave is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or (at +## your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## . + +## -*- texinfo -*- +## @deftypefn {Function File} {[@var{x}, @var{map}] =} frame2im (@var{f}) +## Convert movie frame to indexed image. +## +## A movie frame is simply a struct with the fields @qcode{"cdata"} and +## @qcode{"colormap"}. +## +## Support for N-dimensional images or movies is given when @var{f} is a +## struct array. In such cases, @var{x} will be a MxNx1xK or MxNx3xK for +## indexed and RGB movies respectively, with each frame concatenated on +## the 4th dimension. +## +## @seealso{im2frame} +## @end deftypefn + +## Author: Carnë Draug + +function [x, map] = frame2im (frame) + + if (nargin != 1) + print_usage (); + elseif (! all (isfield (frame, {"cdata", "colormap"}))) + error ("frame2im: F must be a struct with the fields colormap and cdata"); + endif + + n = numel (frame); + if (n == 0) + error ("frame2im: FRAME is empty"); + else + x = [frame.cdata]; + map = frame(1).colormap; + endif + + ## support for N dimensional images if we receive a struct array + if (n > 1) + x = reshape (x, rows (x), columns (x) / n, n, size (frame(1).cdata, 3)); + x = permute (x, [1 2 4 3]); + endif + +endfunction + +%!function f = make_rgb_f () +%! f = randi ([0 255], 10, 20, 3); +%!endfunction + +%!function f = make_ind_f () +%! f = randi ([1 100], 10, 20, 3); +%!endfunction + +%!test +%! x = make_ind_f (); +%! cmap = jet (100); +%! frame = struct ("cdata", x, "colormap", cmap); +%! [rx, rcmap] = frame2im (frame); +%! assert (rx, x); +%! assert (rcmap, cmap); + +%!test +%! rgb = make_rgb_f (); +%! frame = struct ("cdata", rgb, "colormap", []); +%! [rrgb, rcmap] = frame2im (frame); +%! assert (rrgb, rgb); +%! assert (rcmap, []); + +%!test +%! f1 = make_rgb_f (); +%! f2 = make_rgb_f (); +%! f3 = make_rgb_f (); +%! f4 = make_rgb_f (); +%! rgb = {f1, f2, f3, f4}; +%! movie = struct ("cdata", rgb, "colormap", []); +%! [rx, rcmap] = frame2im (movie); +%! assert (rx, cat (4, f1, f2, f3, f4)); +%! assert (rcmap, []); + +%!test +%! f1 = make_ind_f (); +%! f2 = make_ind_f (); +%! f3 = make_ind_f (); +%! f4 = make_ind_f (); +%! ind = {f1, f2, f3, f4}; +%! cmap = jet (100); +%! movie = struct ("cdata", ind, "colormap", cmap); +%! [rx, rcmap] = frame2im (movie); +%! assert (rx, cat (4, f1, f2, f3, f4)); +%! assert (rcmap, cmap); + diff -r 912158cf524d -r 39a69f54417e scripts/plot/util/im2frame.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/plot/util/im2frame.m Thu Nov 06 21:10:04 2014 +0000 @@ -0,0 +1,101 @@ +## Copyright (C) 2014 Carnë Draug +## +## This file is part of Octave. +## +## Octave is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or (at +## your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## . + +## -*- texinfo -*- +## @deftypefn {Function File} {} im2frame (@var{rgb}) +## @deftypefnx {Function File} {} im2frame (@var{x}, @var{map}) +## Convert image to movie frame. +## +## A movie frame is simply a struct with the fields @qcode{"cdata"} and +## @qcode{"colormap"}. +## +## Support for N-dimensional images is given when each image projection, +## matrix sizes of MxN and MxNx3 for RGB images, is concatenated on the fourth +## dimension. In such cases, the returned value is a struct array. +## +## @seealso{frame2im} +## @end deftypefn + +## Author: Carnë Draug + +function [frame] = im2frame (x, map = []) + + if (nargin < 1 || nargin > 2) + print_usage (); + elseif (ndims (x) > 4) + error ("im2frame: X and RGB must be a single image"); + endif + + ## Matlab documentation is incorrect. Singleton 3rd dimension will error + ## without cmap (no use of default cmap), and cmap is added to the frame + ## even when image is RGB. + + nchannels = size (x, 3); + if (nchannels == 3) + ## RGB image, do nothing + elseif (nchannels == 1) + if (nargin < 2) + error ("im2frame: MAP required for indexed images"); + endif + [x, map] = ind2x ("im2frame", x, map); + else + error ("im2frame: first argument must be indexed or RGB image"); + endif + + ## support N dimensional images and return a struct array + if (ndims (x) == 4) + x = reshape (num2cell (x, [1 2 3]), 1, size (x, 4)); + endif + + frame = struct ("cdata", x, "colormap", map); +endfunction + +%!function f = make_rgb_f () +%! f = randi ([0 255], 10, 20, 3); +%!endfunction + +%!function f = make_ind_f () +%! f = randi ([1 100], 10, 20, 3); +%!endfunction + +%!test +%! rgb = make_rgb_f (); +%! assert (im2frame (rgb), struct ("cdata", rgb, "colormap", [])); + +%!test +%! ind = make_ind_f (); +%! cmap = bone (100); +%! assert (im2frame (ind, cmap), struct ("cdata", ind, "colormap", cmap)); + +%!test +%! rgb1 = make_rgb_f (); +%! rgb2 = make_rgb_f (); +%! rgb3 = make_rgb_f (); +%! rgb4 = make_rgb_f (); +%! assert (im2frame (cat (4, rgb1, rgb2, rgb3, rgb4)), +%! struct ("cdata", {rgb1, rgb2, rgb3, rgb4}, "colormap", [])); + +%!test +%! ind1 = make_ind_f (); +%! ind2 = make_ind_f (); +%! ind3 = make_ind_f (); +%! ind4 = make_ind_f (); +%! cmap = bone (100); +%! assert (im2frame (cat (4, ind1, ind2, ind3, ind4), cmap), +%! struct ("cdata", {ind1, ind2, ind3, ind4}, "colormap", cmap)); + diff -r 912158cf524d -r 39a69f54417e scripts/plot/util/module.mk --- a/scripts/plot/util/module.mk Wed Nov 05 12:45:44 2014 -0500 +++ b/scripts/plot/util/module.mk Thu Nov 06 21:10:04 2014 +0000 @@ -38,6 +38,7 @@ plot/util/findall.m \ plot/util/findfigs.m \ plot/util/findobj.m \ + plot/util/frame2im.m \ plot/util/gca.m \ plot/util/gcbf.m \ plot/util/gcbo.m \ @@ -51,6 +52,7 @@ plot/util/hgload.m \ plot/util/hgsave.m \ plot/util/hold.m \ + plot/util/im2frame.m \ plot/util/isaxes.m \ plot/util/isfigure.m \ plot/util/ishghandle.m \