31-08-2012, 10:26 AM
compute statistics
compute statistics.doc (Size: 335 KB / Downloads: 36)
Introduction
Using an image of rice grains, this example illustrates how you can enhance an image to correct for nonuniform illumination, and then use the enhanced image to identify individual grains. This enables you to learn about the characteristics of the grains and easily compute statistics for all the grains in the image.
Use Morphological Opening to Estimate the Background
In the sample image, the background illumination is brighter in the center of the image than at the bottom. In this step, the example uses a morphological opening operation to estimate the background illumination. Morphological opening is an erosion followed by a dilation, using the same structuring element for both operations. The opening operation has the effect of removing objects that cannot completely contain the structuring element. For more information about morphological image processing, see Morphological Operations
View the Background Approximation as a Surface
Use the surf command to create a surface display of the background (the background approximation created in Step 2). The surf command creates colored parametric surfaces that enable you to view mathematical functions over a rectangular region. However, the surf function requires data of class double, so you first need to convert background using the double command:
figure, surf(double(background(1:8:end,1:8:end))),zlim([0 255]);
set(gca,'ydir','reverse');
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.)
In the surface display, [0, 0] represents the origin, or upper-left corner of the image. The highest part of the curve indicates that the highest pixel values of background (and consequently rice.png) occur near the middle rows of the image. The lowest pixel values occur at the bottom of the image and are represented in the surface plot by the lowest part of the curve.
The surface plot is a Handle Graphics® object. You can use object properties to fine-tune its appearance. For more information, see the surface reference page.