Académique Documents
Professionnel Documents
Culture Documents
The Image Processing Toolbox is a collection of functions that extend the capability of the MATLAB numeric computing environment. The toolbox supports a wide range of image processing operations, including:
Spatial image transformations Morphological operations Neighborhood and block operations Linear filtering and filter design Transforms Image analysis and enhancement Image registration Deblurring Region of interest operations
Many of the toolbox functions are MATLAB M-files, a series of MATLAB statements that implement specialized image processing algorithms. You can view the MATLAB code for these functions using the statement
type function_name
You can extend the capabilities of the Image Processing Toolbox by writing your own M-files, or by using the toolbox in combination with other toolboxes, such as the Signal Processing Toolbox and the Wavelet Toolbox.
To read an image, use the imread command. Let's read in a TIFF image named pout.tif (which is one of the sample images that is supplied with the Image Processing Toolbox), and store it in an array named I.
I=imread('pout.tif');
call to imhist with the figure command so that the histogram does not overwrite the display of the image I in the current figure window.)
figure, imhist(I) % Display a histogram of I in a new figure.
Notice how the intensity range is rather narrow. It does not cover the potential range of [0, 255], and is missing the high and low values that would result in good contrast. Now call histeq to spread the intensity values over the full range, thereby improving the contrast of I. Return the modified image in the variable I2.
I2 = histeq(I); % Equalize I and output in new array I2.
See how the pixel values now extend across the full range of possible values.
I = imread('rice.tif'); imshow(I)
The example uses MATLAB indexing syntax to view only 1 out of 8 pixels in each direction; otherwise the surface plot would be too dense. The example also sets the scale of the plot to better match the range of the uint8 data and reverses the y-axis of the display to provide a better view of the data (the pixels at the bottom of the image appear at the front of the surface plot).
Now call the whos command to see what type of array the thresholded image bw is.
whos
The size of the objects The accuracy of your approximated background Whether you set the connectivity parameter to 4 or 8 Whether or not any objects are touching (in which case they may be labeled as one object) In the example, some grains of rice are touching, so bwlabel treats them as one object.
We chose the left edge of a grain and got the following results.
grain = 0 0 0 0 0 0 0 60 60
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 60 60 60 60 60 0 0 0
0 60 60 60 60 60 0 0 0
60 60 60 60 60 60 60 0 0
60 60 60 60 60 60 60 0 0
60 60 60 60 60 60 60 0 0
60 60 60 60 60 60 60 0 0
A good way to view a label matrix is to display it as a pseudo-color indexed image. In the pseudo-color image, the number that identifies each object in the label matrix maps to a different color in the associated colormap matrix. When you view a label matrix as an RGB image, the objects in the image are easier to distinguish. To view a label matrix in this way, use the label2rgb function. Using this function, you can specify the colormap, the background color, and how objects in the label matrix map to colors in the colormap.
RGB_label = label2rgb(labeled, @spring, 'c', 'shuffle'); imshow(RGB_label);
To find the area of the component labeled with 51's, use dot notation to access the Area field in the 51st element in the graindata structure array. Note that structure field names are case sensitive, so you need to capitalize the name as shown.
graindata(51).Area
To find the smallest possible bounding box and the centroid (center of mass) for the same component, use this code:
graindata(51).BoundingBox, graindata(51).Centroid ans = 142.5000 ans = 155.3953 89.5000 24.0000 26.0000
102.1791
To create a new vector, allgrains, which holds just the area measurement for each grain, use this code:
allgrains = [graindata.Area]; whos allgrains
Call the whos command to see how MATLAB allocated the allgrains variable.
Name Size Bytes Class
allgrains
1x80
640
double array
is a one-row array of 80 elements, where each element contains the area measurement of a grain. Check the area of the 51st element of allgrains.
allgrains allgrains(51)
returns
ans = 296
returns
ans = 695
Use the find command to return the component label of this large-sized grain.
biggrain = find(allgrains==695)
returns
biggrain =
68
returns
ans = 249
Make a histogram containing 20 bins that show the distribution of rice grain sizes.
hist(allgrains,20)
References:
www.mathworks.com/products/image/ www.mathtools.net/MATLAB/Image_Processing/ www.amath.colorado.edu/courses/4720/2000Spr/Labs/Worksheets/Matlab_tutorial/matlabimpr.html www.imageprocessingplace.com/DIPUM/dipum_book_description/book_description.htm