Morphological Operators for ImageJ

You probably downloaded this file and plugins as a single zip file from: http://www.dentistry.bham.ac.uk/landinig/
This is my collection of ImageJ plugins to perform various morphological operations.
All plugins are recordable. Some macros that make use of those plugins are also included.
While most macros were written to deal with white particles, the plugins, deal with both, black or white particles (this means that the macros can be easily modified to deal with black particles too).
Tested under ImageJ 1.34o.
Please make sure that you have the latest version of the ImageJ ij.jar file.

Disclaimer: The software in these pages is experimental. Use these plugins at your own risk. Although I have made every effort to make sure that they run as intended, there may be bugs and unexpected behaviour in instances that I have not envisaged. Please send any comments, problems or improvements to G.Landini at bham. ac. uk

Copyright notice: Please check the copyright notices in the source code of each plugin. Some of the plugins are modifications of earlier versions written by other authors and therefore their original copyright notices apply. Please respect the original authors authorship notices.
If no specific copyright notice is included, then consider the plugin as free software: you can redistribute it and/or modify it under the terms of the GNU General Public license as published by the Free Software Foundation; either version 2 of the license, or (at your option) any later version.
These programs are distributed in the hope that they will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the programs; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

BinaryConditionalDilate_.class
This plugin dilates (3x3 neighbourhood, 8-connected) particlesin an image (called seed) inside another image (called mask). The procedure can be applied n of times, or until idempotence if n = -1. In that case the procedure becomes is the same as BinaryReconstruction.


BinaryConditionalErode_.class
This plugin erodes (3x3 neighbourhood, 8-connected) particles in an image (called seed) except what is masked in another image (called mask) (i.e. the mask "protects" what should not be eroded). it can be applied n times, or, until idempotence if n = -1.


BinaryConnectivity_.class
Returns the number of connected pixels (+1) to each foreground pixel (8 neighbours): background = 0, single pixel = 1, end of a line = 2, bifurcations = 3, triple points = 4, etc. Brightness/Contrast must be adjusted to see the result.


BinaryDilate_.class
This plugin performs a 3x3 8-neighbour Binary Dilation of a binary image. The differences with the built in Dilation in ImageJ are:

Notice: This plugin will be discontinued since ImageJ 1.33q fixed a bug that prevented border processing and also implements the use "coefficients". Note, however that in ImageJ, the coefficients range from 1 to 8 instead of 0 to 7.

BinaryDilateNoMerge4_.class
BinaryDilateNoMerge8_.class

These plugins perform a conditional binary dilation of a binary image (without merging particles together). The results are similar to a binary watershed transform of the background, partitioning it into areas of influence of the particles. Dilations are done with 4 or 8 pixel structuring elements respectively. The number of iterations can be set. Use -1 for dilation until idempotence.
Very slow, maybe there are better algorithms, but slow seems better than nothing...
If you need to dilate without merging until idempotence, then use the macro Influence_Zones.txt described below.


BinaryErode_.class
This plugin performs a 3x3 8-neighbour Binary Erosion of a binary image.
The differences with the built in Erosion in ImageJ are:

Notice: This plugin will be discontinued since ImageJ 1.33q fixed a bug that prevented border processing and also implements the use "coefficients". Note, however that in ImageJ, the coefficients range from 1 to 8 instead of 0 to 7.

BinaryFill_.class
This plugin fills holes in 8-connected particles (and also in child-particles) of a binary image. This function was incorporated in ImageJ v.1.31o (Process->Binary->Fill holes).


BinaryFilterReconstruct_.class
This plugin filters 8-connected particles in a binary image that otherwise would disappear after n erosions. The difference with morphological Opening is that BinaryFilterReconstruct preserves the original shape or the particles (Opening tends to smooth the boundaries of particles). The algorithm is n erosions, followed by a Binary Reconstruction of the original image based on the eroded image as the seed.


BinaryHitOrMiss_.class
This plugin returns the locations of the image that match the kernel pattern.
The pattern is a 3x3 neighbourhood where 0=empty, 1=set, 2=don't care.


BinaryLabel8_.class
ImageJ plugin for labelling particles (8 neighbours) in a binary image.
Can label up to 65530 particles in a unique greyscale value (from 1 to 65531), after that, the colours are recycled.
The output is a new 16 bit greyscale image with re-scaled brightness.


BinaryReconstruct_.class
This is a very powerful morphological operation that reconstructs (retains) 8-connected particles in an image (called mask) based on markers present in another image (called seed).
It consists of dilating the seeds inside the mask (so particles that do not have seeds are not reconstructed).
This procedure is called "Feature-AND" in reference [2].


BinaryThick_.class
BinaryThick2_.class

These two plugins dilate the locations of the image that match one (BinaryThick_.class) or two (BinaryThick2_.class) kernel patterns.
First dilates then rotates the kernel, if set to do so. The pattern is a 3x3neighbourhood where 0=empty, 1=set, 2=don't care.


BinaryThin_.class
BinaryThin2_.class
These two plugins erode the locations of the image that match one (BinaryThick_.class) or two (BinaryThick2_.class) kernel patterns.
First erodes then rotates the kernel, if set to do so. The pattern is a 3x3 neighbourhood where 0=empty, 1=set, 2=don't care.


Domes_.class
This plugin extracts "domes" in a greyscale image.
Domes are bright 8-connected regions of a chosen height (measured from their top downwards) in the greyscale function.
It can also return "basins" (locally dark regions) instead of domes.
Domes and basins are good candidates to extract reconstruction markers in images with uneven backgrounds. See reference [3].


GreyscaleDilate_.class
GreyscaleErode_.class

These plugins perform a 3x3 Binary Dilation/Erosion of a greyscale image. Same as the Min and Max filters of radius=1 (8 neighbours) in ImageJ, but:


Greyscale "Proper" Morphological Filters (macros)


GreyscaleReconstruct_.class
This plugin reconstructs a greyscale image (the "mask" image) based on a "seed" image. This is an implementation of the parallel algorithm from [3].
It is very important to read Vincent's paper to understand greyscale reconstruction and its applications.
The reconstruction algorithm is: iterated 8-neighbour geodesic dilations of the seed UNDER the mask image until stability is reached (the idempotent limit).
It supports stacks reconstructed by a single seed image and also a single image reconstructed by a stack of seeds. Based on Calculator_Plus by Wayne Rasband.


Morphological Gradients and 2nd Derivative macros


EDM_16bits.txt
This macro produces an Euclidean Distance Map on a binary image [the object over which the EDM is calculated is assumed to be 255 and the background 0]. The macro extends the built in ImageJ command to distances of up to 65535 pixels. The result is a 16 bit image.


Particles4_.class
Particles8_.class
Particles8_Plus.class
These are plugins for estimating various statistics of binary 4- and 8-connected particles.
Warning!: The plugins assume square pixels only.
These plugins do not return the same values as the built in ImageJ Analyze Particles command because they use another concept to extract area and perimeter. Here, Perimeter and Area are measured from the centres of the boundary pixels of a particle.
Area disregards "holes" in the particles (i.e. it returns the area inside the boundary), but Pixels returns the number of pixels forming the particle (a particle with holes will therefore have more Area than Pixels).
Also note that here Area is calculated from the polygon formed by the boundary pixels. If the particle has no holes, then Area is smaller than Pixels (since the polygon is located in the centre of boundary pixels). Note that using this logic, Area for 1 pixel particles is 0, for a 2x2 square it is 1, etc. while the value of Pixels in each particle is what you see.

Why to write such a plugin?
This was created to return exactly the number of pixels in particles when dealing with synthetic images (such as percolation clusters).
The Analyze Particles command in ImageJ performs a running average of size 3 on the perimeter coordinates when calculating the polygon-area of particles.
That is a good way of reducing the effect of pixelation when calculating area and perimeter of digitised images, but in some instances one may want to know exactly (in pixels) the area of particles/clusters.

These plugins can label the particles in different colours. Some colours are reserved for the particle detection and various calculations, so there are only 250 labelling colours available (1 to 251). It is therefore possible when using Particles4_ that two 4-connected particles which are corner neighbours could end up labelled with the same colour and therefore look like an 8-connected particle (this could happen when a very large particle is surrounded by many small ones). Although the labelling may be confusing, the statistics generated are correct.(If one only needs to label the particles unequivocally, then it is better to use the BinaryLabel8_.class plugin because it can label up to 65530 particles in unique greyscale values --after that, it also recycles the labelling colour.)

The plugins can draw the centre of mass (rounded to the nearest pixel, labelled or not) of each particle or the start coordinates of each particle (the only pixel with 100% certainty that it belongs to the particle). These may be useful for reconstruction purposes (see the KeepParticlesInRange.txt macro below and BinaryReconstruct_ plugin above).
Filtered particles (smaller than the minimum and larger than the maximum sizes) are deleted from the image.

New in Version 1.6
The labels of the options have been modified so they are consistent with those of the built in Analyzer in ImageJ.
A new option "Overwrite Results" was added to prevent the macro asking to save or delete the current Results when executing from a macro.
The results of the particle analysis are now sent to the ResultsTable, so the data generated can be retrieved from a macro for further processing. The macros below show how to do it.

Note: Although these plugins can analyse stacks, the results from all the slices are stored in the same ResultsTable. The data has an extra column named 'Stack' that indicates where the measurements belong to. Therefore, the macro examples above need to be modified to work properly with stacks.

New in Version 1.7
The plugin analysis has been extended to include the following new parameters:

Particles8_Plus adds more parameters (complete list below).

New in Version 1.8
Fixed bug that did not delete single border pixels when "exclude edge particles" was selected. Added CountCorrect parameter for unbiased counting of particles. This parameter should be used with "exclude edge particles" checked.
Here is the complete list of parameters:

From these parameters, other morphometrical ratios can be derived: The formulas of the morphological ratios in OpenOffice (ParticlesPlus.sxc) and Excel (ParticlesPlus.xls) spreadsheet formats are included in the zip file. By pasting the plugin results under the red headers, the derived parameters are calculated under the headers in blue. Copy the formulas of the derived parameters from the first row after the headers to the rows below as necessary.
Example macros that show some of the new parameters: DrawBoundingBox.txt, DrawFeret&Breadth.txt, DrawMinR&MaxR.txt.
The macro UnbiasedCounting.txt counts particles that touch the top and right image frames.
The macro UnbiasedParticleArea.txt estimates the corrected average particle area and number using the CountCorrect parameter.

New in Version 1.8a of Particles8_Plus
Fixed a bug in the Minimal Bounding Circle routine.
Added an example macro: DrawBoundingCircle.txt.

New in Version 1.9
When the image is a stack, the stack label is written to the Results window ("null" otherwise).
Changed some parameter names that caused problems when importing the data into SPSS.
DrawFeret&Breadth.txt was updated to use the new parameter names.

References



First released 6/Nov/2003.
Updated 6/Dec/2003.
Updated 16/Dec/2003.
Updated 22/Apr/2004.
Updated 29/Dec/2004.
Updated 21/Mar/2005.
Updated 30/Apr/2005.
Updated 22/May/2005.
Updated 12/Jul/2005.