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!

File

Max_Inscribed_Circle.jar

Source

on GitHub


Purpose

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

max-largest-circ-dialog2

Plugin Dialog choices

Details

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.

Installation

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

Use

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.

max-largest-circ-beforeafter

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

rm.reset()

// 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 )
        .build()

mic.process()
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.

Notes

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.