Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
pmi432 / LR07 / 2read / image processing toolbox guide.pdf
Скачиваний:
166
Добавлен:
18.03.2015
Размер:
18.08 Mб
Скачать

11 Analyzing and Enhancing Images

Getting Information about Image Pixel Values and Image Statistics

In this section...

“Getting Image Pixel Values Using impixel” on page 11-2

“Creating an Intensity Profile of an Image Using improfile” on page 11-3 “Displaying a Contour Plot of Image Data” on page 11-7

“Creating an Image Histogram Using imhist” on page 11-9 “Getting Summary Statistics About an Image” on page 11-10 “Computing Properties for Image Regions” on page 11-10

Getting Image Pixel Values Using impixel

To determine the values of one or more pixels in an image and return the values in a variable, use the impixel function. You can specify the pixels by passing their coordinates as input arguments or you can select the pixels interactively using a mouse. impixel returns the value of specified pixels in a variable in the MATLAB workspace.

Note You can also get pixel value information interactively using the Image Tool -- see “Getting Information about the Pixels in an Image” on page 4-30.

This example illustrates how to use impixel to get pixel values.

1Display an image. imshow canoe.tif

2Call impixel. When called with no input arguments, impixel associates itself with the image in the current axes.

vals = impixel

3Select the points you want to examine in the image by clicking the mouse. impixel places a star at each point you select.

11-2

Getting Information about Image Pixel Values and Image Statistics

4When you are finished selecting points, press Return. impixel returns the pixel values in an n-by-3 array, where n is the number of points you selected. The stars used to indicate selected points disappear from the image.

pixel_values =

0.1294

0.1294

0.1294

0.5176

0

0

0.7765

0.6118

0.4196

Creating an Intensity Profile of an Image Using improfile

The intensity profile of an image is the set of intensity values taken from regularly spaced points along a line segment or multiline path in an image. For points that do not fall on the center of a pixel, the intensity values are interpolated.

To create an intensity profile, use the improfile function. This function calculates and plots the intensity values along a line segment or a multiline path in an image. You define the line segment (or segments) by specifying

11-3

11 Analyzing and Enhancing Images

their coordinates as input arguments. You can define the line segments using a mouse. (By default, improfile uses nearest-neighbor interpolation, but you can specify a different method. For more information, see “Specifying the Interpolation Method” on page 6-3.) improfile works best with grayscale and truecolor images.

For a single line segment, improfile plots the intensity values in a two-dimensional view. For a multiline path, improfile plots the intensity values in a three-dimensional view.

If you call improfile with no arguments, the cursor changes to crosshairs when it is over the image. You can then specify line segments by clicking the endpoints; improfile draws a line between each two consecutive points you select. When you finish specifying the path, press Return. improfile displays the plot in a new figure.

In this example, you call improfile and specify a single line with the mouse. In this figure, the line is shown in red, and is drawn from top to bottom.

I = fitsread('solarspectra.fts'); imshow(I,[]);

improfile

improfile displays a plot of the data along the line. Notice the peaks and valleys and how they correspond to the light and dark bands in the image.

11-4

Getting Information about Image Pixel Values and Image Statistics

Plot Produced by improfile

The example below shows how improfile works with an RGB image. Use imshow to display the image in a figure window. Call improfile without any arguments and trace a line segment in the image interactively. In the figure, the black line indicates a line segment drawn from top to bottom. Double-click to end the line segment.

imshow peppers.png improfile

11-5

11 Analyzing and Enhancing Images

RGB Image with Line Segment Drawn with improfile

The improfile function displays a plot of the intensity values along the line segment. The plot includes separate lines for the red, green, and blue intensities. In the plot, notice how low the blue values are at the beginning of the plot where the line traverses the orange pepper.

11-6

Соседние файлы в папке 2read