Skip to content

Instantly share code, notes, and snippets.

@miura
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miura/9641262 to your computer and use it in GitHub Desktop.
Save miura/9641262 to your computer and use it in GitHub Desktop.
Detecting outliers with occupied area.
from org.jfree.data.statistics import BoxAndWhiskerCalculator
from ij.measure import ResultsTable
from java.util import ArrayList, Arrays
VERBOSE = True
class InstBWC(BoxAndWhiskerCalculator):
def __init__(self):
pass
def getOutlierBound(rt):
""" Analyzes the results of the 1st partcile analysis.
Since the dilation of nuclear perimeter often causes
overlap of neighboring neculeus 'terrirories', such nucleus
are discarded from the measurements.
Small nucelei are already removed, but since rejection of nuclei depends on
standard outlier detection method, outliers in both smaller and larger sizes
are discarded.
"""
area = rt.getColumn(rt.getColumnIndex('Area'))
arealist = ArrayList(Arrays.asList(area.tolist()))
bwc = InstBWC()
ans = bwc.calculateBoxAndWhiskerStatistics(arealist)
#anscirc = bwc.calculateBoxAndWhiskerStatistics(circlist)
if (VERBOSE):
print ans.toString()
print ans.getOutliers()
q1 = ans.getQ1()
q3 = ans.getQ3()
intrange = q3 - q1
outlier_offset = intrange * 1.5
# circularity better be fixed.
#circq1 = anscirc.getQ1()
#circq3 = anscirc.getQ3()
#circintrange = circq3 - circq1
#circoutlier_offset = circintrange * 1.5
return q1, q3, outlier_offset
thisrt = ResultsTable.getResultsTable()
q1, q3, outlier_offset = getOutlierBound(thisrt)
lower = q1 - outlier_offset
upper = q3 + outlier_offset
print q1, q3, outlier_offset
print 'Lower boundary', lower
print 'Upper boundary', upper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment