Vous êtes sur la page 1sur 19

Digital Image Segmentation of Water Traces in Rock Images

Robert Kabera November 2009

Application of Research

This research explores various approaches to segmenting traces of water in rock images using the matlab image processing toolbox. A crucial characteristic to the design of image processing systems is the signicant level of testing and experimentation that typically is required before getting to an acceptable solution. This characteristic implies that the abillity to formulate approaches and quickly prototype candidate solutions generally plays a key role in reducing cost and time required to arrive at a viable system implementation.

What is Digital Image Processing?

An image can be understood as a two-dimensional function (x, y ), where x and y are spartial (plane) coordinates, and the amplitude of f at any pair of coordinates (x, y ) is called the intensity or gray level of the image at that point. When x, y, and the amplitude values of f are all nite, discrete quantities, we call the image a digital image. Thus, a digital image is composed of a nite number of elements, each of which has a particular location and value. P ixels is the term used widely to denote the elements of a digital image. The eld of digital image processing refers to processing digital images by means of a digital image. There are no clear-cut boundaries in the spectrum from image processing at one extreme to computer vision (the use of computers to emulate computer vision) on the other. However, a useful paradigm is to consider three types of computerized proccesses in this spectrum: low-, middle-, and high-level processes. Low level processes involve primitive operations, such as image preprocessing to reduce noise, contrast enhancement, and image sharpening. A low-level process is characterized by the fact that both its inputs and outputs are images. M id level processes on images involve tasks such as segmentation (partitioning an image into regions or objects), description of those objects to reduce them to a form suitable for computer processing, and classication (recognition) of individual objects. A mid-level process is characterized by the 1

fact that its inputs generally are images, but its outputs are attributes extracted from those images (i.e. edges, contours, and the identity of individual objects. Finally, highlevel processing involves making sense of an ensemble of recognized objects, as in image analysis (also called imageunderstanding ) and, at the far end of the spectrum, performing cognitive functions normally associated with human vision.

Image Types

The matlab image processing toolbox supports four types of images: gray-scale, binary, indexed and RGB images. Most monochrome image processing operations are carried out using binary or gray-scale images, so there will be a focus on these two image types. A gray scale image is a data matrix whose values represent shades of gray. The elements of a gray-scale have integer values in the range [0,255]. A binary image (also know as black and white) is a logical array of 0s for black spots and 1s for white spots in the image. An RGB color image is an M x N x 3 array of color pixels, where each color pixel is a triplet corresponding to the red, green, and blue components of an RGB image at a specic spatial location. An RGB image may be viewed as a stack of three gray-scale images that, when fed into red, green, and blue inputs of a color monitor, produce a color image on the screen. By convention, the three images forming an RGB color image are reered to as the red, green and blue components images.1

Image Segmentation

The focus of this research is on the mid-level processing of images commonly known as image segmentation. Segmentation subdivides an image into its constituent regions or objects. The level to which the subdivision is carried depends on the problem being solved. That is, segmentation should stop when the objects of interest have been isolated. For example, in an automated inspection of electronic assemblies, interest lies in analyzing images of the products with the objective of determining the presence or absence of specic anormalies, such as missing components or broken connection paths. There would be no reason to carry segmentation past the level of detail required to identify those elements. The segmenation of nontrivial images (mathematically-being an expression in which at least one variable is not equal to zero)is one of the most dicult tasks in image processing.2 Segmentation accuracy determines the eventual success or failure of computerized analysis procedures. For this reason, considerable care should be taken to improve the probability of rugged segmentation. This
1 Gonzalez, Rafael C., Richard E. Woods, and Steven L. Eddins. Digital Image Processing With Matlab. Natick: Gatesmark, 2009. p318 2 Nontrivial Denition Denition of Nontrivial at Dictionary.com. Dictionary.com Find the Meanings and Denitions of Words at Dictionary.com. Web. 26 Nov. 2009. http://dictionary.reference.com/browse/nontrivial.

proved to be a challenge is this research. There seemed to be an exchange of costs to pay for a cleanly segmented image but with a considereable loss of (original) image shape integrity versus the original shape of the image remaining intact but having a noisy and relatively less well-segmented image. Measures were taken to pereserve the integrity of the images to be processed in order to improve the accuracy of the on-going segmentation.

The Approach

Segmentation algorinthms for monochrome images (images displayed in a single color or shades of a single color) generally are based on one of two basic properties of image intensity values: discontinuity and similarity. In the rst category, the approach is to partition an image based on sudden changes in intensity, such as edges. The primary approaches in the second category are based on partitioning an image into regions that are similar according to a set of predened criteria. Both approaches are explored in this research, in the order of initially applying segmentation functions to the images of interest and then implementing morphological techniques for postprocessing.

The Bolt: An Introduction to the Matlab Image Toolbox

To intially get familiar with the matlab image processing toolbox, a bolt image will be used to test basic image processing functions. Because the bolt used has clearly dened boundaries of color pixels, its transformations upon being proccessed are very apparent. This makes it easy to get acquainted with the matlab image processing toolbox, before going on to segment the images of interest, rock images containing traces of water. Before attempting to segment an image, there are three ways to measure the capacity of an image to be segmented. These are (1) determining its threshold value T [0,1], (2) getting its degree of separabillity SM [0,1] and (3) visually looking at the separation between modes in the image histogram. Nearly half [0.5]T, high SM [>0.9]and large depth and width of the valleys separating the histogram modes are indicative of a clean segmentation. Examples of these three diagnostic methods will be discussed later. In a binary or gray scale image, the objective is to reasonably separate the object and background pixel intensity levels that are typically grouped into two dominant modes. One obvious way to extract the object from the background is to select a threshold T that separates these modes. This way, any image point (x, y ) at which f (x, y ) >T is called an object (or f oreground) point; otherwise, the point is called a background point (the reverse holds for dark objects on a light background). When T is a constant applicable over the entire image, the thresholding is known as global thresholding . When the value of T changes

over an image, the term variable thresholding is used.3 An eective way of preprocessing an image before attempting to segment it is to convert it to gray scale. The T and SM values as well as the histogram of the gray scale version of the bolt we would like to segment demonstrate the value of converting to gray scale before converting an image to binary. Figure 1 depicts the bolt initially used for function testing.

Figure 1: original bolt to be segmented The code for getting the T, SM and histogram of the bolt image is as follows: f = imread(bolt1.jpg); fg = rgb2gray(f); figure, imshow(fg) figure, imhist(fg) [T,SM] = graythresh(fg) T = 0.0.4275 SM = 0.6663 Figure 2 shows the bolt turned gray scale and gure 3 shows the image histogram of the gray scale image. We see from g. 3 that the bolt has a promising histogram despite low values for SM and T, indicating a low degree of separability of the intensities into two classes. With the following code, we convert the bolt to binary, where f is the image of the bolt being converted. fb = im2bw(f); figure, imshow(fb) Figure 4 shows that there was some measure of success in converting the bolt to binary, as foretold by the images histogram in gure 3. However, the black and white image of the bolt is noisy, it has a signicant pressence of one intensity overlapping the location of the other intensity, wherelse, this should
3 Gonzalez

558

Figure 2: bolt converted to grayscale not be so. In other words, we see a lot of black dots in the white area that should not be there. To deal with this, we can use image ltering to improve our conversion. The code and result of this change is below. w = fspecial(average,20); fa = imfilter(fb, w, replicate) figure, imshow(fa) In gure 5, we see the dierence made by ltering the image before converting it to black and white, all the black dots in the bottom left corner of the bolt image are nomore. Smoothing an image further claries the foreground and background points, increasing T spacing on the image histogram, and thus making thresholding more probable. The reasons the dots in the left corner of the bolt disappear is because they had pixels falling in the middle of the intensity average,thus, smoothing the image out made them fall into the background points. Hence, when the image was subsequently turned to black and white, the black dots disappear from the image because the signicantly greater presence of the foreground (white) in the left corner of the image easily takes over. We cannot overlook that clearing the noise in the image caused the rest of the image to loose its original shape integrity, especially near the center of the image. Later on, we will see that there is often a price to be paid between a well segmented image (with original shape of image distorted) and a not-so-well segmented image (but well preserved shape of original image). 5

Figure 3: histogram of gray scaled bolt

Using Threshold to Segment Water Traces in a Rock Image

We shall now use several approaches of thresholding to try to segment a rock image containing water traces. Fig 6 shows the rock image we would like to segment. After converting the image to gray scale and upon performing the prescribed diagnostic test to see how segmentable the image is, we see that it will be very dicult. Below is the code for these preliminary tests, where crp is the original color image: fg = rgb2gray(crp); imshow(fg)) [T,SM] = graythresh(fg) T = 0.2549 SM = 0.6545 Not only do we have low values for threshold T and separability SM, we also have a unimodal histogram (gure 8). This means we have a very unproprtionate value for foreground and background modes, and so, typical threshoding approaches wont work well. Since one of the main challange will be to preserve the orginal shape of the water traces, we proceed to create a reerence gray scale image with the following simple code. This image can be seen in gure 9. We call this reerence

Figure 4: bolt converted to black and white

Figure 5: ltered binary bolt because it most clearly shows the traces of the water in the rock image, much more so than the original color image itself does. f = rgb2gray(crp) figure, imshow(f, [.25 .32]), title(best integrity)) Having done this,we proceed to slightly lter the image, automatically generate a threshold value T using graythresh, and nally turn the image to black and white. GRAYTHRESH uses Otsus method, which chooses the threshold to minimize the intraclass variance of the thresholded black and white pixels.4 The code for this image is below. Its results can be seen in gure 10. fg = rgb2gray(crp); f = tofloat(fg);
4 Global

image threshold using Otsus method - MATLAB. The MathWorks.

Figure 6: rock image to be segmented figure, imshow(fa) fa = imfilter(f, w, replicate); Ta = graythresh(fa); ga = im2bw(fa, Ta); figure, imshow(ga)

Post-Processing Using Morphology

The results of gure 10 show a poorly segmented rock image. While the image is indeed black and white, there is a signicant excess of background noise and a distortion of the chicken feet, particularly the right-toes. To supplement this failed segmentation attempt, we implement some post image processing techniques. This approach will help in the transition from image-processing methods whose inputs and outputs are images, to image analysis methods, whose output attempt to describe the contents of the image. The techniques we look to use are dilation and erosion, both fundamental to morphological image processing. Dilation is an operation that grows or thickens objects in an image while erosion shrinks or thins objects in a binary. The specic erosion or dilation is controlled by a shape reered to as a structural element. The toolbox function STREL constructs structing elements with a variety of shapes and sizes. It is convention in image processing to let the rst parameter in an erosion or dilation function be the image and the second term be the structuring element,

Figure 7: gray rock image to be segmented which should be smaller than the image.5 To clean the white spots in the background of the rock image, we can use the commands for morphological erosion and dilation, these are morphological opening and closing. Opening removes completely regions of an object that cannot contain the structuring element, smooths object contours, breaks thin connections, and removes thin potrusions. Like opening, morphological closing tends to smooth the contours of objects. Unlike opening, however, closing typically joins narrow breaks, lls long thin gulfs, and lls holes smaller than the structuring elements. Opening and closing are implemented by toolbox functions IMOPEN and IMCLOSE. Both open and close functions can be combined in IMRODE to gain what we want: a reasonably uniform background. This is achieved by subtracting an eroded image from its dilated version, which produces a morphological gradient, which is a measure of local gray-level variation in the image. In graphics software for digital image editing, the term gradient is used for a gradual blend of color which can be considered as an even gradation from low to
5 Golnzalez

490

Figure 8: histogram of gray rock image to be segmented high values, as used from white to black in the images to the right.6 We now proceed to applying these new morphological techniques to improve the poor results of gure 10. However, instead of using as input a ltered image, which has no integrity to the original shape of the water traces, we use a graythresh image. [Tf SMf] = graythresh(f) Tf = 0.2549 figure, imshow(fa) SMf = 0.6531 gf = im2bw(f, Tf); figure, imshow(gf), title(graythresh) Note the consistently low values for T and SM. Also,in gure 11, note the better integrity of the graythresh rock image to water traces, espcially in the top-right corner. Applying the function IMRODE to the graythresh image with the following code produces the following results. M1 = imerode(gf, strel(disk, 1.0)); figure, imshow(M1), title(disk structural element) Here, we use a disk-shaped structural element of size 1. We see in gure 12 that the image is slightly well segmented with decent image shape integrity. We
6 Dilation, erosion, and the morphological gradient. MATLAB Central - Blogs. Web. 26 Nov. 2009.

10

Figure 9: clear traces of water in gray rock image now try to segment the image further, with less background noise by using a dick of size 3. M3 = imerode(gf, strel(disk, 3.0)); figure, imshow(M3), title(disk structural element) Figure 13 shows that a good and clean background in this segmentation comes at the cost of loosing the shape integrity of the water traces. This is as clean and noiseless as we can get the background without distorting the image beyond recognition. To demonstrate the danger of any further changes, below are examples of using the open and close functions to further reduce noise. NON = imopen(gf, strel(square, 5)); figure, imshow(NON), title(open noise reduced) CNON = imclose(NON, strel(square, 5)); figure, imshow(CNON), title(open noise reduced) Figures 14 and 15 demonstrate the distortion of images that can result from beyond reasonable segmentation. 11

Figure 10: ltered but poorly segemented rock image

Candidate Segmentation by Means of Clustering and Texture

A method of segmentation that combines the techniques of cluestering and texture based segmentation is known as region growing .7 Matlabs Image Processing toolbox has this function; its only caveat is that it does not work for predened seed points with an intensity level of less than 1. Thus, this methodas it currently exists-could not be used on our water traces because our highest intensity level was less than .5. However, if customized, region-growing has great potential for optimal segmentation. As its name implies, region growing is a procedure that grows pixels or subregions based on predened criteria for growth. The basic approach is to start with a set of seed points and from these grow regions by appeding to each seed those neighboring pixels that have predened properties similar to the seed (such as specic ranges of gray level or color). When there no predened set of
7 Gonzalez, Rafael C., Richard E. Woods, and Steven L. Eddins. Digital Image Processing With Matlab. Natick: Gatesmark, 2009. p578

12

Figure 11: graythreshed segemented rock image seeds, one way approach is to compute at every pixel the same set of properties that ultimately will be used to to assign pixels to regions during the growing process. Should these computation results display clusters of values, the pixels whose proporties place them near the centroid of these clusters can be used as seed. The selection of similarity criteria depends not only on the problem under consideration, but also on the type of image available. When images are monochrome, region analysis must be carried out with a set of descriptors based on intensity levels (such as moments or texture) and spatial properties (such as connectivity). The use of descriptors is based on the assumption that a model of expected results is at least partially available. The syntax for the region growing function as it exists is as follows. [g, NR, SI, TI] = regiongrow(f, S, T) F is an image to be segmented and S denes an intensity value such that all points in f with that value become seed points. The threshold value T is used to test if a pixel in the image is suciently similar to the seed or seeds to which it is 8-connected. All values of S and T are scaled to the range[0,1]. In 13

Figure 12: disk structural element size 1 segemented rock image the output, g is the segmented image and N R is the number of regions found. Parameters SI is an image containing the seed points, and paramters T I is an image containing the pixels that passed the threshold test before they were proccessed for connectivity.

10

Fun Segmentations and Concluding Remarks

In this conclusion, we explore very random yet interesting segmentations such as creating a shadow segmentation and white soil crust segmentations. A shadow is achieved by subtracting the opened version of an image from the orignal. This not only generates a shadow, but in so doing,creates a reasonably uniform background. We generate the shadow in gure 16 using the following code. se = strel(disk, 2); f2 = imtophat(gf, se); figure, imshow(f2), title(Good Shadow))

14

Figure 13: disk structural element size 3 segemented rock image Lastly, we explore the water traces being segmentated in a manner similar to water cracks in soil, with the following code. Essnetially, we segmented a graythresh rock image with the predened conditions being the opposite of the black and white elements of the image. The results of this, seen in gure 17, were obtained with the following code. g = im2bw(f, graythresh(f)); gc = g; D = bwdist(gc); L = watershed(-D); figure, imshow (L) w = L == 0; g2 = g w; imshow(g2) A great deal of time was lost in this research by attempting to group pixels with the same intesity level to form a region without taking connectivity into account. This often yielded a meanningless segmentation. Thus, it must be 15

Figure 14: open noise reduction noted that the use of connectivity is fundamental to nontrivial image segmentation. Furthermore, from this research, we see that there is often a price to be paid between a well segmented image (with original shape of image distorted) and a not-so-well segmented image (but well preserved shape of original image). More segmentations can be investigated using the region growing technique previously discussed, provided more exible seed parameters are attained. While there is no such thing as perfect segmentation, perhaps methods such as this one can generate more perfect segmentations.

11

References

1. Gonzalez, Rafael C., Richard E. Woods, and Steven L. Eddins. Digital Image Processing With Matlab. 3rd Edition. Natick: Gatesmark, 2009. 2. "Nontrivial Definition | Definition of Nontrivial at Dictionary.com."

16

Figure 15: closed noise reduction Dictionary.com | Find the Meanings and Definitions of Words at Dictionary.com. Web. 26 Nov. 2009. <http://dictionary.reference.com/browse/nontrivial>. 3. "Global image threshold using Otsus method - MATLAB." The MathWorks - MATLAB and Simulink for Technical Computing.Web. 26 Nov. 2009. <http://www.mathworks.com/access/helpdesk/help/toolbox/images/graythresh.html> 4.Dilation, erosion, and the morphological gradient MATLAB Central - Blogs. Web. 26 Nov. 2009. <http://blogs.mathworks.com/steve/2006/09/25/ dilation-erosion-and-the-morphological-gradient/> 5. Gonzalez, Rafael C., Richard E. Woods, and Steven L. Eddins. Digital Image Processing With Matlab. 2nd Edition. Pearson Prentice Hall, 2008. 6. Doherty, Edward. Marcel Dekker, 1994. Image Processing Methods. Print. 17 New York:

Figure 16: shadow of water traces

18

Figure 17: crack segmentation of water traces

19

Vous aimerez peut-être aussi