Custom Measurement#
Subclass MeasureFeatures to extract custom features from detected
colonies.
from phenotypic.abc_ import MeasureFeatures
import pandas as pd
import numpy as np
class MeasureAspectRatio(MeasureFeatures):
"""Measure the aspect ratio of each colony's bounding box."""
def _operate(self, image):
from skimage.measure import regionprops
objmap = image.objmap[:]
rows = []
for prop in regionprops(objmap):
height = prop.bbox[2] - prop.bbox[0]
width = prop.bbox[3] - prop.bbox[1]
rows.append({
"ObjectLabel": prop.label,
"AspectRatio": height / max(width, 1),
})
return pd.DataFrame(rows)
Contract#
Read from
objmapand image data (gray,rgb)Return a
pd.DataFramewith one row per objectInclude an
ObjectLabelcolumn matchingobjmaplabelsDo not modify the image