Here is a complete example that does exactly what you need (computes histogram for each region of a volume defined by a segment). It use Mask volume effect of SegmentEditorExtraEffects extension, so you need to install that extension.
Here is a complete example that does exactly what you need (computes histogram for each region of a volume defined by a segment). It use Mask volume effect of SegmentEditorExtraEffects extension, so you need to install that extension.