Mercurial > octave-antonio
annotate doc/interpreter/image.txi @ 8144:01fac748b680
Add the 'imfinfo' function for reading image file information.
author | sh@sh-laptop |
---|---|
date | Wed, 24 Sep 2008 15:40:27 -0400 |
parents | bbaa5d7d0143 |
children | 213dd524f96b |
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 |
8144
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
7984
diff
changeset
|
67 It is possible to get information about an image file on disk, without actually |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
7984
diff
changeset
|
68 reading in into Octave. This is done using the @code{imfinfo} function which |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
7984
diff
changeset
|
69 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
|
70 file. |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
7984
diff
changeset
|
71 |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
7984
diff
changeset
|
72 @DOCSTRING(imfinfo) |
01fac748b680
Add the 'imfinfo' function for reading image file information.
sh@sh-laptop
parents:
7984
diff
changeset
|
73 |
6529 | 74 @node Displaying Images |
75 @section Displaying Images | |
3294 | 76 |
6529 | 77 A natural part of image processing is visualization of an image. |
78 The most basic function for this is the @code{imshow} function that | |
79 shows the image given in the first input argument. This function uses | |
80 an external program to show the image. If gnuplot 4.2 or later is | |
81 available it will be used to display the image, otherwise the | |
82 @code{display}, @code{xv}, or @code{xloadimage} program is used. The | |
83 actual program can be selected with the @code{image_viewer} function. | |
3294 | 84 |
6529 | 85 @DOCSTRING(imshow) |
3294 | 86 |
3373 | 87 @DOCSTRING(image) |
3294 | 88 |
3373 | 89 @DOCSTRING(imagesc) |
3294 | 90 |
6529 | 91 @DOCSTRING(image_viewer) |
92 | |
93 @node Representing Images | |
94 @section Representing Images | |
95 | |
96 In general Octave supports four different kinds of images, gray-scale | |
97 images, RGB images, binary images, and indexed images. A gray-scale | |
6535 | 98 image is represented with an M-by-N matrix in which each |
6529 | 99 element corresponds to the intensity of a pixel. An RGB image is |
6535 | 100 represented with an M-by-N-by3 array where each |
6529 | 101 3-vector corresponds to the red, green, and blue intensities of each |
102 pixel. | |
103 | |
104 The actual meaning of the value of a pixel in a gray-scale or RGB | |
105 image depends on the class of the matrix. If the matrix is of class | |
106 @code{double} pixel intensities are between 0 and 1, if it is of class | |
107 @code{uint8} intensities are between 0 and 255, and if it is of class | |
108 @code{uint16} intensities are between 0 and 65535. | |
109 | |
6535 | 110 A binary image is a M-by-N matrix of class @code{logical}. |
6529 | 111 A pixel in a binary image is black if it is @code{false} and white |
112 if it is @code{true}. | |
113 | |
6535 | 114 An indexed image consists of an M-by-N matrix of integers |
115 and a C-by-3 color map. Each integer corresponds to an | |
6529 | 116 index in the color map, and each row in the color map corresponds to |
117 a RGB color. The color map must be of class @code{double} with values | |
118 between 0 and 1. | |
119 | |
120 @DOCSTRING(gray2ind) | |
3294 | 121 |
3373 | 122 @DOCSTRING(ind2gray) |
3294 | 123 |
6529 | 124 @DOCSTRING(rgb2ind) |
125 | |
3373 | 126 @DOCSTRING(ind2rgb) |
3294 | 127 |
6529 | 128 @DOCSTRING(colormap) |
129 | |
6788 | 130 @DOCSTRING(autumn) |
131 | |
132 @DOCSTRING(bone) | |
133 | |
134 @DOCSTRING(cool) | |
135 | |
136 @DOCSTRING(copper) | |
137 | |
6529 | 138 @DOCSTRING(gray) |
139 | |
6788 | 140 @DOCSTRING(hot) |
141 | |
142 @DOCSTRING(hsv) | |
143 | |
144 @DOCSTRING(jet) | |
145 | |
6529 | 146 @DOCSTRING(ocean) |
147 | |
6788 | 148 @DOCSTRING(pink) |
149 | |
150 @DOCSTRING(prism) | |
151 | |
152 @DOCSTRING(rainbow) | |
153 | |
154 @DOCSTRING(spring) | |
155 | |
156 @DOCSTRING(summer) | |
157 | |
158 @DOCSTRING(white) | |
159 | |
160 @DOCSTRING(winter) | |
161 | |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7189
diff
changeset
|
162 @DOCSTRING(contrast) |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7189
diff
changeset
|
163 |
7189 | 164 An additional colormap is @code{gmap40}. This code map contains only |
165 colors with integer values of the red, green and blue components. This | |
166 workaround a limitation on gnuplot 4.0, that does not allow the color of | |
167 line or patch objects to be set, and so @code{gmap40} is useful for | |
168 gnuplot 4.0 users, and in particular in conjunction with the @var{bar}, | |
169 @var{barh} or @var{contour} functions. | |
170 | |
171 @DOCSTRING(gmap40) | |
172 | |
6529 | 173 @node Plotting on top of Images |
174 @section Plotting on top of Images | |
175 | |
176 If gnuplot is being used to display images it is possible to plot on | |
177 top of images. Since an image is a matrix it is indexed by row and | |
178 column values. The plotting system is, however, based on the | |
179 traditional @math{(x, y)} system. To minimize the difference between | |
180 the two systems Octave places the origin of the coordinate system in | |
181 the point corresponding to the pixel at @math{(1, 1)}. So, to plot | |
182 points given by row and column values on top of an image, one should | |
183 simply call @code{plot} with the column values as the first argument | |
184 and the row values as the second. As an example the following code | |
185 generates an image with random intensities between 0 and 1, and shows | |
186 the image with red circles over pixels with an intensity above | |
187 @math{0.99}. | |
188 | |
189 @example | |
6535 | 190 I = rand (100, 100); |
191 [row, col] = find (I > 0.99); | |
192 hold ("on"); | |
193 imshow (I); | |
194 plot (col, row, "ro"); | |
195 hold ("off"); | |
6529 | 196 @end example |
197 | |
198 @node Color Conversion | |
199 @section Color Conversion | |
200 | |
201 Octave supports conversion from the RGB color system to NTSC and HSV | |
202 and vice versa. | |
203 | |
204 @DOCSTRING(rgb2hsv) | |
205 | |
206 @DOCSTRING(hsv2rgb) | |
3294 | 207 |
3373 | 208 @DOCSTRING(rgb2ntsc) |
3294 | 209 |
3373 | 210 @DOCSTRING(ntsc2rgb) |
3294 | 211 |
3803 | 212 |