<s> from __future__ import division <EOL> import numpy as np <EOL> import mahotas as mh <EOL> from . . labeled import bwperim <EOL> from . . internal import _make_binary <EOL> __all__ = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> def roundness ( bw ) : <EOL> '''<STR_LIT>''' <EOL> bw = _make_binary ( bw ) <EOL> area = np . sum ( bw ) <EOL> perim = np . sum ( bwperim ( bw ) ) <EOL> if area == <NUM_LIT:0> : <EOL> return <NUM_LIT:0.> <EOL> return float ( perim ) * perim / <NUM_LIT> / np . pi / area <EOL> def ellipse_axes ( bwimage ) : <EOL> '''<STR_LIT>''' <EOL> from . moments import moments <EOL> bwimage = _make_binary ( bwimage ) <EOL> if not np . any ( bwimage ) : <EOL> return <NUM_LIT:0.> , <NUM_LIT:0.> <EOL> cof = mh . center_of_mass ( bwimage ) <EOL> hull_mu00 = moments ( bwimage , <NUM_LIT:0> , <NUM_LIT:0> , cof ) <EOL> hull_mu11 = moments ( bwimage , <NUM_LIT:1> , <NUM_LIT:1> , cof ) <EOL> hull_mu02 = moments ( bwimage , <NUM_LIT:0> , <NUM_LIT:2> , cof ) <EOL> hull_mu20 = moments ( bwimage , <NUM_LIT:2> , <NUM_LIT:0> , cof ) <EOL> semimajor = np . sqrt ( ( <NUM_LIT:2> * ( hull_mu20 + hull_mu02 + np . sqrt ( ( hull_mu20 - hull_mu02 ) ** <NUM_LIT:2> + <NUM_LIT:4> * hull_mu11 ** <NUM_LIT:2> ) ) ) / hull_mu00 ) <EOL> semiminor = np . sqrt ( ( <NUM_LIT:2> * ( hull_mu20 + hull_mu02 - np . sqrt ( ( hull_mu20 - hull_mu02 ) ** <NUM_LIT:2> + <NUM_LIT:4> * hull_mu11 ** <NUM_LIT:2> ) ) ) / hull_mu00 ) <EOL> return semimajor , semiminor <EOL> def eccentricity ( bwimage ) : <EOL> """<STR_LIT>""" <EOL> semimajor , semiminor = ellipse_axes ( bwimage ) <EOL> if semimajor == <NUM_LIT:0.> : <EOL> return <NUM_LIT:0.> <EOL> return np . sqrt ( semimajor ** <NUM_LIT:2> - semiminor ** <NUM_LIT:2> ) / semimajor </s>
