• Ingen resultater fundet

Chapter 6 Digital Image Analysis 32

6.2 Mathematical morphology

classifying it as beef most likely would.

Median filter

The median filter replaces the pixel by the median of the neighborhood pixels. The size can be defined as it is found suitable. It should be noted that unlike most of the other filters this needs a sorting mechanism in implementation and can therefore prove to be slow with large kernel sizes and large images.

K nearest neighbor filter

The nearest neighbor filter replaces the pixel with the average of the k pixels, which values are closest to the pixel in question. E.g. having a 3 3× filter with 6 nearest neighbors, means taking the average of the 6 pixels which value are closest to the pixel in question, discarding the remaining three pixel values.

6.2 Mathematical morphology

Morphology is said to be the study of forms and structure; mathematical morphology is an approach for the study of spatial forms and structures in digital images. This section focused on mathematical morphology of binary images, and from there moves the presented methods into the gray scale domain.

6.2.1 Binary morphology

As claimed in [13], an image can be considered a setShaving the objects of the image as the subsetXS. Using the set definition, it enables the use of set concepts and modifiers such as union, intersection, translation etc. and enables us to identify the properties of transformations such as anti-extensive, increasing, idem-potency and homo-topic. This section will not focus on the mathematical theory, since this is out of the thesis texts scope. Instead it will introduce the most common operations and concepts, starting with the simple translation.

The translation is introduced since this forms a basis for understanding the other concepts introduces. Translating the set X with a vector hcan be defined as:

{

:

}

Xh = ∈ ∃ ∈z S x X z= +x h (6.5) As it is observed the translation simply move the objects in an image based on the translation vectorh.

In order to define further operations the structuring element (B) is introduced, for the translation in equation 6.5, the structuring element can be said to be translation vector. However normally

36  Digital Image Analysis

the structuring element is a set of points centered on an origin. The use and importance of the structuring element will become apparent when introducing the common operators, but generally it is said that the structuring element is to morphology what the filter kernel is to filtering.

6.2.1.1 Dilation

One of the basic operators in morphology is dilation. Dilation of the set of objectsX with the structuring elementBis defined as:

b b B

X B X

⊕ =

(6.6)

Meaning dilation enlarges the imageX depended on the structuring element in use. An example is given below.

Figure 6.2 - Dilation example

6.2.1.2 Erosion

Intuitively introduction of the dilation, motivates the introduction of an opposite operation, namely the erosion. Erosion of a setX with the structuring elementBis defined as:

b b B

X B X

Θ =

(6.7)

Erosion causes the image to shrink depended on the structuring element in use. An example of erosion is shown below.

Figure 6.3 - Erosion example

Having defined these two basics operations, they enable the introduction of two other useful operations opening and closing.

6.2 Mathematical morphology  37

6.2.1.3 Opening and Closing

Opening and closing are defined using the basic operators of erosion and dilation introduced in the prior section.

Opening is defined as:

( )

X B=XB= X BΘ ⊕B (6.8)

First image is eroded with B and the resulting image is then dilated with B. It can be hard to envision the outcome from the definition above, but generally opening is said to separate the particles in the image.

An example is given here:

Figure 6.4 - Opening example

Closing is defined as:

( )

X• =B XB = XB ΘB (6.9)

First the image is dilated with B, which is followed by erosion with B. Again it can be hard to envision the effects of this, it is normally said that closing connects the objects, and fills holes.

An example is given here:

Figure 6.5 - Closing example

6.2.1.4 Reconstruction

The reconstruction transformation is quite different from others introduced, in the sense it does not directly use a structuring element. Reconstruction instead uses two images of the same size (a marker

( )

J and a mask

( )

I ) to generate the resulting image.

38  Digital Image Analysis

The resulting image consists of the connected components in the mask, which is marked in marker image. A component is said to be marked if one of the pixels in the component is marked with a 1 in the marker.

The reconstruction transformation is defined in [14] as “the union of components in Iwhich contain at least one pixel inJ ”.

An example is given here:

a) b) c)

Figure 6.6 – (a) The mask, (b) The marker, (c) Result of reconstruction

6.2.2 Grayscale morphology

Moving binary morphology into the grayscale domain proves to create useful tools, not only for the already defined binary operators, but also opens for new operations that prove to be powerful when analyzing the profile of grayscale image.

6.2.2.1 Dilation and Erosion

To move the first four of the introduced operations into the grayscale domain, is simply a matter of defining dilation and erosion. Before being able to do this, a definition of the grayscale structural element is needed.

One of the approached is to simply keep the structural element in a binary form, or as it is also called having a flat structural element. This makes the transition into grayscale straight forward, since the OR operation will be equivalent to maximum and AND will be equivalent to minimum. Thus leading to the following definition of dilation

[maxi j B, ]

( [

,

] [ ]

,

)

X B x m i n j b i j

⊕ = − − + (6.11)

And the following for erosion:

[mini j B, ]

( [

,

] [ ]

,

)

X B x m i n j b i j

Θ = − − − (6.12)

6.2 Mathematical morphology  39

It should be noted here that erosion and dilation on grayscale images, visually will have the opposite effect than on binary images. This is since 1 in a binary image means black and 0 means white, which is opposite to grayscale images. In grayscale images large values means white and small values indicate black. Below is included an example of applying erosion and dilation to a grayscale image.

a) b) c) d)

Figure 6.7 - (a) Original image, (b) Structural element, (c) Dilated image, (d) Eroded image

The example images clearly show a brighter image after dilation and a darker after erosion, this is especially apparent around the eye. Moving opening and closing into the grayscale from here is straightforward and will therefore not be examined further.

6.2.2.2 Reconstruction

Recalling the reconstruction transformation it was said to “extract the connected components in the mask, which were marked in the marker”. This raises some questions when moving into a grayscale domain, when is components connected in a grayscale image? One obvious approach could be to state that if the pixel values are higher than a certain valuek, the components are connected. This motivates the definition of a threshold function. The threshold function Tk for an imageIis defined as:

{ }

( ) ( )

k I

T I = pD I pk (6.13)

Moving reconstruction into the grayscale domain can be done thereby be done, by saying it is to extract the peaks from the mask which are marked in the marker.

Using this it is now possible to define grayscale reconstruction for a mask Iand a marker J both defined in the discrete set D=

{

0,1,....(N1)

}

such thatJ I, meaning each pixel in the marker must not exceed the corresponding pixel value of the mask. The reconstruction transformation ρI( )J can then be defined as: ([14])

p DI

∀ ∈ ( )( ) max{

[

0, 1

]

( )

(

( ) }

)

I J p k N p TK I T Jk

ρ = ∈ − ∈ρ (6.14)

The principle is illustrated in Figure 6.8.

40  Digital Image Analysis

Figure 6.8 – Reconstruction of the mask f from the marker g (Figure from [14])

6.2.2.3 H-Domes

As mentioned in the introduction text of the section, greyscale morphology turns out to be a powerful tool for examining the profile of the image; this is due to the nature of the greyscale reconstruction transformation introduced. It turns out that using reconstruction it is possible to easily find the maximal structures or regional maximums in the images using a method called H-Domes.

The H-Domes transformation creates the marker to use in reconstruction, directly from the mask and a valueh by simply subtracting this value from the mask. Having created the marker h-domes performs a reconstruction using the marker, and creates the resulting h-domes image by subtracting the reconstructed image from the original image leaving only the regional maximums in the image. This concept is illustrated in Figure 6.9.

Figure 6.9 - H-Domes concept (From [14])

Formalising the concept gives the following definition.

D Ih( )= −I ρI(Ih) (6.15) It becomes obvious from Figure 6.9, that it is extremely important to select an appropriate

hvalue, in order to get a useful result.

7.1 Principal Component Analysis  41