Mercurial > hg > octave-max
changeset 6309:6a60e68fc4b1
[project @ 2007-02-15 09:49:27 by jwe]
author | jwe |
---|---|
date | Thu, 15 Feb 2007 09:49:27 +0000 |
parents | 22e2c78e406e |
children | cf8894bbc49d |
files | scripts/ChangeLog scripts/image/image.m scripts/image/imshow.m scripts/plot/__uiobject_draw_axes__.m scripts/plot/__uiobject_image_ctor__.m |
diffstat | 5 files changed, 61 insertions(+), 45 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,5 +1,12 @@ 2007-02-15 Daniel J Sebald <daniel.sebald@ieee.org> + * plot/__uiobject_image_ctor__.m: Set xdata and ydata properties. + * image/__img__.m: New file containing common parts of image.m and + imshow.m. + * image/image.m, image/imshow.m: Call __img__. + * plot/__uiobject_draw_axes__.m: + Handle rgb imaged data stored in 3-d arrays. + * plot/figure.m: Doc fix. 2007-02-14 Thomas Weber <thomas.weber.mail@gmail.com>
--- a/scripts/image/image.m +++ b/scripts/image/image.m @@ -56,33 +56,7 @@ print_usage (); endif - if (isempty (img)) - error ("image: matrix is empty"); - endif - - ## Use the newly added mode of "plot" called "with image". - if (isempty (x)) - x = [1, columns(img)]; - endif - - if (isempty (y)) - y = [1, rows(img)]; - endif - - ca = gca (); - - s = __uiobject_image_ctor__ (ca); - - s.cdata = img; - - tmp = __uiobject_make_handle__ (s); - - __uiobject_adopt__ (ca, tmp); - - xlim = [x(1), x(end)]; - ylim = [y(1), y(end)]; - - set (ca, "view", [0, 90], "xlim", xlim, "ylim", ylim); + tmp = __img__ (x, y, img); if (nargout > 0) h = tmp;
--- a/scripts/image/imshow.m +++ b/scripts/image/imshow.m @@ -23,7 +23,7 @@ ## @deftypefnx {Function File} {} imshow (@var{im}, @var{map}) ## @deftypefnx {Function File} {} imshow (@var{R}, @var{G}, @var{B}, @dots{}) ## @deftypefnx {Function File} {} imshow (@var{filename}) -## @deftypefnx {Function File} {} imshow (@dots{}, @var{string_param1}, @var{value1}, ...) +## @deftypefnx {Function File} {} imshow (@dots{}, @var{string_param1}, @var{value1}, @dots{}) ## Display the image @var{im}, where @var{im} can a 2-dimensional ## (gray-scale image) or a 3-dimensional (RGB image) matrix. If three matrices ## of the same size are given as arguments, they will be concatenated into @@ -146,21 +146,21 @@ im(im > 1) = 1; endif - ## Convert to indexed image. dim = ndims (im); if (dim == 2) im = round ((size (color_map, 1) - 1) * im); + colormap (color_map); + image (im, initial_magnification/100); + colormap (old_colormap); elseif (dim == 3 && size (im, 3) == 3) - [im, color_map] = rgb2ind (im); + __img__ ([] , [], im); + ## FIXME -- needed anymore for a special case? + ## Convert to indexed image. + ## [im, color_map] = rgb2ind (im); else error ("imshow: input image must be a 2D or 3D matrix"); endif - ## And now, we show the image. - colormap (color_map); - image (im, initial_magnification/100); - colormap (old_colormap); - endfunction %!error imshow () # no arguments
--- a/scripts/plot/__uiobject_draw_axes__.m +++ b/scripts/plot/__uiobject_draw_axes__.m @@ -30,6 +30,8 @@ axis_obj = get (h); + parent_figure_obj = get (axis_obj.parent); + ## Set axis properties here? if (! isempty (axis_obj.outerposition)) @@ -222,7 +224,6 @@ data = cell (); have_img_data = false; - img_data = []; xminp = yminp = zminp = Inf; xmax = ymax = zmax = -Inf; @@ -239,7 +240,9 @@ endif have_img_data = true; img_data = obj.cdata; - + img_colormap = parent_figure_obj.colormap; + img_xdata = obj.xdata; + img_ydata = obj.ydata; case "line" data_idx++; @@ -552,28 +555,58 @@ if (ischar (view_fcn) && strcmp (view_fcn, "gnuplot_internal")) have_data = true; - [y_dim, x_dim] = size (img_data); + [y_dim, x_dim] = size (img_data(:,:,1)); if (x_dim > 1) - dx = abs (xlim(2)-xlim(1))/(x_dim-1); + dx = abs (img_xdata(2)-img_xdata(1))/(x_dim-1); else dx = 1; endif if (y_dim > 1) - dy = abs (ylim(2)-ylim(1))/(y_dim-1); + dy = abs (img_ydata(2)-img_ydata(1))/(y_dim-1); else dy = 1; endif - x_origin = min (xlim); - y_origin = min (ylim); + x_origin = min (img_xdata); + y_origin = min (img_ydata); ## Let the file be deleted when Octave exits or `purge_tmp_files' ## is called. [fid, fname] = mkstemp (strcat (P_tmpdir, "/gpimageXXXXXX"), 1); - fwrite (fid, img_data(:), "float"); + if (ndims (img_data) == 3) + fwrite (fid, permute (img_data, [3, 1, 2])(:), "float"); + format = "1:2:3"; + imagetype = "rgbimage"; + else + fwrite (fid, img_data(:), "float"); + format = "1"; + imagetype = "image"; + palette_size = rows (img_colormap); + fprintf (plot_stream, + "set palette positive color model RGB maxcolors %i;\n", + palette_size); + if (palette_size <= 128) + ## Break up command to avoid buffer overflow. + fprintf (plot_stream, "set palette file \"-\" using 1:2:3:4;\n"); + for i = 1:palette_size + fprintf (plot_stream, "%g %g %g %g;\n", + 1e-3*round (1e3*[(i-1)/(palette_size-1), img_colormap(i,:)])); + end + fprintf (plot_stream, "e;\n"); + else + # Let the file be deleted when Octave exits or `purge_tmp_files' is called. + [fid, binary_fname, msg] = mkstemp (strcat (P_tmpdir, "/gpimageXXXXXX"), 1); + fwrite (fid, img_colormap', "float32", 0, "ieee-le"); + fclose (fid); + fprintf (plot_stream, + "set palette file \"%s\" binary record=%d using 1:2:3;\n", + binary_fname, palette_size); + endif + endif fclose (fid); - fprintf (plot_stream, "plot \"%s\" binary array=%dx%d scan=yx flipy origin=(%g,%g) dx=%g dy=%g using 1 with image", - fname, x_dim, y_dim, x_origin, y_origin, dx, dy); + fprintf (plot_stream, + "plot \"%s\" binary array=%dx%d scan=yx flipy origin=(%g,%g) dx=%g dy=%g using %s with %s", + fname, x_dim, y_dim, x_origin, y_origin, dx, dy, format, imagetype); plot_cmd = ","; else