flood_func(im, func, labels=None)[source]#

Flood each isolated region in an image with a constant value calculated by the given function.

  • im (ndarray) – An image with the numerical values of interest in each voxel, and 0’s elsewhere.

  • func (Numpy function handle) – The function to be applied to each region in the image. Any Numpy function that returns a scalar value can be passed, such as amin, amax, sum, mean, median, etc.

  • labels (ndarray) – An array containing labels identifying each individual region to be flooded. If not provided then scipy.ndimage.label is applied to im > 0.


flooded – An image the same size as im with each isolated region flooded with a constant value based on the given func and the values in im.

Return type:


See also

flood, region_size


Many of the functions in scipy.ndimage can be applied to individual regions using the index argument. This function extends that behavior to all numpy function, in the event you wanted to compute the cosine of the values in each region for some reason. This function also floods the original image instead of returning a list of values for each region.


Click here to view online example.