hnccorr.seeds module

Seed related components of HNCcorr.

class hnccorr.seeds.LocalCorrelationSeeder(neighborhood_size, keep_fraction, padding, grid_size)[source]

Bases: object

Provide seeds based on the correlation of pixels to their local neighborhood.

Seed pixels are selected based on the average correlation of the pixel to its local neighborhood.For each block of grid_size by grid_size pixels, the pixel with the highest average local correlation is selected. The remaining pixels in each block are discarded. From the remaining pixels, a fraction of _seed_fraction pixels, those with the highest average local correlation, are kept and attempted for segmentation.

The local neighborhood of each pixel consist of the pixels in a square of width _neighborhood_size centered on the pixels. Pixel coordinates outside the boundary of the movie are ignored.

Variables
  • _current_index (int) – Index of next seed in _seeds to return.

  • _excluded_pixels (set) – Set of pixel coordinates to excluded as future seeds.

  • _grid_size (int) – Number of pixels per dimension in a block.

  • _keep_fraction (float) – Percentage of candidate seed pixels to attempt for segmentation. All other candidate seed pixels are discarded.

  • _movie (Movie) – Movie to segment.

  • _neighborhood_size (int) – Width in pixels of the local neighborhood of a pixel.

  • _padding (int) – L-infinity distance for determining which pixels should be padded to the exclusion set in exclude_pixels().

  • _seeds (list[tuple]) – List of candidate seed coordinates to return.

__init__(neighborhood_size, keep_fraction, padding, grid_size)[source]

Initializes a LocalCorrelationSeeder object.

_compute_average_local_correlation(pixel, valid_neighbors)[source]

Compute average correlation between pixel and neighbors.

_select_best_per_grid_block(scores)[source]

Selects pixel with highest score in a block of grid_size pixels per dim.

exclude_pixels(pixels)[source]

Excludes pixels from being returned by next() method.

All pixels within in the set pixels as well as pixels that are within an L- infinity distance of _padding from any excluded pixel are excluded as seeds.

Method enables exclusion of pixels in previously segmented cells from serving as new seeds. This may help to prevent repeated segmentation of the cell.

Parameters

pixels (set) – Set of pixel coordinates to exclude.

Returns

None

next()[source]

Provides next seed pixel for segmentation.

Returns the movie coordinates of the next available seed pixel for segmentation. Seed pixels that have previously been excluded will be ignored. Returns None when all seeds are exhausted.

Returns

Coordinates of next seed pixel. None if no seeds remaining.

Return type

tuple or None

reset()[source]

Reinitialize the sequence of seed pixels and empties _excluded_seeds.

select_seeds(movie)[source]

Identifies candidate seeds in movie.

Initializes list of candidate seeds in the movie. See class description for details. Seeds can be accessed via the next() method.

Parameters

movie (Movie) – Movie object to segment.

Returns

None

class hnccorr.seeds.NegativeSeedSelector(radius, count)[source]

Bases: object

Selects negative seed pixels uniformly from a circle around center seed pixel.

Selects _count pixels from a circle centered on the center seed pixel with radius _radius. The selected pixels are spread uniformly over the circle. Non-integer pixel indices are rounded to the closest (integer) pixel. Currently only 2-dimensional movies are supported.

Variables
  • _radius (float) – L2 distance to center seed.

  • _count (int) – Number of negative seed pixels to select.

select(center_seed, movie)[source]

Selects negative seed pixels.

Parameters
  • center_seed (tuple) – Center seed pixels.

  • movie (Movie) – Movie for segmentation.

Returns

Set of negative seed pixels. Each pixel is denoted by a tuple.

Return type

set

class hnccorr.seeds.PositiveSeedSelector(max_distance)[source]

Bases: object

Selects positive seed pixels in a square centered on center_seed.

Selects all pixels in a square centered on center_seed as positive seeds. A pixel is selected if it is within a Chebyshev distance (L-Inf) of _max_distance from the center seed pixel.

Variables

_max_distance (int) – Maximum L-Inf distance allowed.

select(center_seed, movie)[source]

Selects positive seeds.

Parameters
  • center_seed (tuple) – Center seed pixel.

  • movie (Movie) – Movie for segmentation.

Returns

Set of positive seed pixels. Each pixel is denoted by a tuple.

Return type

set