Mercurial > octave-antonio
annotate doc/interpreter/image.txi @ 7984:bbaa5d7d0143
Some documentation updates
author | David Bateman <dbateman@free.fr> |
---|---|
date | Mon, 28 Jul 2008 15:47:40 +0200 |
parents | e8d953d03f6a |
children | 01fac748b680 |
rev | line source |
---|---|
6778 | 1 @c Copyright (C) 1996, 1997, 2007 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 |
23 environment for processing and analysing images. To illustrate | |
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 | |
6535 | 29 I = loadimage ("default.img"); |
30 S = conv2 (I, ones (5, 5) / 25, "same"); | |
31 [Dx, Dy] = gradient (S); | |
6529 | 32 @end example |
33 | |
34 @noindent | |
35 In this example @code{S} contains the smoothed image, and @code{Dx} | |
36 and @code{Dy} contains the partial spatial derivatives of the image. | |
37 | |
6535 | 38 @menu |
39 * Loading and Saving Images:: | |
40 * Displaying Images:: | |
41 * Representing Images:: | |
42 * Plotting on top of Images:: | |
43 * Color Conversion:: | |
44 @end menu | |
45 | |
6529 | 46 @node Loading and Saving Images |
47 @section Loading and Saving Images | |
48 | |
49 The first step in most image processing tasks is to load an image | |
50 into Octave. Currently Octave only support saving images in the | |
51 Portable Pixmap Format (PPM), PostScript, and Octave's own format, and | |
52 loading images in Octave's format. Most image processing code will | |
53 follow the structure of this code | |
3294 | 54 |
6529 | 55 @example |
6535 | 56 I = loadimage ("my_input_image.img"); |
57 J = process_my_image (I); | |
58 saveimage ("my_output_image.img", J); | |
6529 | 59 @end example |
60 | |
61 @DOCSTRING(loadimage) | |
62 | |
63 @DOCSTRING(saveimage) | |
64 | |
65 @DOCSTRING(IMAGE_PATH) | |
3294 | 66 |
6529 | 67 @node Displaying Images |
68 @section Displaying Images | |
3294 | 69 |
6529 | 70 A natural part of image processing is visualization of an image. |
71 The most basic function for this is the @code{imshow} function that | |
72 shows the image given in the first input argument. This function uses | |
73 an external program to show the image. If gnuplot 4.2 or later is | |
74 available it will be used to display the image, otherwise the | |
75 @code{display}, @code{xv}, or @code{xloadimage} program is used. The | |
76 actual program can be selected with the @code{image_viewer} function. | |
3294 | 77 |
6529 | 78 @DOCSTRING(imshow) |
3294 | 79 |
3373 | 80 @DOCSTRING(image) |
3294 | 81 |
3373 | 82 @DOCSTRING(imagesc) |
3294 | 83 |
6529 | 84 @DOCSTRING(image_viewer) |
85 | |
86 @node Representing Images | |
87 @section Representing Images | |
88 | |
89 In general Octave supports four different kinds of images, gray-scale | |
90 images, RGB images, binary images, and indexed images. A gray-scale | |
6535 | 91 image is represented with an M-by-N matrix in which each |
6529 | 92 element corresponds to the intensity of a pixel. An RGB image is |
6535 | 93 represented with an M-by-N-by3 array where each |
6529 | 94 3-vector corresponds to the red, green, and blue intensities of each |
95 pixel. | |
96 | |
97 The actual meaning of the value of a pixel in a gray-scale or RGB | |
98 image depends on the class of the matrix. If the matrix is of class | |
99 @code{double} pixel intensities are between 0 and 1, if it is of class | |
100 @code{uint8} intensities are between 0 and 255, and if it is of class | |
101 @code{uint16} intensities are between 0 and 65535. | |
102 | |
6535 | 103 A binary image is a M-by-N matrix of class @code{logical}. |
6529 | 104 A pixel in a binary image is black if it is @code{false} and white |
105 if it is @code{true}. | |
106 | |
6535 | 107 An indexed image consists of an M-by-N matrix of integers |
108 and a C-by-3 color map. Each integer corresponds to an | |
6529 | 109 index in the color map, and each row in the color map corresponds to |
110 a RGB color. The color map must be of class @code{double} with values | |
111 between 0 and 1. | |
112 | |
113 @DOCSTRING(gray2ind) | |
3294 | 114 |
3373 | 115 @DOCSTRING(ind2gray) |
3294 | 116 |
6529 | 117 @DOCSTRING(rgb2ind) |
118 | |
3373 | 119 @DOCSTRING(ind2rgb) |
3294 | 120 |
6529 | 121 @DOCSTRING(colormap) |
122 | |
6788 | 123 @DOCSTRING(autumn) |
124 | |
125 @DOCSTRING(bone) | |
126 | |
127 @DOCSTRING(cool) | |
128 | |
129 @DOCSTRING(copper) | |
130 | |
6529 | 131 @DOCSTRING(gray) |
132 | |
6788 | 133 @DOCSTRING(hot) |
134 | |
135 @DOCSTRING(hsv) | |
136 | |
137 @DOCSTRING(jet) | |
138 | |
6529 | 139 @DOCSTRING(ocean) |
140 | |
6788 | 141 @DOCSTRING(pink) |
142 | |
143 @DOCSTRING(prism) | |
144 | |
145 @DOCSTRING(rainbow) | |
146 | |
147 @DOCSTRING(spring) | |
148 | |
149 @DOCSTRING(summer) | |
150 | |
151 @DOCSTRING(white) | |
152 | |
153 @DOCSTRING(winter) | |
154 | |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7189
diff
changeset
|
155 @DOCSTRING(contrast) |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7189
diff
changeset
|
156 |
7189 | 157 An additional colormap is @code{gmap40}. This code map contains only |
158 colors with integer values of the red, green and blue components. This | |
159 workaround a limitation on gnuplot 4.0, that does not allow the color of | |
160 line or patch objects to be set, and so @code{gmap40} is useful for | |
161 gnuplot 4.0 users, and in particular in conjunction with the @var{bar}, | |
162 @var{barh} or @var{contour} functions. | |
163 | |
164 @DOCSTRING(gmap40) | |
165 | |
6529 | 166 @node Plotting on top of Images |
167 @section Plotting on top of Images | |
168 | |
169 If gnuplot is being used to display images it is possible to plot on | |
170 top of images. Since an image is a matrix it is indexed by row and | |
171 column values. The plotting system is, however, based on the | |
172 traditional @math{(x, y)} system. To minimize the difference between | |
173 the two systems Octave places the origin of the coordinate system in | |
174 the point corresponding to the pixel at @math{(1, 1)}. So, to plot | |
175 points given by row and column values on top of an image, one should | |
176 simply call @code{plot} with the column values as the first argument | |
177 and the row values as the second. As an example the following code | |
178 generates an image with random intensities between 0 and 1, and shows | |
179 the image with red circles over pixels with an intensity above | |
180 @math{0.99}. | |
181 | |
182 @example | |
6535 | 183 I = rand (100, 100); |
184 [row, col] = find (I > 0.99); | |
185 hold ("on"); | |
186 imshow (I); | |
187 plot (col, row, "ro"); | |
188 hold ("off"); | |
6529 | 189 @end example |
190 | |
191 @node Color Conversion | |
192 @section Color Conversion | |
193 | |
194 Octave supports conversion from the RGB color system to NTSC and HSV | |
195 and vice versa. | |
196 | |
197 @DOCSTRING(rgb2hsv) | |
198 | |
199 @DOCSTRING(hsv2rgb) | |
3294 | 200 |
3373 | 201 @DOCSTRING(rgb2ntsc) |
3294 | 202 |
3373 | 203 @DOCSTRING(ntsc2rgb) |
3294 | 204 |
3803 | 205 |