def identify_misfeatured_regions(st, filter_size=<NUM_LIT:5>, sigma_cutoff=<NUM_LIT>):
<EOL>r = st.residuals<EOL>weights = np.ones([filter_size]*len(r.shape), dtype='<STR_LIT:float>')<EOL>weights /= weights.sum()<EOL>f = np.sqrt(nd.filters.convolve(r*r, weights, mode='<STR_LIT>'))<EOL>if sigma_cutoff == '<STR_LIT>':<EOL><INDENT>max_ok = initializers.otsu_threshold(f)<EOL><DEDENT>else:<EOL><INDENT>max_ok = f.mean() + sigma_cutoff * f.std()<EOL><DEDENT>bad = f > max_ok<EOL>labels, n = nd.measurements.label(bad)<EOL>inds = []<EOL>for i in range(<NUM_LIT:1>, n+<NUM_LIT:1>):<EOL><INDENT>inds.append(np.nonzero(labels == i))<EOL><DEDENT>tiles = [Tile(np.min(ind, axis=<NUM_LIT:1>), np.max(ind, axis=<NUM_LIT:1>)+<NUM_LIT:1>) for ind in inds]<EOL>volumes = [t.volume for t in tiles]<EOL>return [tiles[i] for i in np.argsort(volumes)[::-<NUM_LIT:1>]]<EOL>
Identifies regions of missing/misfeatured particles based on the
residuals' local deviation from uniform Gaussian noise.

Parameters
----------
st : :class:`peri.states.State`
    The state in which to identify mis-featured regions.

filter_size : Int, best if odd.
    The size of the filter for calculating the local standard deviation;
    should approximately be the size of a poorly featured region in
    each dimension. Default is 5.

sigma_cutoff : Float or `otsu`, optional
    The max allowed deviation of the residuals from what is expected,
    in units of the residuals' standard deviation. Lower means more
    sensitive, higher = less sensitive. Default is 8.0, i.e. one pixel
    out of every 7*10^11 is mis-identified randomly. In practice the
    noise is not Gaussian so there are still some regions mis-identified
    as improperly featured. Set to ```otsu``` to calculate this number
    based on an automatic Otsu threshold.

Returns
-------
tiles : List of :class:`peri.util.Tile`
    Each tile is the smallest bounding tile that contains an improperly
    featured region. The list is sorted by the tile's volume.

Notes
-----
Algorithm is
1.  Create a field of the local standard deviation, as measured over
    a hypercube of size filter_size.
2.  Find the maximum reasonable value of the field. [The field should
    be a random variable with mean of r.std() and standard deviation
    of ~r.std() / sqrt(N), where r is the residuals and N is the
    number of pixels in the hypercube.]
3.  Label & Identify the misfeatured regions as portions where
    the local error is too large.
4.  Parse the misfeatured regions into tiles.
5.  Return the sorted tiles.
The Otsu option to calculate the sigma cutoff works well for images
that actually contain missing particles, returning a number similar
to one calculated with a sigma cutoff. However, if the image is
well-featured with Gaussian residuals, then the Otsu threshold
splits the Gaussian down the middle instead of at the tails, which
is very bad. So use with caution.