Skip to content

Instantly share code, notes, and snippets.

@hirokai
Created March 15, 2014 23:06
Show Gist options
  • Save hirokai/9575307 to your computer and use it in GitHub Desktop.
Save hirokai/9575307 to your computer and use it in GitHub Desktop.
Simple radial profile analysis for Fiji with Jython
# Example of Fiji script for calculating a radial profile.
from ij import IJ
from ij.process import ImageStatistics as IS
from ij.gui import Roi, OvalRoi
# Get mean pixel intensity in a specified donut-shaped area
def get_mean_in_donut(imp, cx, cy, min_r, max_r):
options = IS.MEAN | IS.MEDIAN | IS.MIN_MAX | IS.AREA
ip = imp.getProcessor()
# Define two ROIs. One is outer diameter. Another is inner diameter.
roi_small = OvalRoi(cx-min_r, cy-min_r, min_r*2+1, min_r*2+1)
roi_big = OvalRoi(cx-max_r, cy-max_r, max_r*2+1, max_r*2+1)
imp.setRoi(roi_small)
stats_small = IS.getStatistics(ip, options, imp.getCalibration())
imp.setRoi(roi_big)
stats_big = IS.getStatistics(ip, options, imp.getCalibration())
# Subtract integrated intensity of inner circle from that of outer circle, and divide it by the area.
return (stats_big.mean * stats_big.area - stats_small.mean * stats_small.area) / (stats_big.area - stats_small.area)
# Getting a radial profile.
def get_radialprofile(imp, cx, cy, rmax, num_bin):
r_interval = rmax / num_bin
rs = [(i*r_interval, (i+1)*r_interval) for i in range(num_bin)]
return [get_mean_in_donut(imp, cx, cy, r[0], r[1]) for r in rs]
# Starting point of the script
imp = IJ.getImage()
if not imp is None:
profile = get_radialprofile(imp, 300, 200, 100, 10)
print ",".join(map(str, profile))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment