Page history Edit this page How do I edit this website?
Original MediaWiki page

Max Inscribed Circles

The content of this page has not been vetted since shifting away from MediaWiki. If you’d like to help, check out the how to help guide!




on GitHub


This is an implementation of the Largest Inscribed Circle algorithm using an euclidean distance map. The algorithm is looped until a circle diameter smaller than the defined minimum diameter is found. The code for this plugin was inspired by this Matlab Central function


Plugin Dialog choices


As of July 26th 2016, the plugin has been rewritten with a new algorithm to make it run much faster.. See the faster implementation details figure. Faster implementation details

The previous implementation would calculate a distance map, then find the max value, place a circle and repeat. This was making it very slow for small circle diameters or large images as it needed to make one distance map calculation per circle on the whole image.

By using a Local Maxima Finder, we can draw multiple circles on a single pass, provided that these are

  1. The largest distances on the distance map image
  2. Not overlapping with one another

That way when there are plenty of circles that are the same size, we can draw them all at the same time.


This plugin is available from the PTBIOP Update Site. This places it in a “BIOP” Folder in the plugins directory of Fiji/ImageJ


Call up the plugin using PluginsBIOPImage AnalysisBinaryMax Inscribed Circles….

You can select the smallest circle diameter after which it will stop looking, and whether you want the plugin to run on the current selection or the current image mask.

It will add all the found circles to the ROI Manager.

Setting the Minimum Disk Diameter to 0 will return a single ROI with the largest inscribed circle.


Result of Plugin on whole image

Macro Recordable

Making use of the GenericDialog class, the plugin is macro-recordable.

run("Max Inscribed Circles...", "minimum=20");

Running from a Plugin

What you need to run this in a plugin is

import ch.epfl.biop.MaxInscribedCircles;

And then you can use it in two ways. Statically or with a builder pattern

//imp must be an 8-bit binary image. No stacks
// static call
ArrayList<Roi> circles = MaxInscribedCircles.findCircles(ImagePlus imp, double minD, boolean isSelectionOnly);

Example using the builder pattern in Groovy from a script

#@ ImagePlus imp
#@ RoiManager rm 
import ij.gui.Overlay
import ch.epfl.biop.MaxInscribedCircles


// Builder Pattern. Useful if you have a stack
MaxInscribedCircles mic = MaxInscribedCircles.builder(imp)
        .minimumDiameter( 5 )
        .useSelectionOnly( true ) // will only do the selection and ignore the stack
        .getSpine(true )
        .spineClosenessTolerance( 20 )
        .spineMinimumSimilarity( 0.3)
        .appendPositionToName( true )

def circles = mic.getCircles()
def spines = mic.getSpines()
def spineParts = mic.getSpineParts()

def overlay = new Overlay()

circles.each{ rm.addRoi( it ) }
spines.each{ rm.addRoi( it ) }
spineParts.each{ overlay.add( it ) }

imp.setOverlay( overlay )

Set the last argument isSelectionOnly to true if you want to fit circles in the current selection. If you’d like to use the pixel mask, set it to false.


The accuracy is not perfect as we are using the distance map which has finite values. But for most practical purposes (Circles larger than 2 pixels in diameter), it should be sufficient.