digital image segmentation of water traces in rock images

Upload: kabe88101

Post on 04-Jun-2018

222 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/14/2019 Digital Image Segmentation of Water Traces in Rock Images

    1/19

    Digital Image Segmentation of Water Traces in

    Rock Images

    Robert Kabera

    November 2009

    1 Application of Research

    This research explores various approaches to segmenting traces of water in rockimages using the matlab image processing toolbox. A crucial characteristic tothe design of image processing systems is the significant level of testing andexperimentation that typically is required before getting to an acceptable solu-tion. This characteristic implies that the abillity to formulate approaches andquickly prototype candidate solutions generally plays a key role in reducing costand time required to arrive at a viable system implementation.

    2 What is Digital Image Processing?

    An image can be understood as a two-dimensional function (x, y), where xand y are spartial (plane) coordinates, and the amplitude off at any pair ofcoordinates (x, y) is called the intensity or gray

    level of the image at that

    point. Whenx, y,and the amplitude values offare all finite, discrete quantities,we call the image a digital image. Thus, a digital image is composed of a finitenumber of elements, each of which has a particular location and value. Pixelsis the term used widely to denote the elements of a digital image. The field ofdigital image processing refers to processing digital images by means of a digitalimage.

    There are no clear-cut boundaries in the spectrum from image processing atone extreme to computer vision (the use of computers to emulate computervision) on the other. However, a useful paradigm is to consider three typesof computerized proccesses in this spectrum: low-, middle-, and high-level pro-cesses. Low level processes involve primitive operations, such as image pre-

    processing to reduce noise, contrast enhancement, and image sharpening. Alow-level process is characterized by the fact that both its inputs and outputsare images. M id level processes on images involve tasks such as segmenta-tion (partitioning an image into regions or objects), description of those objectsto reduce them to a form suitable for computer processing, and classification(recognition) of individual objects. A mid-level process is characterized by the

    1

  • 8/14/2019 Digital Image Segmentation of Water Traces in Rock Images

    2/19

    fact that its inputs generally are images, but its outputs are attributes extractedfrom those images (i.e. edges, contours, and the identity of individual objects.

    Finally, highlevel processing involves making sense of an ensemble of recog-nized objects, as in image analysis (also called imageunderstanding) and, atthe far end of the spectrum, performing cognitive functions normally associatedwith human vision.

    3 Image Types

    The matlab image processing toolbox supports four types of images: gray-scale,binary, indexed and RGB images. Most monochrome image processing opera-tions are carried out using binary or gray-scale images, so there will be a focuson these two image types. A gray scale image is a data matrix whose valuesrepresent 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 logi-cal array of 0s for black spots and 1s for white spots in the image. An RGBcolor image is an M x N x 3 array ofcolor pixels, where each color pixel is atriplet corresponding to the red, green, and blue components of an RGB imageat a specific spatial location. An RGB image may be viewed as a stack ofthree gray-scale images that, when fed into red, green, and blue inputs of acolor monitor, produce a color image on the screen. By convention, the threeimages forming an RGB color image are reffered to as the red, green and bluecomponents images.1

    4 Image Segmentation

    The focus of this research is on the mid-level processing of images commonlyknown as image segmentation. Segmentation subdivides an image into its con-stituent regions or objects. The level to which the subdivision is carried dependson the problem being solved. That is, segmentation should stop when the ob-

    jects of interest have been isolated. For example, in an automated inspection ofelectronic assemblies, interest lies in analyzing images of the products with theobjective of determining the presence or absence of specific anormalies, such asmissing components or broken connection paths. There would be no reason tocarry segmentation past the level of detail required to identify those elements.

    The segmenation of nontrivial images (mathematically-being an expressionin which at least one variable is not equal to zero)is one of the most difficult tasksin image processing.2 Segmentation accuracy determines the eventual successor failure of computerized analysis procedures. For this reason, considerable

    care should be taken to improve the probability of rugged segmentation. This1Gonzalez, Rafael C., Richard E. Woods, and Steven L. Eddins. Digital Image Processing

    With Matlab. Natick: Gatesmark, 2009. p3182Nontrivial Definition Definition of Nontrivial at Dictionary.com. Dictionary.com

    Find the Meanings and Definitions of Words at Dictionary.com. Web. 26 Nov. 2009.http://dictionary.reference.com/browse/nontrivial.

    2

  • 8/14/2019 Digital Image Segmentation of Water Traces in Rock Images

    3/19

    proved to be a challenge is this research. There seemed to be an exchangeof 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 remainingintact but having a noisy and relatively less well-segmented image. Measureswere taken to pereserve the integrity of the images to be processed in order toimprove the accuracy of the on-going segmentation.

    5 The Approach

    Segmentation algorinthms for monochrome images (images displayed in a sin-gle color or shades of a single color) generally are based on one of two basicproperties of image intensity values: discontinuity and similarity. In the firstcategory, the approach is to partition an image based on sudden changes inintensity, such as edges. The primary approaches in the second category are

    based on partitioning an image into regions that are similar according to a setof predefined criteria. Both approaches are explored in this research, in theorder of initially applying segmentation functions to the images of interest andthen implementing morphological techniques for postprocessing.

    6 The Bolt: An Introduction to the Matlab Im-

    age Toolbox

    To intially get familiar with the matlab image processing toolbox, a bolt imagewill be used to test basic image processing functions. Because the bolt usedhas clearly defined boundaries of color pixels, its transformations upon beingproccessed are very apparent. This makes it easy to get acquainted with thematlab image processing toolbox, before going on to segment the images ofinterest, rock images containing traces of water.

    Before attempting to segment an image, there are three ways to measure thecapacity of an image to be segmented. These are (1) determining its thresholdvalue T [0,1], (2) getting its degree of separabillity SM [0,1] and (3) visuallylooking 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 thehistogram modes are indicative of a clean segmentation. Examples of thesethree diagnostic methods will be discussed later.

    In a binary or gray scale image, the objective is to reasonably separate theobject and background pixel intensity levels that are typically grouped into twodominant modes. One obvious way to extract the object from the background

    is to select a thresholdT

    that separates these modes. This way, any image point(x, y) at whichf(x, y) >Tis called an object (or f oreground) point; otherwise,the point is called a background point (the reverse holds for dark objects on alight background). When Tis a constant applicable over the entire image, thethresholding is known as global thresholding. When the value of T changes

    3

  • 8/14/2019 Digital Image Segmentation of Water Traces in Rock Images

    4/19

    over an image, the term variable thresholding is used.3

    An effective 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 histogramof the gray scale version of the bolt we would like to segment demonstrate thevalue 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 figure 3 shows the imagehistogram of the gray scale image. We see from fig. 3 that the bolt has apromising histogram despite low values for SM and T, indicating a low degreeof separability of the intensities into two classes. With the following code, weconvert 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 thebolt to binary, as foretold by the images histogram in figure 3. However, theblack and white image of the bolt is noisy, it has a significant pressence of oneintensity overlapping the location of the other intensity, wherelse, this should

    3Gonzalez 558

    4

  • 8/14/2019 Digital Image Segmentation of Water Traces in Rock Images

    5/19

    Figure 2: bolt converted to grayscale

    not be so. In other words, we see a lot of black dots in the white area thatshould not be there. To deal with this, we can use image filtering to improveour conversion. The code and result of this change is below.

    w = fspecial(average,20);fa = imfilter(fb, w, replicate)

    figure, imshow(fa)

    In figure 5, we see the difference made by filtering the image before convert-ing it to black and white, all the black dots in the bottom left corner of thebolt image are nomore. Smoothing an image further clarifies the foregroundand background points, increasing T spacing on the image histogram, and thusmaking thresholding more probable. The reasons the dots in the left corner ofthe bolt disappear is because they had pixels falling in the middle of the inten-sity average,thus, smoothing the image out made them fall into the backgroundpoints. Hence, when the image was subsequently turned to black and white, theblack dots disappear from the image because the significantly 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 theimage. Later on, we will see that there is often a price to be paid between awell segmented image (with original shape of image distorted) and a not-so-wellsegmented image (but well preserved shape of original image).

    5

  • 8/14/2019 Digital Image Segmentation of Water Traces in Rock Images

    6/19

    Figure 3: histogram of gray scaled bolt

    7 Using Threshold to Segment Water Traces in

    a Rock Image

    We shall now use several approaches of thresholding to try to segment a rockimage containing water traces. Fig 6 shows the rock image we would like tosegment.

    After converting the image to gray scale and upon performing the prescribeddiagnostic test to see how segmentable the image is, we see that it will be verydifficult. Below is the code for these preliminary tests, where crp is the originalcolor 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 alsohave a unimodal histogram (figure 8). This means we have a very unproprtion-

    ate value for foreground and background modes, and so, typical threshodingapproaches wont work well.

    Since one of the main challange will be to preserve the orginal shape ofthe water traces, we proceed to create a refference gray scale image with thefollowing simple code. This image can be seen in figure 9. We call this refference

    6

  • 8/14/2019 Digital Image Segmentation of Water Traces in Rock Images

    7/19

    Figure 4: bolt converted to black and white

    Figure 5: filtered binary bolt

    because it most clearly shows the traces of the water in the rock image, muchmore 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 filter the image, automatically gen-erate a threshold value T using graythresh, and finally turn the image to blackand 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 figure 10.

    fg = rgb2gray(crp);

    f = tofloat(fg);

    4Global image threshold using Otsus method - MATLAB. The MathWorks.

    7

  • 8/14/2019 Digital Image Segmentation of Water Traces in Rock Images

    8/19

    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)

    8 Post-Processing Using Morphology

    The results of figure 10 show a poorly segmented rock image. While the imageis indeed black and white, there is a significant excess of background noise and adistortion of the chicken feet, particularly the right-toes. To supplement thisfailed segmentation attempt, we implement some post image processing tech-niques. This approach will help in the transition from image-processing methodswhose inputs and outputs are images, to image analysis methods, whose outputattempt to describe the contents of the image. The techniques we look to usearedilationand erosion, both fundamental to morphological image processing.Dilationis an operation that grows or thickens objects in an image whileerosionshrinks or thins objects in a binary. The specific erosion or dilation

    is controlled by a shape reffered to as a structural element.The toolbox func-tion STREL constructs structing elements with a variety of shapes and sizes.It is convention in image processing to let the first parameter in an erosion ordilation function be the image and the second term be the structuring element,

    8

  • 8/14/2019 Digital Image Segmentation of Water Traces in Rock Images

    9/19

    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 usethe commands for morphological erosion and dilation, these are morphologicalopening and closing. Opening removes completely regions of an object thatcannot contain the structuring element, smooths object contours, breaks thinconnections, and removes thin potrusions. Like opening, morphological closingtends to smooth the contours of objects. Unlike opening, however, closing typ-ically joins narrow breaks, fills long thin gulfs, and fills holes smaller than thestructuring elements.

    Opening and closing are implemented by toolbox functions IMOPEN andIMCLOSE. Both open and close functions can be combined in IMRODE to gainwhat we want: a reasonably uniform background. This is achieved by subtract-

    ing an eroded image from its dilated version, which produces a morphologicalgradient, which is a measure of local gray-level variation in the image. Ingraphics software for digital image editing, the term gradient is used for a grad-ual blend of color which can be considered as an even gradation from low to

    5Golnzalez 490

    9

  • 8/14/2019 Digital Image Segmentation of Water Traces in Rock Images

    10/19

    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 improvethe poor results of figure 10. However, instead of using as input a filteredimage, which has no integrity to the original shape of the water traces, we usea 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 figure 11, note thebetter integrity of the graythresh rock image to water traces, espcially in thetop-right corner. Applying the function IMRODE to the graythresh image withthe 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 figure 12that the image is slightly well segmented with decent image shape integrity. We

    6Dilation, erosion, and the morphological gradient. MATLAB Central - Blogs. Web. 26Nov. 2009.

    10

  • 8/14/2019 Digital Image Segmentation of Water Traces in Rock Images

    11/19

    Figure 9: clear traces of water in gray rock image

    now try to segment the image further, with less background noise by using adick 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 segmentationcomes at the cost of loosing the shape integrity of the water traces. This is asclean and noiseless as we can get the background without distorting the imagebeyond recognition. To demonstrate the danger of any further changes, beloware 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 frombeyond reasonable segmentation.

    11

  • 8/14/2019 Digital Image Segmentation of Water Traces in Rock Images

    12/19

    Figure 10: filtered but poorly segemented rock image

    9 Candidate Segmentation by Means of Clus-

    tering and Texture

    A method of segmentation that combines the techniques of cluestering and tex-ture based segmentation is known as region growing.7 Matlabs Image Pro-cessing toolbox has this function; its only caveat is that it does not work forpredefined seed points with an intensity level of less than 1. Thus, this method-as it currently exists-could not be used on our water traces because our highestintensity level was less than .5. However, if customized, region-growing hasgreat potential for optimal segmentation.

    As its name implies, region growing is a procedure that grows pixels or sub-regions based on predefined criteria for growth. The basic approach is to start

    with a set of seed points and from these grow regions by appeding to eachseed those neighboring pixels that have predefined properties similar to the seed(such as specific ranges of gray level or color). When there no predefined set of

    7Gonzalez, Rafael C., Richard E. Woods, and Steven L. Eddins. Digital Image ProcessingWith Matlab. Natick: Gatesmark, 2009. p578

    12

  • 8/14/2019 Digital Image Segmentation of Water Traces in Rock Images

    13/19

    Figure 11: graythreshed segemented rock image

    seeds, one way approach is to compute at every pixel the same set of propertiesthat ultimately will be used to to assign pixels to regions during the growingprocess. Should these computation results display clusters of values, the pixelswhose proporties place them near the centroid of these clusters can be usedas seed. The selection of similarity criteria depends not only on the problemunder consideration, but also on the type of image available. When images aremonochrome, region analysis must be carried out with a set of descriptors basedon intensity levels (such as moments or texture) and spatial properties (such asconnectivity). The use of descriptors is based on the assumption that a modelof 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)

    Fis an image to be segmented and Sdefines an intensity value such thatall points in f with that value become seed points. The threshold value T isused to test if a pixel in the image is sufficiently similar to the seed or seeds towhich it is 8-connected. All values ofS and T are scaled to the range[0,1]. In

    13

  • 8/14/2019 Digital Image Segmentation of Water Traces in Rock Images

    14/19

    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 isan image containing the pixels that passed the threshold test before they wereproccessed for connectivity.

    10 Fun Segmentations and Concluding Remarks

    In this conclusion, we explore very random yet interesting segmentations suchas creating a shadow segmentation and white soil crust segmentations. Ashadow is achieved by subtracting the opened version of an image from theorignal. This not only generates a shadow, but in so doing,creates a reasonably

    uniform background. We generate the shadow in figure 16 using the followingcode.

    se = strel(disk, 2);

    f2 = imtophat(gf, se);

    figure, imshow(f2), title(Good Shadow))

    14

  • 8/14/2019 Digital Image Segmentation of Water Traces in Rock Images

    15/19

    Figure 13: disk structural element size 3 segemented rock image

    Lastly, we explore the water traces being segmentated in a manner similarto water cracks in soil, with the following code. Essnetially, we segmented agraythresh rock image with the predefined conditions being the opposite of theblack and white elements of the image. The results of this, seen in figure 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 pixelswith the same intesity level to form a region without taking connectivity intoaccount. This often yielded a meanningless segmentation. Thus, it must be

    15

  • 8/14/2019 Digital Image Segmentation of Water Traces in Rock Images

    16/19

    Figure 14: open noise reduction

    noted that the use of connectivity is fundamental to nontrivial image segmen-tation. Furthermore, from this research, we see that there is often a price to bepaid 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 pre-viously discussed, provided more flexible seed parameters are attained. Whilethere is no such thing as perfect segmentation, perhaps methods such as thisone 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

  • 8/14/2019 Digital Image Segmentation of Water Traces in Rock Images

    17/19

    Figure 15: closed noise reduction

    Dictionary.com | Find the Meanings and Definitions of Words at

    Dictionary.com. Web. 26 Nov. 2009.

    .

    3. "Global image threshold using Otsus method - MATLAB."

    The MathWorks - MATLAB and Simulink for Technical Computing.Web.

    26 Nov. 2009.

    4.Dilation, erosion, and the morphological gradient

    MATLAB Central - Blogs. Web. 26 Nov. 2009.

    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. Image Processing Methods. New York:

    Marcel Dekker, 1994. Print.

    17

  • 8/14/2019 Digital Image Segmentation of Water Traces in Rock Images

    18/19

    Figure 16: shadow of water traces

    18

  • 8/14/2019 Digital Image Segmentation of Water Traces in Rock Images

    19/19

    Figure 17: crack segmentation of water traces

    19