pixels matlab,matlab图像处理(如何从像素中获得图像的信息) | 学步园

Getting Information about Image Pixel Values and Image Statistics

Getting Image Pixel Values Using impixel

To determine the values of one or more pixels in an image andreturn the values in a variable, use the

impixel function.You can specify the pixels by passing their coordinates as input argumentsor you can select the pixels interactively using a mouse.

impixel returnsthe value of specified pixels in a variable in the MATLAB workspace.

Note  You can also get pixel value information interactively usingthe Image Tool -- see

Getting Information about the Pixels in an Image.

This example illustrates how to use impixel toget pixel values.

Display an image.

imshow canoe.tif

Call impixel.When called with no input arguments,

impixel associatesitself with the image in the current axes.

vals = impixel

Select the points you want to examinein the image by clicking the mouse.

impixel placesa star at each point you select.

3241193.html

When you are finished selecting points,press

Return. impixel returnsthe pixel values in an n-by-3 array, where n isthe number of points you selected. The stars used to indicate selectedpoints 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 valuestaken from regularly spaced points along a line segment or multilinepath in an image. For points that do not fall on the center of a pixel,the intensity values are interpolated.

To create anintensity profile, use the

improfile function.This function calculates and plots the intensity values along a linesegment or a multiline path in an image. You define the line segment(or segments) by specifying their coordinates as input arguments.You

can define the line segments using a mouse. (By default, improfile usesnearest-neighbor interpolation, but you can specify a different method.For more information, see

Specifying the Interpolation Method.) improfile worksbest with grayscale and truecolor images.

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

improfile plotsthe 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 canthen specify line segments by clicking the endpoints;

improfile drawsa line between each two consecutive points you select. When you finishspecifying the path, press

Return. improfile displaysthe plot in a new figure.

In this example, you call improfile and specifya single line with the mouse. In this figure, the line is shown inred, and is drawn from top to bottom.

I = fitsread('solarspectra.fts');

imshow(I,[]);

improfile

3241193.html

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

Plot Produced by improfile

3241193.html

The example below shows how improfile workswith an RGB image. Use imshow to display the imagein a figure window. Call improfile without anyarguments and trace a line segment in the image interactively. Inthe figure, the black line indicates a line segment drawn from topto bottom. Double-click to end the line

segment.

imshow peppers.png

improfile

RGB Image with Line Segment Drawn with improfile

3241193.html

The improfile function displays a plot ofthe intensity values along the line segment. The plot includes separatelines for the red, green, and blue intensities. In the plot, noticehow low the blue values are at the beginning of the plot where theline

traverses the orange pepper.

Plot of Intensity Values Along a Line Segment in an RGB Image

3241193.html

Displaying a Contour Plot of Image Data

You can use the toolbox function imcontour todisplay a contour plot of the data in a grayscale image. A contouris a path in an image along which the image intensity values are equalto a constant. This function is similar

to the contour functionin MATLAB, but it automatically sets up the axes so their orientationand aspect ratio match the image.

This example displays a grayscale image of grains of rice anda contour plot of the image data:

Reada grayscale image and display it.

I = imread('rice.png');

imshow(I)

3241193.html

Display a contour plot of the grayscaleimage.

figure, imcontour(I,3)

3241193.html

You can use the clabel function to labelthe levels of the contours. See the description of

clabel in the MATLAB Function Referencefor details.

Creating an Image Histogram Using imhist

An image histogram is a chart that showsthe distribution of intensities in an indexed or grayscale image.You can use the information in a histogram to choose an appropriateenhancement operation. For example, if an image

histogram shows thatthe range of intensity values is small, you can use an intensity adjustmentfunction to spread the values across a wider range.

To create an image histogram, use the imhist function.This function creates a histogram plot by making

n equallyspaced bins, each representing a range of data values. It then calculatesthe number of pixels within each range.

The following example displays an image of grains of rice anda histogram based on 64 bins. The histogram shows a peak at around100, corresponding to the dark gray background in the image. For informationabout how to modify an image by changing the distribution

of its histogram,see Adjusting Intensity Values to a Specified Range.

Read image and display it.

I = imread('rice.png');

imshow(I)

3241193.html

Display histogram of image.

figure, imhist(I)

3241193.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值