Mercurial > octave
comparison scripts/image/image.m @ 6257:44c91c5dfe1d
[project @ 2007-01-30 19:16:52 by jwe]
author | jwe |
---|---|
date | Tue, 30 Jan 2007 19:16:55 +0000 |
parents | d90b16110095 |
children | 77df53484011 |
comparison
equal
deleted
inserted
replaced
6256:83949ae13b2c | 6257:44c91c5dfe1d |
---|---|
16 ## along with Octave; see the file COPYING. If not, write to the Free | 16 ## along with Octave; see the file COPYING. If not, write to the Free |
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | 17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
18 ## 02110-1301, USA. | 18 ## 02110-1301, USA. |
19 | 19 |
20 ## -*- texinfo -*- | 20 ## -*- texinfo -*- |
21 ## @deftypefn {Function File} {} image (@var{x}, @var{zoom}) | 21 ## @deftypefn {Function File} {} image (@var{img}) |
22 ## @deftypefnx {Function File} {} image (@var{x}, @var{y}, @var{A}, @var{zoom}) | 22 ## @deftypefnx {Function File} {} image (@var{x}, @var{y}, @var{img}) |
23 ## Display a matrix as a color image. The elements of @var{x} are indices | 23 ## Display a matrix as a color image. The elements of @var{x} are indices |
24 ## into the current colormap and should have values between 1 and the | 24 ## into the current colormap and should have values between 1 and the |
25 ## length of the colormap. If @var{zoom} is omitted, the image will be | 25 ## length of the colormap. |
26 ## scaled to fit within 600x350 (to a max of 4). | |
27 ## | 26 ## |
28 ## It first tries to use @code{gnuplot}, then @code{display} from | 27 ## It first tries to use @code{gnuplot}, then @code{display} from |
29 ## @code{ImageMagick}, then @code{xv}, and then @code{xloadimage}. | 28 ## @code{ImageMagick}, then @code{xv}, and then @code{xloadimage}. |
30 ## The actual program used can be changed using the @code{image_viewer} | 29 ## The actual program used can be changed using the @code{image_viewer} |
31 ## function. | 30 ## function. |
38 | 37 |
39 ## Author: Tony Richardson <arichard@stark.cc.oh.us> | 38 ## Author: Tony Richardson <arichard@stark.cc.oh.us> |
40 ## Created: July 1994 | 39 ## Created: July 1994 |
41 ## Adapted-By: jwe | 40 ## Adapted-By: jwe |
42 | 41 |
43 function image (x, y, A, zoom) | 42 function image (x, y, img) |
43 | |
44 newplot (); | |
44 | 45 |
45 if (nargin == 0) | 46 if (nargin == 0) |
46 ## Load Bobbie Jo Richardson (Born 3/16/94) | 47 ## Load Bobbie Jo Richardson (Born 3/16/94) |
47 A = loadimage ("default.img"); | 48 img = loadimage ("default.img"); |
48 zoom = 2; | |
49 x = y = []; | 49 x = y = []; |
50 elseif (nargin == 1) | 50 elseif (nargin == 1) |
51 A = x; | 51 img = x; |
52 zoom = []; | |
53 x = y = []; | 52 x = y = []; |
54 elseif (nargin == 2) | 53 elseif (nargin > 3) |
55 A = x; | 54 print_usage (); |
56 zoom = y; | |
57 x = y = []; | |
58 elseif (nargin == 3) | |
59 zoom = []; | |
60 elseif (nargin > 4) | |
61 usage ("image (matrix, zoom) or image (x, y, matrix, zoom)"); | |
62 endif | 55 endif |
63 | 56 |
64 if (isempty (zoom)) | 57 if (isempty (img)) |
65 ## Find an integer scale factor which sets the image to | 58 error ("image: matrix is empty"); |
66 ## approximately the size of the screen. | |
67 zoom = min ([350/rows(A), 600/columns(A), 4]); | |
68 if (zoom >= 1) | |
69 zoom = floor (zoom); | |
70 else | |
71 zoom = 1 / ceil (1/zoom); | |
72 endif | |
73 endif | 59 endif |
74 | 60 |
75 ## Get the image viewer. | 61 ## Use the newly added mode of "plot" called "with image". |
76 [view_cmd, view_fcn, view_zoom] = image_viewer (); | 62 if (isempty (x)) |
63 x = [1, columns(img)]; | |
64 endif | |
77 | 65 |
78 ## Show the image. | 66 if (isempty (y)) |
79 view_fcn (x, y, A, zoom*view_zoom, view_cmd); | 67 y = [1, rows(img)]; |
68 endif | |
69 | |
70 ca = gca (); | |
71 | |
72 s = __uiobject_image_ctor__ (ca); | |
73 | |
74 s.cdata = img; | |
75 | |
76 tmp = __uiobject_make_handle__ (s); | |
77 | |
78 __uiobject_adopt__ (ca, tmp); | |
79 | |
80 xlim = [x(1), x(end)]; | |
81 ylim = [y(1), y(end)]; | |
82 | |
83 set (ca, "view", [0, 90], "xlim", xlim, "ylim", ylim); | |
84 | |
85 if (nargout > 0) | |
86 h = tmp; | |
87 endif | |
88 | |
89 drawnow (); | |
80 | 90 |
81 endfunction | 91 endfunction |