Mercurial > hg > octave-lyh
annotate doc/interpreter/image.txi @ 9210:a7a9eecc07b5
Change recommendation for writing documentation to favor @tex
rather than @iftex construction.
author | Rik <rdrider0-list@yahoo.com> |
---|---|
date | Sun, 17 May 2009 14:17:32 -0700 |
parents | bd8e388043c4 |
children | 322f43e0e170 |
rev | line source |
---|---|
8920 | 1 @c Copyright (C) 1996, 1997, 2007, 2008, 2009 John W. Eaton |
7018 | 2 @c |
3 @c This file is part of Octave. | |
4 @c | |
5 @c Octave is free software; you can redistribute it and/or modify it | |
6 @c under the terms of the GNU General Public License as published by the | |
7 @c Free Software Foundation; either version 3 of the License, or (at | |
8 @c your option) any later version. | |
9 @c | |
10 @c Octave is distributed in the hope that it will be useful, but WITHOUT | |
11 @c ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
12 @c FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
13 @c for more details. | |
14 @c | |
15 @c You should have received a copy of the GNU General Public License | |
16 @c along with Octave; see the file COPYING. If not, see | |
17 @c <http://www.gnu.org/licenses/>. | |
3294 | 18 |
4167 | 19 @node Image Processing |
3294 | 20 @chapter Image Processing |
21 | |
6529 | 22 Since an image basically is a matrix Octave is a very powerful |
9072
bd8e388043c4
Cleanup documentation for signal.texi, image.texi, audio.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
23 environment for processing and analyzing images. To illustrate |
6529 | 24 how easy it is to do image processing in Octave, the following |
25 example will load an image, smooth it by a 5-by-5 averaging filter, | |
26 and compute the gradient of the smoothed image. | |
27 | |
28 @example | |
9072
bd8e388043c4
Cleanup documentation for signal.texi, image.texi, audio.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
29 @group |
8148 | 30 I = imread ("myimage.jpg"); |
6535 | 31 S = conv2 (I, ones (5, 5) / 25, "same"); |
32 [Dx, Dy] = gradient (S); | |
9072
bd8e388043c4
Cleanup documentation for signal.texi, image.texi, audio.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
33 @end group |
6529 | 34 @end example |
35 | |
36 @noindent | |
37 In this example @code{S} contains the smoothed image, and @code{Dx} | |
38 and @code{Dy} contains the partial spatial derivatives of the image. | |
39 | |
6535 | 40 @menu |
41 * Loading and Saving Images:: | |
42 * Displaying Images:: | |
43 * Representing Images:: | |
44 * Plotting on top of Images:: | |
45 * Color Conversion:: | |
46 @end menu | |
47 | |
6529 | 48 @node Loading and Saving Images |
49 @section Loading and Saving Images | |
50 | |
51 The first step in most image processing tasks is to load an image | |
9072
bd8e388043c4
Cleanup documentation for signal.texi, image.texi, audio.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
52 into Octave. This is done using the @code{imread} function, which uses the |
bd8e388043c4
Cleanup documentation for signal.texi, image.texi, audio.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
53 @code{GraphicsMagick} library for reading. This means a vast number of image |
8148 | 54 formats is supported. The @code{imwrite} function is the corresponding function |
55 for writing images to the disk. | |
56 | |
57 In summary, most image processing code will follow the structure of this code | |
3294 | 58 |
6529 | 59 @example |
9072
bd8e388043c4
Cleanup documentation for signal.texi, image.texi, audio.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
60 @group |
8148 | 61 I = imread ("my_input_image.img"); |
6535 | 62 J = process_my_image (I); |
8148 | 63 imwrite ("my_output_image.img", J); |
9072
bd8e388043c4
Cleanup documentation for signal.texi, image.texi, audio.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
64 @end group |
6529 | 65 @end example |
66 | |
8148 | 67 @DOCSTRING(imread) |
6529 | 68 |
8148 | 69 @DOCSTRING(imwrite) |
6529 | 70 |
71 @DOCSTRING(IMAGE_PATH) | |
3294 | 72 |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
7984
diff
changeset
|
73 It is possible to get information about an image file on disk, without actually |
9072
bd8e388043c4
Cleanup documentation for signal.texi, image.texi, audio.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
74 reading it into Octave. This is done using the @code{imfinfo} function which |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
7984
diff
changeset
|
75 provides read access to many of the parameters stored in the header of the image |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
7984
diff
changeset
|
76 file. |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
7984
diff
changeset
|
77 |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
7984
diff
changeset
|
78 @DOCSTRING(imfinfo) |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
7984
diff
changeset
|
79 |
6529 | 80 @node Displaying Images |
81 @section Displaying Images | |
3294 | 82 |
6529 | 83 A natural part of image processing is visualization of an image. |
84 The most basic function for this is the @code{imshow} function that | |
9072
bd8e388043c4
Cleanup documentation for signal.texi, image.texi, audio.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
85 shows the image given in the first input argument. This function uses |
bd8e388043c4
Cleanup documentation for signal.texi, image.texi, audio.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
86 an external program to show the image. If gnuplot 4.2 or later is |
6529 | 87 available it will be used to display the image, otherwise the |
9072
bd8e388043c4
Cleanup documentation for signal.texi, image.texi, audio.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
88 @code{display}, @code{xv}, or @code{xloadimage} program is used. The |
6529 | 89 actual program can be selected with the @code{image_viewer} function. |
3294 | 90 |
6529 | 91 @DOCSTRING(imshow) |
3294 | 92 |
3373 | 93 @DOCSTRING(image) |
3294 | 94 |
3373 | 95 @DOCSTRING(imagesc) |
3294 | 96 |
6529 | 97 @DOCSTRING(image_viewer) |
98 | |
99 @node Representing Images | |
100 @section Representing Images | |
101 | |
102 In general Octave supports four different kinds of images, gray-scale | |
9072
bd8e388043c4
Cleanup documentation for signal.texi, image.texi, audio.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
103 images, RGB images, binary images, and indexed images. A gray-scale |
6535 | 104 image is represented with an M-by-N matrix in which each |
9072
bd8e388043c4
Cleanup documentation for signal.texi, image.texi, audio.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
105 element corresponds to the intensity of a pixel. An RGB image is |
8325
b93ac0586e4b
spelling corrections
Brian Gough<bjg@network-theory.co.uk>
parents:
8148
diff
changeset
|
106 represented with an M-by-N-by-3 array where each |
6529 | 107 3-vector corresponds to the red, green, and blue intensities of each |
108 pixel. | |
109 | |
110 The actual meaning of the value of a pixel in a gray-scale or RGB | |
9072
bd8e388043c4
Cleanup documentation for signal.texi, image.texi, audio.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
111 image depends on the class of the matrix. If the matrix is of class |
6529 | 112 @code{double} pixel intensities are between 0 and 1, if it is of class |
113 @code{uint8} intensities are between 0 and 255, and if it is of class | |
114 @code{uint16} intensities are between 0 and 65535. | |
115 | |
8347
fa78cb8d8a5c
corrections for typos
Brian Gough<bjg@network-theory.co.uk>
parents:
8325
diff
changeset
|
116 A binary image is an M-by-N matrix of class @code{logical}. |
6529 | 117 A pixel in a binary image is black if it is @code{false} and white |
118 if it is @code{true}. | |
119 | |
6535 | 120 An indexed image consists of an M-by-N matrix of integers |
9072
bd8e388043c4
Cleanup documentation for signal.texi, image.texi, audio.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
121 and a C-by-3 color map. Each integer corresponds to an |
6529 | 122 index in the color map, and each row in the color map corresponds to |
9072
bd8e388043c4
Cleanup documentation for signal.texi, image.texi, audio.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
123 an RGB color. The color map must be of class @code{double} with values |
6529 | 124 between 0 and 1. |
125 | |
126 @DOCSTRING(gray2ind) | |
3294 | 127 |
3373 | 128 @DOCSTRING(ind2gray) |
3294 | 129 |
6529 | 130 @DOCSTRING(rgb2ind) |
131 | |
3373 | 132 @DOCSTRING(ind2rgb) |
3294 | 133 |
6529 | 134 @DOCSTRING(colormap) |
135 | |
8539
67a632417879
image.txi: @DOCSTRING for brighten
John W. Eaton <jwe@octave.org>
parents:
8347
diff
changeset
|
136 @DOCSTRING(brighten) |
67a632417879
image.txi: @DOCSTRING for brighten
John W. Eaton <jwe@octave.org>
parents:
8347
diff
changeset
|
137 |
6788 | 138 @DOCSTRING(autumn) |
139 | |
140 @DOCSTRING(bone) | |
141 | |
142 @DOCSTRING(cool) | |
143 | |
144 @DOCSTRING(copper) | |
145 | |
8817
03b7f618ab3d
include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents:
8539
diff
changeset
|
146 @DOCSTRING(flag) |
03b7f618ab3d
include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents:
8539
diff
changeset
|
147 |
6529 | 148 @DOCSTRING(gray) |
149 | |
6788 | 150 @DOCSTRING(hot) |
151 | |
152 @DOCSTRING(hsv) | |
153 | |
154 @DOCSTRING(jet) | |
155 | |
6529 | 156 @DOCSTRING(ocean) |
157 | |
6788 | 158 @DOCSTRING(pink) |
159 | |
160 @DOCSTRING(prism) | |
161 | |
162 @DOCSTRING(rainbow) | |
163 | |
164 @DOCSTRING(spring) | |
165 | |
166 @DOCSTRING(summer) | |
167 | |
168 @DOCSTRING(white) | |
169 | |
170 @DOCSTRING(winter) | |
171 | |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7189
diff
changeset
|
172 @DOCSTRING(contrast) |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7189
diff
changeset
|
173 |
9072
bd8e388043c4
Cleanup documentation for signal.texi, image.texi, audio.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
174 An additional colormap is @code{gmap40}. This code map contains only |
bd8e388043c4
Cleanup documentation for signal.texi, image.texi, audio.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
175 colors with integer values of the red, green and blue components. This |
8347
fa78cb8d8a5c
corrections for typos
Brian Gough<bjg@network-theory.co.uk>
parents:
8325
diff
changeset
|
176 is a workaround for a limitation of gnuplot 4.0, that does not allow the color of |
7189 | 177 line or patch objects to be set, and so @code{gmap40} is useful for |
178 gnuplot 4.0 users, and in particular in conjunction with the @var{bar}, | |
179 @var{barh} or @var{contour} functions. | |
180 | |
181 @DOCSTRING(gmap40) | |
182 | |
8817
03b7f618ab3d
include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents:
8539
diff
changeset
|
183 You may use the @code{spinmap} function to cycle through the colors in |
03b7f618ab3d
include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents:
8539
diff
changeset
|
184 the current colormap, displaying the changes for the current figure. |
03b7f618ab3d
include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents:
8539
diff
changeset
|
185 |
03b7f618ab3d
include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents:
8539
diff
changeset
|
186 @DOCSTRING(spinmap) |
03b7f618ab3d
include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents:
8539
diff
changeset
|
187 |
6529 | 188 @node Plotting on top of Images |
189 @section Plotting on top of Images | |
190 | |
191 If gnuplot is being used to display images it is possible to plot on | |
9072
bd8e388043c4
Cleanup documentation for signal.texi, image.texi, audio.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
192 top of images. Since an image is a matrix it is indexed by row and |
bd8e388043c4
Cleanup documentation for signal.texi, image.texi, audio.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
193 column values. The plotting system is, however, based on the |
bd8e388043c4
Cleanup documentation for signal.texi, image.texi, audio.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
194 traditional @math{(x, y)} system. To minimize the difference between |
6529 | 195 the two systems Octave places the origin of the coordinate system in |
9072
bd8e388043c4
Cleanup documentation for signal.texi, image.texi, audio.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
196 the point corresponding to the pixel at @math{(1, 1)}. So, to plot |
6529 | 197 points given by row and column values on top of an image, one should |
198 simply call @code{plot} with the column values as the first argument | |
9072
bd8e388043c4
Cleanup documentation for signal.texi, image.texi, audio.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
199 and the row values as the second. As an example the following code |
6529 | 200 generates an image with random intensities between 0 and 1, and shows |
201 the image with red circles over pixels with an intensity above | |
202 @math{0.99}. | |
203 | |
204 @example | |
9072
bd8e388043c4
Cleanup documentation for signal.texi, image.texi, audio.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
205 @group |
6535 | 206 I = rand (100, 100); |
207 [row, col] = find (I > 0.99); | |
208 hold ("on"); | |
209 imshow (I); | |
210 plot (col, row, "ro"); | |
211 hold ("off"); | |
9072
bd8e388043c4
Cleanup documentation for signal.texi, image.texi, audio.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
212 @end group |
6529 | 213 @end example |
214 | |
215 @node Color Conversion | |
216 @section Color Conversion | |
217 | |
218 Octave supports conversion from the RGB color system to NTSC and HSV | |
219 and vice versa. | |
220 | |
221 @DOCSTRING(rgb2hsv) | |
222 | |
223 @DOCSTRING(hsv2rgb) | |
3294 | 224 |
3373 | 225 @DOCSTRING(rgb2ntsc) |
3294 | 226 |
3373 | 227 @DOCSTRING(ntsc2rgb) |
3294 | 228 |
3803 | 229 |