Coccobiom2 - SEM measuring macros

revised March 2015


When working with coccoliths we often are able to study numerous specimens and from numerous samples. Given this quantitative comparisons of morphology can be very useful for refining and testing species concepts, examining possible ecophenotypic controls on morphology, studying evolution, improving biostratigraphy, etc. On the other hand there is often a problem that rather few parameters can be measured independently since coccoliths have rather simple morphologies and many potential parameters are strongly covariant - e.g. if working with placolith coccoliths it is often the case that coccolith length, width and number of elements are very strongly correlated so essentially a single parameter, size is responsible for the vast majority of variation in all three parameters. So a typical coccolith morphometric study will consist of measuring a few parameters from a very large number of specimens. Given this streamlining and automating the process as far as possible can make a massive difference to the quantity and quality of results. I have ben carrying out studies of this type with a range of collaborators over a long period and have used macros written in NIH-Image and its successor programs to facilitate this. The version documented here is a set developed for work with Emiliania and Gephyrocapsa.

Objective - a set of macros to measure Emiliania huxleyi and Gephyrocapsa coccoliths in distal view fast and accurately, including: NB Most of the routines are not very specialised and could be applied to other genera of coccoliths or to other types of image with little or no modification. The macro code is not complex and can be modified by anyone with a little programming experience.


Getting started

  1. Download Fiji (June 2014 version) from the website
  2. Download the archive containing macro files, some more documentation, and test images from download here.
  3. Install Fiji and unpack the archive.
  4. Open Fiji and experiment with its functions using the image supplied and/or your own images
  5. Install the macros (use menu item Plugins/Macros/Install...)- and find them listed under PlugIns/Macros
  6. Open the test image of E. huxleyi
  7. Experiment with setting the magnification using both built in Fiji tools and the macros - see below.
  8. Experiment with measuring the coccolith using both built in Fiji tools and the macros - see below.
  9. Read the rest of these notes.
  10. Send feedback - writing macros/getting a nice workflow takes a fairly long time, documenting it takes a lot more work. This is not a fully worked out step through yet and I do not know how far to go in producing one. I need feedback. Jeremy Young

Overview of the process


  1. Open new set of images using menu command: File/Import../Import sequence
  2. If the images are small then Rescale the images using menu command: Image/Scale..
    In Dialog box set: X Scale 5.0; Y scale 5; interpolation bilinear; process entire stack; create new window
  3. Run macro set magnification [f5]
    in dialog box set: SEM calibration - NOC, magnification/1000 - 25 [ignore other options]


  1. set distal shield using the ellipse selection tool then measure - [1]
  2. set outer edge of tube - place cursor in location where tube edge is clearly visible - [2]
  3. set inner edge of tube - [3]
  4. a. Emiliania only: observe accuracy of ray identification b. Gephyrocapsa only: make bridge diagonal - [e]; rotate bridge diagonal - [s/d] set bridge diagonal - [r]
  5. select next image - [4]

Data export

This part is very easy. Open the results window; select all; copy and paste into an excel spreadsheet.

Details of the process


Setting up a batch of images

Typically with morphometric work you will want to measure a batch of say 50-60 images of a species from each of several samples. This requires working through numerous images an these macros assume each specimen is on a separate image. To build up the set of images see the separate image collecting macros. Having separate images for each specimen makes archiving and automation easier and is my preferred method. Process is basically:
  1. Prepare the images with each image being the same magnification, cropped to the same size
  2. and containing 1 coccolith lying flat in distal view.
  3. Transfer the set of images to a folder
  4. In ImageJ select menu option File/Import/Image sequence... and select the folder
  5. If desired use the dialog box options to enlarge all the images in the stack - this can help significantly with measuring. I hae worked succesfully with Ehuxleyi specimens captured as 100 x 100 pixel SEM images and enlarged to 500 x 500 pixel images.
  6. The program opens the images as a stack which you can rapidly work through without opening and closing individual images (look at menu Image/Stacks/ to see more things you can do with the stack of images). This will not work if the images are different sizes.

Setting the magnification

As with any image analysis program you can set the scale so that measurements are made in microns rather than pixels. There arre two ways to do this.
  1. From a scalebar using commands buit into ImageJ
  2. From recorded magnification using the macro

Finally - don't assume the scalebars on your SEMs are correct - they can be wrong although this is less common now. An easy check is provided by E.huxleyi - the length of a well-formed E. huxleyi coccolith is very close to its length/10 - e.g an Ehux cocolth with 35 rays will be about 3.5µm long (+/- about 10%) if you measure a few specimens and they are consistently departing from this then suspect your scalebars are wrong.

Images from older SEMs may also be distorted - often the vertical scale is 5% less than the horizontal scale so the images should first be stretched in Photoshop or ImageJ.


The macros work fine on TEMs. For the ehux ray identification routine you need to switch between detecting bright and dark peaks using macro choose dark or bright peaks [f6].


[1] Set outside edge of coccolith by drawing an ellipse (select ellipse tool from the toolbar - NOT the oval tool), drag from the best defined end to opposite end of coccolith to set length and orientation of the ellipse; then adjust the ellipse width by dragging handles on the edges. key-[1]

Adjustments to the ellipse can be made via the following macros (not that in practice you need to much).

[f] [t] - fatter thinner (NB once you have measured a couple of specimens then these can be used instead dragging handles)

[s] [d] rotate left/right (this can be useful). If you remember some latin s/d is sinistral/dextral.

[o] [l] [j] [k] move up/down left/right (rarely useful in practice)

[n] [h] shrink/grow (rarely useful in practice)

NB For each of these holding down the spacebar while pressing the key will result in larger adjustments

Rerunning the macro [1] initiates measuring of a new specimen, i.e. it will create a new row in the results window, so it should only be done once per specimen.

[2] Set outer edge of tube by placing mouse on inner edge of d shield at a point where it is well-defined. key-[2] or [z]

If macro [z] is used then only the rim width is calculated (NB The macro measures the distance from the mouse to the nearest point on the rim ellipse, using a routine described in Young et al., 1994). This is displayed as an ellipse around the rim. Ideally this ellipse should neatly match the outer tube but it won't always. Deviations can result from irregular rim, tilted specimens or mis-set rim ellipse. If the last of these seems likely it may be worth remeasuring them (using the adjustment macros)

If macro [2] is used then in addition the distal shield rays are identified, counted and their average width measured. To do this the macro samples the greyscale values around an ellipse halfway between the outer tube edge and the rim edge, then it detects local brightness maxima around this ellipse. These are identified by placing a red square on the image Ray widths are then measured by finding their edges (on a brightness profile these are points of maximum steepness). These ray widths are shown on the image as red lines.

Finally the ray widths are ranked from widest to narrowest and widths of the middle 50% are averaged (this is done in order to eliminate rogue values from misidentified rays, merged rays etc). The selected ray widths are marked with black squares.

If macro [z] is run after macro [2] then the tube tube width will be set independently of the ray number. This is useful e.g. with type R Ehux where ray number can be set from the outer edge where the rays show serrated outline.

Rerunning macro [2] will recalculate the rim width, ray-number and ray-thickness based on the current cursor location and overwrite the previous results, so it can be done repeatedly without any problems.

[3] Set inner edge of tube by placing mouse on edge of central area at a point where it is well-defined. key-[3] NB The point to try to identify is inner top edge of the tube (not the base of the tube), this is often a bright edge. Also note that although an ellipse is placed around the central area the parameter which is recorded is the spacing between this ellipse and the outer tube ellipse. If the inner tube magian is irregular then what we want is an estimate of the average tube thickness. For an Ehux with a completely closed central area click right in the centre of the specimen.

Rerunning the macro will recalculate the tube width based on the current cursor location and overwrite the previous results, so it can be done repeatedly without any problems. Macros [2] and [3] can be run in reverse sequence without any problems

[3a] Adjust ray-number (Emiliania)

The ray counting macro is much more successful than we might expect from the quality of the images, but on the other hand ray number is very strongly correlated with coccolith length -so scientifically it is probably not worth adjusting the ray counts unless there is reason to believe the population (or some of it) is unusual in this respect)

If ray number is consistently too high or low then adjust the "window" used to detect the rays by using [f7]. The default value is set based on the magnification and will give good results for E. huxleyi if the magnification is set correctly (Ie in part the ray identification macro 'cheats' because it is set up to detect rays at the spacing of Ehux rays). If rays are being consistently missed then decrease the window size; if too many 'rays' are being detected then increase the window value. The default value is set when macro [f5] is run. For TEM images the rays will appear dark not bright so use macro f6 to change to selecting dark peaks.

[3b] Measure the bridge orientation (Gephyrocapsa)

  1. A line is drawn through the centre of the coccolith at a likely bridge orientation. This is done by a macro [x] with no need for any user input (the mouse position is not used).
  2. The line is rotated until it is parallel to the bridge. This can be done manually by dragging the end points of the line (nb if you right click or press ctrl then the line will rotate about its mid point). Alternatively it can be done via macros [q] or [w] which rotate the bar in increments of 1°, holding the space bar results in rotation of 10°.

Alternatively - set orientation with a hand drawn line-selection (toggle between selection tools by using macro [9]) and if desired rotate this using [q] / [w] or set angle directly from it [s]

[4] select next image key

This steps to the next image in the stack, if the specimen if unsuitable it can be repeated

NB The < and > keys can also be used to step through the stack of specimens, but they will not remove the overlay so the dedicated macro [4] is better to use.

Oops - correcting mistakes! After selecting the next image it is important that the next macro run is [1]. If any other macro is run then the results of the previous specimen will be changed, and displayed on the screen. An easy error to make is to press [t] or [f] to correct ellipse width before actually setting the outer ellipse (macro-[1]). If you do this just do the reverse action to undo it (e.g. if you tapped [f] twice, then tap [t] twice to undo the effect), then [f8] to remove the overlay and start again. (To understand this, try it out observing also how the numbers in the results window change)

Tilted specimens and specimens on coccospheres

The measurement routine used here is vulnerable to tilt, or rather it makes the problems of making reliable measurements on tilted specimens very obvious. On tilted specimens the width on opposite sides of the coccolith will appear different the long axis orientation may be difficult to determine exactly, the axial cross will not lie at the centre of the specimen and the tube ellipses will not track the features nicely. Such specimens should not be measured unless there is a severe shortage of specimens. If you need to measure specimens on coccospheres I suggest experimenting with setting the ellipse then tuning its position etc using the adjustment macros.

Shield width

The program applies the axial ratio of the previous measurement to the next measurement. This minimises the amount of manual adjustment needed BUT it is important to watch and fine tune the width each time. The use of this routine will reduce the variability in recorded axial ratios, so if this is of special interest the macro could be adjusted to force the user into correcting ellipticity each time.

Additional macros

[f8] remove overlay - clears screen of overlay (NB removing overlay makes selection tools work more smoothly)

[f9] change tool - toggle between ellipse measure tool (which is normally wanted) and line tool

Coccobiom2-collect: Macros for collecting specimens from batch processed images

Purpose: collect and count specimens from batch collected SEM images (i.e. images auto-captured in large batches on an automated SEM). Specifically they are designed for the use with images captured on the Southampton NOC SEM, but in principle should work fine with any SEM.




Place cursor over specimen

Run key macro corresponding to the species - e.g. [a]. the macro then:

Repeat until all specimens in the image have been counted

run macro next slice [4] to move on to next image and update log of progress (log window)


  1. If images are in isolated images - specimens at the edge should only be included if >50% of the specimen is in the image.
  2. If images are in a grid/array with significant overlap between tiles - an overlay rectangle can be added to the image and used as the margin of area for selecting specimens (this is very easy and works well - applied to batch images collected by Martine on NHM SEM).
  3. If images are in a grid/array with no overlap between tiles - this is the usual case with the NOC images. To handle this the macros have been written to determine of the specimen is likely to continue onto an adjacent image and if so to make a composite sub-image from both the active image and the adjacent image. (NB This works around all four edges but not at the corners, since this would require patching together a sub-image from 4 images which would have needed more programming than seemed worthwhile).

NB At present changing between these modes requires alteration to the macro code - should be rewritten to make it a selection in the start batch dialog.

NB After 60 distal Ehux specimens have been counted a message appears indicating this -> no need to collect further specimens

Window behaviour - the stack window in imageJ can seem to behave a bit erratically. Note the following

  1. to pan image holddown shift and use one finger on trackpad
  2. to flick through slices of the stack use < and > keys, or use scroll bar at bottom of image (but sroll keys on this work erratically)
  3. if stack window does not show the scroll bar at bottom try zooming to x100, resizing the image, then zooming back down.
  4. two-finger scrolling on the trackpad will result in scrolling through the slices.
  5. clicking in the scroll bar will result in scrolling through the slices.


Customising the key assignments. At present this needs to be done by editing the macro - sparray assignments Better would be to have macro read a text file Start batch dialog - having separate sample prefix and sample number fields is not really ideal, too many cases where it does not work, so probably better to use a single string number a string


The key assignment data consists of the following fields for each key
Jeremy Young, UCL, March 2012, updated March 2015