Research Research Tools for Image Processing Mathematical Morphology for ImageJ Search

Mathematical Morphology plug-ins for ImageJ
Dr. Eugene Ageenko, Dr. Alexey Podlasov


Mathematical morphology

Mathematical morphology refers to a branch of nonlinear image processing and analysis developed initially by Georges Matheron and Jean Serra. Morphological image processing has become a standard part of the imaging scientist’s toolbox and today is applied daily to a wide range of industrial applications, including (and certainly not limited to) inspection, biomedical imaging, document processing, pattern recognition, metallurgy, microscopy, and robot vision. Because the morphological operations can serve as a universal language for image processing, their application is only limited by the ability to design effective algorithms and efficient computational implementation [12, 14, 15]. On the practical level most introductory books in image analysis and most available commercial imaging software include at least few morphological operators.

We define In mathematical morphology the binary image space  is defined as  (the space of all possible image pixel locations), and the binary image  – as a set  of foreground pixel locations:

The main principle of mathematical morphology is to analyze the geometrical and topological structure of the image  by “probing” that image with another small set  called structuring element. By the “probing” we understand applying the structuring element  at every pixel location  and determining the cardinal value that is the number of elements of coinciding with elements of  translated along , i.e. . In this way structuring element  defines the positions of analyzed pixels relatively to a given pixel location . Coinciding of pixels with the translated structuring element is illustrated on the Figure 2.


Figure. Probing the image with the structuring element.

The morphological transformation  is defined as some transformation of the image using the information retrieved with “probing” of  with structuring element . The choice of the appropriate structuring element strongly depends on the particular application at hand. This however should not be viewed as a limitation, since it usually leads to additional flexibility in algorithm design.

Classical mathematical morphology is based on set theory with transformations exhibiting all-or-nothing precision of pure logic and therefore such transformations could be sensitive to image noise. Sometimes this logic-based paradigm is referred as standard or crisp morphology. Soft morphology is an alternative approach, in which morphological operations are based on more general weighted order statistics. The definitions of the soft morphological operators are similar to crisp operators but incorporate a factor specifying how well the structuring element fits within the image.  This property makes soft morphological filters to be less sensitive to noise that is very practical feature in many image processing applications.


Data representations

Binary images in ImageJ

For binary images we will use the following default photometric assumption that white pixel color corresponds to the image background, when black to the foreground. Using that we assume that empty image is all white by default.

Because ImageJ does not support directly binary images, we use a grayscale image representation to hold binary image. We will assume that pixel value 0 corresponds to a black (foreground) pixel, and pixel value 255 (0xFF) corresponds to a white (background) pixel of binary image. In further when we refer to a binary image we will assume its grayscale representation.

Structuring elements

Structuring element defines a local neighborhood of a pixel where morphological operators are applied. We implemented structuring element concept in class Element. All operators described below use name of structuring element as one of its input parameters. Class Element contains 10 statically predefined structuring elements (see Table 1). Plugins access structuring element via “element” parameter which must contain element’s name. For example to use element CROSS_3X3 call plugin with “element=’CROSS_3X3’”.

Table 1: Structuring elements left to right: BLOCK_3X3, CROSS_3X3, PIERCED_BLOCK_3X3, PIERCED_CROSS_3X3, VERTICAL_BAR_1X3, HORIZONTAL_BAR_3X1, PIERCED_V_BAR_1X3, PIERCED_H_BAR_3X1, SMALL_BLOCK_2X2, SMALL_TRANS_BLOCK_2X2

Here the position of current pixel is underlined. Plugins developed below assume that element BLOCK_3X3 applied by default.


Developed plug-ins

Plugin descriptions

Current subsection describes implemented operators which require only structuring element as parameter. The only exception is rank operator requiring integer rank parameter. Plugins are summarized in Table 2 and brief description of implementation aspects are given further.

Table 2: Plugin summary

Plugin’s name

Plugin description

Example of using

Rank(*)

rank operator

IJ.run("Rank ", "rank=2 element = ’BLOCK_3X3’");

Median

median operator  

IJ.run("Median ", "element = ’BLOCK_3X3’");

Erode

erosion , also denoted as 

IJ.run("Erode ", "element = ’BLOCK_3X3’");

Dilate

dilation , also denoted as

IJ.run("Dilate ", "element = ’BLOCK_3X3’");

Open

opening, which is

IJ.run("Open ", "element = ’BLOCK_3X3’");

Close

closing, which is

IJ.run("Close ", "element = ’BLOCK_3X3’");

OpenClose

sequential opening and closing

IJ.run("OpenClose ", "element = ’BLOCK_3X3’");

CloseOpen

sequential closing and opening

IJ.run("CloseOpen ", "element = ’BLOCK_3X3’");

RankMaxOpen(*)

soft analogue of opening operator

IJ.run(" RankMaxOpen ", "rank=2 element = ’BLOCK_3X3’");

RankMinClose(*)

soft analogue of closing operator

IJ.run(" RankMinClose ", "rank=2 element = ’BLOCK_3X3’");

(*) These plugins require additional parameter “rank” that is an integral number representing the operator’s rank.

Rank operator

The rank operator Rank(Element, Rank) denoted by , where Element or A is a structuring element defining the neighborhood and Rank or s is rank parameter, sets pixel to be black if the local neighborhood of the current pixel location contains at least Rank black pixels. If rank parameter is greater than the amount of pixels in structuring element or less than 0 then it is assumed to be equal to this number. Rank plugin is the basis for the implementation of other morphological operators

Median

Median operator denoted by  is a rank operator with ranking parameter equal to a number of pixels in structuring element divided by two or mathematically . Therefore we can calculate that number for given structuring element and give it to already implemented rank operator.

IJ.run("Rank", "rank=" + IJ.d2s((int)(element.length/2)) + "element=" + str);
IJ.run("Rename...", "title='Median with " + str + "'");

Erode

Erosion operator is denoted by  or . As it has been shown in [12], erosion could be implemented via rank operator: , where  is the number of pixels in structuring element A.

IJ.run("Rank ", "rank=-1 element=" + str);

Dilate

Dilation operator is denoted by  or . Implementation of dilation is much the same as implementation of erosion. As it has been shown in [12], dilation could be implemented via rank operator . We don’t even need to calculate number of pixels in A.

IJ.run("Rank ", "rank=1 element=" + str);

Open

As defined, opening operator is a result of applying erosion and dilation sequentially. Therefore it is natural to use plugins described above to implement it as follows (str is a string containing the name of a structuring element):

IJ.run("Erode ", "element='" + str + "'");
IJ.run("Dilate ", "element='" + str + "'");

Close

In a similar to previous section we implement closing operator in a same manner. Closing operator is a result of sequential application of dilation and erosion:

IJ.run("Dilate ", "element='" + str + "'");
IJ.run("Erode ", "element='" + str + "'");

OpenClose

This plugin is also implemented using already developed plugins by sequential applying of open and close operators. Therefore its implementation does not demand any detailed observation.

IJ.run("Open ", "element='" + str + "'");
IJ.run("Close ", "element='" + str + "'");

CloseOpen

This plugin is also implemented using already developed plugins by sequential applying of close and open operators.

IJ.run("Close ", "element='" + str + "'");
IJ.run("Open ", "element='" + str + "'");

Rank-max opening

Rank-max opening operator  also could be implemented using plugins developed above. Algorithm is as follows:

Algorithm:

Procedure RankMaxOpening (A : structuring element, k: integer)
    Image T = Create copy of input image.
    Do
Rank(A,k) with input image
    Do
Dilate(A) with input image
    Image R = input image AND T
    Delete T
    Return
R
End

Rank-min closing

Rank-min closing operator , where is the reflection of and is the number of pixels in . We can avoid reflecting of structuring element by using the fact that , where  is the complement of  (i.e. ). The algorithm is implemented in a fashion similar to the previous one.


Macro-operations

With ImageJ one can easily create macros to implement new filters using existing ones from within ImageJ's environment. Here we present one simple macro implementing Alternative-Sequential filter. Alternative sequential filters are the compositions of openings and closings with increasing structuring element [16]. The result performance of the filter depends on the order (open-close or close-open), the shape of structuring element and the speed of its increasing.

Rank AS-filter macro

This macro implements Ranked AS-filter using Rank-max Opening and Rank-min Closing plugins.

Macro:

for(i=0; i<9; i++) {
    run("RankMinClose ", "rank="+i+" element=BLOCK_3X3");

    run("RankMaxOpen ", "rank="+i+" element=BLOCK_3X3");
}

This macro implements Close-Open AS-filter, but it is easy to modify it to implement Open-Close AS-filter.


Testing

The visual appearance of the 256x256 pixels reference binary image processed with some of the plugins.


House affected by salt-and-pepper noise


OpenClosing with block 3x3


Rank-max opening with block 3x3


Rank AS Close-Open with block 3x3

 In the following we evaluate execution times for several plugins. All plugins were applied for the large 5000x5000 pixels test image. The Pentium 4, 1.80GHz, 256MB RAM based computer running Microsoft Windows XP Professional has been used for execution time evaluation. The Table 3 represents average execution times for implemented morphological plugins. We have used ImageJ version 1.3.2j running on Java Virtual Machine version 1.3.1_03 by Sun Microsystems. For comparison we give running times for the morphological filtering algorithms implemented by us in C-language and compiled to native Windows (WinApi) code using Microsoft Visual Studio 6 compiler suite. The algorithms were executed several hundreds times and average running time has been computed. As one can see the speed of about  3 Mpixels per second has been obtained.

Table 2. Average execution times for for morphological plugins using large 25 Mpixels image

Plugin

Rank

Median

Dilation

Erosion

Open

Close

OpenClose

CloseOpen

ImageJ execution time, s

8,2

7,4

7,4

7,3

14,6

14,9

34,4

32,2

Winapi execution time, s

8,1

7,7

9,0

6,5

12,8

12,9

26,06

25,85


Download Mathematical Morphology Plug-ins for ImageJ (ZIP-file)


Updated: 2008   © Eugene Ageenko