repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_code_tokens
listlengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
listlengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
CellProfiler/centrosome
centrosome/cpmorphology.py
find_neighbors
def find_neighbors(labels): '''Find the set of objects that touch each object in a labels matrix Construct a "list", per-object, of the objects 8-connected adjacent to that object. Returns three 1-d arrays: * array of #'s of neighbors per object * array of indexes per object to that object'...
python
def find_neighbors(labels): '''Find the set of objects that touch each object in a labels matrix Construct a "list", per-object, of the objects 8-connected adjacent to that object. Returns three 1-d arrays: * array of #'s of neighbors per object * array of indexes per object to that object'...
[ "def", "find_neighbors", "(", "labels", ")", ":", "max_label", "=", "np", ".", "max", "(", "labels", ")", "# Make a labels matrix with zeros around the edges so we can do index", "# offsets without worrying.", "#", "new_labels", "=", "np", ".", "zeros", "(", "np", "."...
Find the set of objects that touch each object in a labels matrix Construct a "list", per-object, of the objects 8-connected adjacent to that object. Returns three 1-d arrays: * array of #'s of neighbors per object * array of indexes per object to that object's list of neighbors * array hol...
[ "Find", "the", "set", "of", "objects", "that", "touch", "each", "object", "in", "a", "labels", "matrix", "Construct", "a", "list", "per", "-", "object", "of", "the", "objects", "8", "-", "connected", "adjacent", "to", "that", "object", ".", "Returns", "t...
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L3507-L3581
CellProfiler/centrosome
centrosome/cpmorphology.py
distance_color_labels
def distance_color_labels(labels): '''Recolor a labels matrix so that adjacent labels have distant numbers ''' # # Color labels so adjacent ones are most distant # colors = color_labels(labels, True) # # Order pixels by color, then label # # rlabels = labels.ravel() orde...
python
def distance_color_labels(labels): '''Recolor a labels matrix so that adjacent labels have distant numbers ''' # # Color labels so adjacent ones are most distant # colors = color_labels(labels, True) # # Order pixels by color, then label # # rlabels = labels.ravel() orde...
[ "def", "distance_color_labels", "(", "labels", ")", ":", "#", "# Color labels so adjacent ones are most distant", "#", "colors", "=", "color_labels", "(", "labels", ",", "True", ")", "#", "# Order pixels by color, then label #", "#", "rlabels", "=", "labels", ".", "ra...
Recolor a labels matrix so that adjacent labels have distant numbers
[ "Recolor", "a", "labels", "matrix", "so", "that", "adjacent", "labels", "have", "distant", "numbers" ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L3583-L3607
CellProfiler/centrosome
centrosome/cpmorphology.py
color_labels
def color_labels(labels, distance_transform = False): '''Color a labels matrix so that no adjacent labels have the same color distance_transform - if true, distance transform the labels to find out which objects are closest to each other. Create a label coloring matrix which assigns ...
python
def color_labels(labels, distance_transform = False): '''Color a labels matrix so that no adjacent labels have the same color distance_transform - if true, distance transform the labels to find out which objects are closest to each other. Create a label coloring matrix which assigns ...
[ "def", "color_labels", "(", "labels", ",", "distance_transform", "=", "False", ")", ":", "if", "distance_transform", ":", "i", ",", "j", "=", "scind", ".", "distance_transform_edt", "(", "labels", "==", "0", ",", "return_distances", "=", "False", ",", "retur...
Color a labels matrix so that no adjacent labels have the same color distance_transform - if true, distance transform the labels to find out which objects are closest to each other. Create a label coloring matrix which assigns a color (1-n) to each pixel in the labels matrix such tha...
[ "Color", "a", "labels", "matrix", "so", "that", "no", "adjacent", "labels", "have", "the", "same", "color", "distance_transform", "-", "if", "true", "distance", "transform", "the", "labels", "to", "find", "out", "which", "objects", "are", "closest", "to", "e...
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L3609-L3679
CellProfiler/centrosome
centrosome/cpmorphology.py
skeletonize
def skeletonize(image, mask=None, ordering = None): '''Skeletonize the image Take the distance transform. Order the 1 points by the distance transform. Remove a point if it has more than 1 neighbor and if removing it does not change the Euler number. image - the binary image to be skel...
python
def skeletonize(image, mask=None, ordering = None): '''Skeletonize the image Take the distance transform. Order the 1 points by the distance transform. Remove a point if it has more than 1 neighbor and if removing it does not change the Euler number. image - the binary image to be skel...
[ "def", "skeletonize", "(", "image", ",", "mask", "=", "None", ",", "ordering", "=", "None", ")", ":", "global", "eight_connect", "if", "mask", "is", "None", ":", "masked_image", "=", "image", "else", ":", "masked_image", "=", "image", ".", "astype", "(",...
Skeletonize the image Take the distance transform. Order the 1 points by the distance transform. Remove a point if it has more than 1 neighbor and if removing it does not change the Euler number. image - the binary image to be skeletonized mask - only skeletonize pixels within the...
[ "Skeletonize", "the", "image", "Take", "the", "distance", "transform", ".", "Order", "the", "1", "points", "by", "the", "distance", "transform", ".", "Remove", "a", "point", "if", "it", "has", "more", "than", "1", "neighbor", "and", "if", "removing", "it",...
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L3681-L3753
CellProfiler/centrosome
centrosome/cpmorphology.py
skeletonize_labels
def skeletonize_labels(labels): '''Skeletonize a labels matrix''' # # The trick here is to separate touching labels by coloring the # labels matrix and then processing each color separately # colors = color_labels(labels) max_color = np.max(colors) if max_color == 0: return label...
python
def skeletonize_labels(labels): '''Skeletonize a labels matrix''' # # The trick here is to separate touching labels by coloring the # labels matrix and then processing each color separately # colors = color_labels(labels) max_color = np.max(colors) if max_color == 0: return label...
[ "def", "skeletonize_labels", "(", "labels", ")", ":", "#", "# The trick here is to separate touching labels by coloring the", "# labels matrix and then processing each color separately", "#", "colors", "=", "color_labels", "(", "labels", ")", "max_color", "=", "np", ".", "max...
Skeletonize a labels matrix
[ "Skeletonize", "a", "labels", "matrix" ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L3755-L3769
CellProfiler/centrosome
centrosome/cpmorphology.py
label_skeleton
def label_skeleton(skeleton): '''Label a skeleton so that each edge has a unique label This operation produces a labels matrix where each edge between two branchpoints has a different label. If the skeleton has been properly eroded, there are three kinds of points: 1) point adjacent to 0 or 1 o...
python
def label_skeleton(skeleton): '''Label a skeleton so that each edge has a unique label This operation produces a labels matrix where each edge between two branchpoints has a different label. If the skeleton has been properly eroded, there are three kinds of points: 1) point adjacent to 0 or 1 o...
[ "def", "label_skeleton", "(", "skeleton", ")", ":", "bpts", "=", "branchpoints", "(", "skeleton", ")", "#", "# Count the # of neighbors per point", "#", "neighbors", "=", "scind", ".", "convolve", "(", "skeleton", ".", "astype", "(", "int", ")", ",", "np", "...
Label a skeleton so that each edge has a unique label This operation produces a labels matrix where each edge between two branchpoints has a different label. If the skeleton has been properly eroded, there are three kinds of points: 1) point adjacent to 0 or 1 other points = end of edge 2) poin...
[ "Label", "a", "skeleton", "so", "that", "each", "edge", "has", "a", "unique", "label", "This", "operation", "produces", "a", "labels", "matrix", "where", "each", "edge", "between", "two", "branchpoints", "has", "a", "different", "label", ".", "If", "the", ...
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L3771-L3849
CellProfiler/centrosome
centrosome/cpmorphology.py
skeleton_length
def skeleton_length(labels, indices=None): '''Compute the length of all skeleton branches for labeled skeletons labels - a labels matrix indices - the indexes of the labels to be measured. Default is all returns an array of one skeleton length per label. ''' global __skel_length_table ...
python
def skeleton_length(labels, indices=None): '''Compute the length of all skeleton branches for labeled skeletons labels - a labels matrix indices - the indexes of the labels to be measured. Default is all returns an array of one skeleton length per label. ''' global __skel_length_table ...
[ "def", "skeleton_length", "(", "labels", ",", "indices", "=", "None", ")", ":", "global", "__skel_length_table", "if", "__skel_length_table", "is", "None", ":", "tbl", "=", "np", ".", "zeros", "(", "512", ",", "np", ".", "float32", ")", "for", "ii", "in"...
Compute the length of all skeleton branches for labeled skeletons labels - a labels matrix indices - the indexes of the labels to be measured. Default is all returns an array of one skeleton length per label.
[ "Compute", "the", "length", "of", "all", "skeleton", "branches", "for", "labeled", "skeletons", "labels", "-", "a", "labels", "matrix", "indices", "-", "the", "indexes", "of", "the", "labels", "to", "be", "measured", ".", "Default", "is", "all", "returns", ...
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L3853-L3903
CellProfiler/centrosome
centrosome/cpmorphology.py
distance_to_edge
def distance_to_edge(labels): '''Compute the distance of a pixel to the edge of its object labels - a labels matrix returns a matrix of distances ''' colors = color_labels(labels) max_color = np.max(colors) result = np.zeros(labels.shape) if max_color == 0: return resul...
python
def distance_to_edge(labels): '''Compute the distance of a pixel to the edge of its object labels - a labels matrix returns a matrix of distances ''' colors = color_labels(labels) max_color = np.max(colors) result = np.zeros(labels.shape) if max_color == 0: return resul...
[ "def", "distance_to_edge", "(", "labels", ")", ":", "colors", "=", "color_labels", "(", "labels", ")", "max_color", "=", "np", ".", "max", "(", "colors", ")", "result", "=", "np", ".", "zeros", "(", "labels", ".", "shape", ")", "if", "max_color", "==",...
Compute the distance of a pixel to the edge of its object labels - a labels matrix returns a matrix of distances
[ "Compute", "the", "distance", "of", "a", "pixel", "to", "the", "edge", "of", "its", "object", "labels", "-", "a", "labels", "matrix", "returns", "a", "matrix", "of", "distances" ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L3905-L3921
CellProfiler/centrosome
centrosome/cpmorphology.py
regional_maximum
def regional_maximum(image, mask = None, structure=None, ties_are_ok=False): '''Return a binary mask containing only points that are regional maxima image - image to be transformed mask - mask of relevant pixels structure - binary structure giving the neighborhood and connectivity ...
python
def regional_maximum(image, mask = None, structure=None, ties_are_ok=False): '''Return a binary mask containing only points that are regional maxima image - image to be transformed mask - mask of relevant pixels structure - binary structure giving the neighborhood and connectivity ...
[ "def", "regional_maximum", "(", "image", ",", "mask", "=", "None", ",", "structure", "=", "None", ",", "ties_are_ok", "=", "False", ")", ":", "global", "eight_connect", "if", "not", "ties_are_ok", ":", "#", "# Get an an initial pass with the ties.", "#", "result...
Return a binary mask containing only points that are regional maxima image - image to be transformed mask - mask of relevant pixels structure - binary structure giving the neighborhood and connectivity in which to search for maxima. Default is 8-connected. ties_are_ok - if ...
[ "Return", "a", "binary", "mask", "containing", "only", "points", "that", "are", "regional", "maxima", "image", "-", "image", "to", "be", "transformed", "mask", "-", "mask", "of", "relevant", "pixels", "structure", "-", "binary", "structure", "giving", "the", ...
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L3923-L4009
CellProfiler/centrosome
centrosome/cpmorphology.py
all_connected_components
def all_connected_components(i,j): '''Associate each label in i with a component # This function finds all connected components given an array of associations between labels i and j using a depth-first search. i & j give the edges of the graph. The first step of the algorithm makes bidirec...
python
def all_connected_components(i,j): '''Associate each label in i with a component # This function finds all connected components given an array of associations between labels i and j using a depth-first search. i & j give the edges of the graph. The first step of the algorithm makes bidirec...
[ "def", "all_connected_components", "(", "i", ",", "j", ")", ":", "if", "len", "(", "i", ")", "==", "0", ":", "return", "i", "i1", "=", "np", ".", "hstack", "(", "(", "i", ",", "j", ")", ")", "j1", "=", "np", ".", "hstack", "(", "(", "j", ",...
Associate each label in i with a component # This function finds all connected components given an array of associations between labels i and j using a depth-first search. i & j give the edges of the graph. The first step of the algorithm makes bidirectional edges, (i->j and j<-i), so it's bes...
[ "Associate", "each", "label", "in", "i", "with", "a", "component", "#", "This", "function", "finds", "all", "connected", "components", "given", "an", "array", "of", "associations", "between", "labels", "i", "and", "j", "using", "a", "depth", "-", "first", ...
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L4011-L4041
CellProfiler/centrosome
centrosome/cpmorphology.py
pairwise_permutations
def pairwise_permutations(i, j): '''Return all permutations of a set of groups This routine takes two vectors: i - the label of each group j - the members of the group. For instance, take a set of two groups with several members each: i | j ------ 1 | 1 1 | 2 1 | 3...
python
def pairwise_permutations(i, j): '''Return all permutations of a set of groups This routine takes two vectors: i - the label of each group j - the members of the group. For instance, take a set of two groups with several members each: i | j ------ 1 | 1 1 | 2 1 | 3...
[ "def", "pairwise_permutations", "(", "i", ",", "j", ")", ":", "if", "len", "(", "i", ")", "==", "0", ":", "return", "(", "np", ".", "array", "(", "[", "]", ",", "int", ")", ",", "np", ".", "array", "(", "[", "]", ",", "j", ".", "dtype", ")"...
Return all permutations of a set of groups This routine takes two vectors: i - the label of each group j - the members of the group. For instance, take a set of two groups with several members each: i | j ------ 1 | 1 1 | 2 1 | 3 2 | 1 2 | 4 2 | 5 2 | 6...
[ "Return", "all", "permutations", "of", "a", "set", "of", "groups", "This", "routine", "takes", "two", "vectors", ":", "i", "-", "the", "label", "of", "each", "group", "j", "-", "the", "members", "of", "the", "group", ".", "For", "instance", "take", "a"...
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L4043-L4186
CellProfiler/centrosome
centrosome/cpmorphology.py
is_local_maximum
def is_local_maximum(image, labels, footprint): '''Return a boolean array of points that are local maxima image - intensity image labels - find maxima only within labels. Zero is reserved for background. footprint - binary mask indicating the neighborhood to be examined must be a ma...
python
def is_local_maximum(image, labels, footprint): '''Return a boolean array of points that are local maxima image - intensity image labels - find maxima only within labels. Zero is reserved for background. footprint - binary mask indicating the neighborhood to be examined must be a ma...
[ "def", "is_local_maximum", "(", "image", ",", "labels", ",", "footprint", ")", ":", "assert", "(", "(", "np", ".", "all", "(", "footprint", ".", "shape", ")", "&", "1", ")", "==", "1", ")", "footprint", "=", "(", "footprint", "!=", "0", ")", "footp...
Return a boolean array of points that are local maxima image - intensity image labels - find maxima only within labels. Zero is reserved for background. footprint - binary mask indicating the neighborhood to be examined must be a matrix with odd dimensions, center is taken to ...
[ "Return", "a", "boolean", "array", "of", "points", "that", "are", "local", "maxima", "image", "-", "intensity", "image", "labels", "-", "find", "maxima", "only", "within", "labels", ".", "Zero", "is", "reserved", "for", "background", ".", "footprint", "-", ...
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L4188-L4260
CellProfiler/centrosome
centrosome/cpmorphology.py
angular_distribution
def angular_distribution(labels, resolution=100, weights=None): '''For each object in labels, compute the angular distribution around the centers of mass. Returns an i x j matrix, where i is the number of objects in the label matrix, and j is the resolution of the distribution (default 100), mapped fro...
python
def angular_distribution(labels, resolution=100, weights=None): '''For each object in labels, compute the angular distribution around the centers of mass. Returns an i x j matrix, where i is the number of objects in the label matrix, and j is the resolution of the distribution (default 100), mapped fro...
[ "def", "angular_distribution", "(", "labels", ",", "resolution", "=", "100", ",", "weights", "=", "None", ")", ":", "if", "weights", "is", "None", ":", "weights", "=", "np", ".", "ones", "(", "labels", ".", "shape", ")", "maxlabel", "=", "labels", ".",...
For each object in labels, compute the angular distribution around the centers of mass. Returns an i x j matrix, where i is the number of objects in the label matrix, and j is the resolution of the distribution (default 100), mapped from -pi to pi. Optionally, the distributions can be weighted by pixe...
[ "For", "each", "object", "in", "labels", "compute", "the", "angular", "distribution", "around", "the", "centers", "of", "mass", ".", "Returns", "an", "i", "x", "j", "matrix", "where", "i", "is", "the", "number", "of", "objects", "in", "the", "label", "ma...
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L4262-L4306
CellProfiler/centrosome
centrosome/cpmorphology.py
feret_diameter
def feret_diameter(chulls, counts, indexes): '''Return the minimum and maximum Feret diameter for each object This function takes the convex hull data, as generated by convex_hull and returns the minimum and maximum Feret diameter for each convex hull. chulls - an n x 3 matrix giving the la...
python
def feret_diameter(chulls, counts, indexes): '''Return the minimum and maximum Feret diameter for each object This function takes the convex hull data, as generated by convex_hull and returns the minimum and maximum Feret diameter for each convex hull. chulls - an n x 3 matrix giving the la...
[ "def", "feret_diameter", "(", "chulls", ",", "counts", ",", "indexes", ")", ":", "#", "# Method taken from Alsuwaiyel, \"Algorithms, Design Techniques and", "# Analysis\", World Scientific, 2003", "#", "# Given a vertex, p1 on the convex hull composed of points p1 to pm,", "# there is ...
Return the minimum and maximum Feret diameter for each object This function takes the convex hull data, as generated by convex_hull and returns the minimum and maximum Feret diameter for each convex hull. chulls - an n x 3 matrix giving the label #, the i coordinate and the j co...
[ "Return", "the", "minimum", "and", "maximum", "Feret", "diameter", "for", "each", "object", "This", "function", "takes", "the", "convex", "hull", "data", "as", "generated", "by", "convex_hull", "and", "returns", "the", "minimum", "and", "maximum", "Feret", "di...
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L4308-L4506
CellProfiler/centrosome
centrosome/cpmorphology.py
is_obtuse
def is_obtuse(p1, v, p2): '''Determine whether the angle, p1 - v - p2 is obtuse p1 - N x 2 array of coordinates of first point on edge v - N x 2 array of vertex coordinates p2 - N x 2 array of coordinates of second point on edge returns vector of booleans ''' p1x = p1[:,1] p1y ...
python
def is_obtuse(p1, v, p2): '''Determine whether the angle, p1 - v - p2 is obtuse p1 - N x 2 array of coordinates of first point on edge v - N x 2 array of vertex coordinates p2 - N x 2 array of coordinates of second point on edge returns vector of booleans ''' p1x = p1[:,1] p1y ...
[ "def", "is_obtuse", "(", "p1", ",", "v", ",", "p2", ")", ":", "p1x", "=", "p1", "[", ":", ",", "1", "]", "p1y", "=", "p1", "[", ":", ",", "0", "]", "p2x", "=", "p2", "[", ":", ",", "1", "]", "p2y", "=", "p2", "[", ":", ",", "0", "]", ...
Determine whether the angle, p1 - v - p2 is obtuse p1 - N x 2 array of coordinates of first point on edge v - N x 2 array of vertex coordinates p2 - N x 2 array of coordinates of second point on edge returns vector of booleans
[ "Determine", "whether", "the", "angle", "p1", "-", "v", "-", "p2", "is", "obtuse", "p1", "-", "N", "x", "2", "array", "of", "coordinates", "of", "first", "point", "on", "edge", "v", "-", "N", "x", "2", "array", "of", "vertex", "coordinates", "p2", ...
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L4508-L4527
CellProfiler/centrosome
centrosome/cpmorphology.py
get_outline_pts
def get_outline_pts(labels, idxs): '''Get the outline points of objects in clockwise order Given a labels matrix of contiguously-labeled objects, trace the exteriors of those objects to get the points of the outline in clockwise order. labels - a labels matrix idxs - return points...
python
def get_outline_pts(labels, idxs): '''Get the outline points of objects in clockwise order Given a labels matrix of contiguously-labeled objects, trace the exteriors of those objects to get the points of the outline in clockwise order. labels - a labels matrix idxs - return points...
[ "def", "get_outline_pts", "(", "labels", ",", "idxs", ")", ":", "idxs", "=", "np", ".", "atleast_1d", "(", "idxs", ")", "if", "len", "(", "idxs", ")", "==", "0", ":", "return", "np", ".", "zeros", "(", "(", "0", ",", "2", ")", ",", "int", ")", ...
Get the outline points of objects in clockwise order Given a labels matrix of contiguously-labeled objects, trace the exteriors of those objects to get the points of the outline in clockwise order. labels - a labels matrix idxs - return points for the labels named by this array ...
[ "Get", "the", "outline", "points", "of", "objects", "in", "clockwise", "order", "Given", "a", "labels", "matrix", "of", "contiguously", "-", "labeled", "objects", "trace", "the", "exteriors", "of", "those", "objects", "to", "get", "the", "points", "of", "the...
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L4553-L4693
CellProfiler/centrosome
centrosome/princomp.py
princomp
def princomp(x): """Determine the principal components of a vector of measurements Determine the principal components of a vector of measurements x should be a M x N numpy array composed of M observations of n variables The output is: coeffs - the NxN correlation matrix that can be used to tran...
python
def princomp(x): """Determine the principal components of a vector of measurements Determine the principal components of a vector of measurements x should be a M x N numpy array composed of M observations of n variables The output is: coeffs - the NxN correlation matrix that can be used to tran...
[ "def", "princomp", "(", "x", ")", ":", "(", "M", ",", "N", ")", "=", "x", ".", "shape", "Mean", "=", "x", ".", "mean", "(", "0", ")", "y", "=", "x", "-", "Mean", "cov", "=", "numpy", ".", "dot", "(", "y", ".", "transpose", "(", ")", ",", ...
Determine the principal components of a vector of measurements Determine the principal components of a vector of measurements x should be a M x N numpy array composed of M observations of n variables The output is: coeffs - the NxN correlation matrix that can be used to transform x into its compone...
[ "Determine", "the", "principal", "components", "of", "a", "vector", "of", "measurements", "Determine", "the", "principal", "components", "of", "a", "vector", "of", "measurements", "x", "should", "be", "a", "M", "x", "N", "numpy", "array", "composed", "of", "...
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/princomp.py#L4-L24
CellProfiler/centrosome
centrosome/index.py
all_pairs
def all_pairs(n): '''Return an (n*(n - 1)) x 2 array of all non-identity pairs of n things n - # of things The array is (cleverly) ordered so that the first m * (m - 1) elements can be used for m < n things: n = 3 [[0, 1], # n = 2 [1, 0], # n = 2 [0, 2], [1, 2], ...
python
def all_pairs(n): '''Return an (n*(n - 1)) x 2 array of all non-identity pairs of n things n - # of things The array is (cleverly) ordered so that the first m * (m - 1) elements can be used for m < n things: n = 3 [[0, 1], # n = 2 [1, 0], # n = 2 [0, 2], [1, 2], ...
[ "def", "all_pairs", "(", "n", ")", ":", "# Get all against all", "i", ",", "j", "=", "[", "x", ".", "flatten", "(", ")", "for", "x", "in", "np", ".", "mgrid", "[", "0", ":", "n", ",", "0", ":", "n", "]", "]", "# Eliminate the diagonal of i == j", "...
Return an (n*(n - 1)) x 2 array of all non-identity pairs of n things n - # of things The array is (cleverly) ordered so that the first m * (m - 1) elements can be used for m < n things: n = 3 [[0, 1], # n = 2 [1, 0], # n = 2 [0, 2], [1, 2], [2, 0], [2, 1]]
[ "Return", "an", "(", "n", "*", "(", "n", "-", "1", "))", "x", "2", "array", "of", "all", "non", "-", "identity", "pairs", "of", "n", "things", "n", "-", "#", "of", "things", "The", "array", "is", "(", "cleverly", ")", "ordered", "so", "that", "...
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/index.py#L116-L138
CellProfiler/centrosome
centrosome/filter.py
stretch
def stretch(image, mask=None): '''Normalize an image to make the minimum zero and maximum one image - pixel data to be normalized mask - optional mask of relevant pixels. None = don't mask returns the stretched image ''' image = np.array(image, float) if np.product(image.shape) == 0: ...
python
def stretch(image, mask=None): '''Normalize an image to make the minimum zero and maximum one image - pixel data to be normalized mask - optional mask of relevant pixels. None = don't mask returns the stretched image ''' image = np.array(image, float) if np.product(image.shape) == 0: ...
[ "def", "stretch", "(", "image", ",", "mask", "=", "None", ")", ":", "image", "=", "np", ".", "array", "(", "image", ",", "float", ")", "if", "np", ".", "product", "(", "image", ".", "shape", ")", "==", "0", ":", "return", "image", "if", "mask", ...
Normalize an image to make the minimum zero and maximum one image - pixel data to be normalized mask - optional mask of relevant pixels. None = don't mask returns the stretched image
[ "Normalize", "an", "image", "to", "make", "the", "minimum", "zero", "and", "maximum", "one" ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/filter.py#L22-L57
CellProfiler/centrosome
centrosome/filter.py
median_filter
def median_filter(data, mask, radius, percent=50): '''Masked median filter with octagonal shape data - array of data to be median filtered. mask - mask of significant pixels in data radius - the radius of a circle inscribed into the filtering octagon percent - conceptually, order the significant pi...
python
def median_filter(data, mask, radius, percent=50): '''Masked median filter with octagonal shape data - array of data to be median filtered. mask - mask of significant pixels in data radius - the radius of a circle inscribed into the filtering octagon percent - conceptually, order the significant pi...
[ "def", "median_filter", "(", "data", ",", "mask", ",", "radius", ",", "percent", "=", "50", ")", ":", "if", "mask", "is", "None", ":", "mask", "=", "np", ".", "ones", "(", "data", ".", "shape", ",", "dtype", "=", "bool", ")", "if", "np", ".", "...
Masked median filter with octagonal shape data - array of data to be median filtered. mask - mask of significant pixels in data radius - the radius of a circle inscribed into the filtering octagon percent - conceptually, order the significant pixels in the octagon, count them and choose t...
[ "Masked", "median", "filter", "with", "octagonal", "shape" ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/filter.py#L68-L107
CellProfiler/centrosome
centrosome/filter.py
bilateral_filter
def bilateral_filter(image, mask, sigma_spatial, sigma_range, sampling_spatial = None, sampling_range = None): """Bilateral filter of an image image - image to be bilaterally filtered mask - mask of significant points in image sigma_spatial - standard deviation of the spatial Gaus...
python
def bilateral_filter(image, mask, sigma_spatial, sigma_range, sampling_spatial = None, sampling_range = None): """Bilateral filter of an image image - image to be bilaterally filtered mask - mask of significant points in image sigma_spatial - standard deviation of the spatial Gaus...
[ "def", "bilateral_filter", "(", "image", ",", "mask", ",", "sigma_spatial", ",", "sigma_range", ",", "sampling_spatial", "=", "None", ",", "sampling_range", "=", "None", ")", ":", "# The algorithm is taken largely from code by Jiawen Chen which miraculously", "# extends to ...
Bilateral filter of an image image - image to be bilaterally filtered mask - mask of significant points in image sigma_spatial - standard deviation of the spatial Gaussian sigma_range - standard deviation of the range Gaussian sampling_spatial - amt to reduce image array extents when sampling ...
[ "Bilateral", "filter", "of", "an", "image" ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/filter.py#L116-L250
CellProfiler/centrosome
centrosome/filter.py
laplacian_of_gaussian
def laplacian_of_gaussian(image, mask, size, sigma): '''Perform the Laplacian of Gaussian transform on the image image - 2-d image array mask - binary mask of significant pixels size - length of side of square kernel to use sigma - standard deviation of the Gaussian ''' half_size = size//...
python
def laplacian_of_gaussian(image, mask, size, sigma): '''Perform the Laplacian of Gaussian transform on the image image - 2-d image array mask - binary mask of significant pixels size - length of side of square kernel to use sigma - standard deviation of the Gaussian ''' half_size = size//...
[ "def", "laplacian_of_gaussian", "(", "image", ",", "mask", ",", "size", ",", "sigma", ")", ":", "half_size", "=", "size", "//", "2", "i", ",", "j", "=", "np", ".", "mgrid", "[", "-", "half_size", ":", "half_size", "+", "1", ",", "-", "half_size", "...
Perform the Laplacian of Gaussian transform on the image image - 2-d image array mask - binary mask of significant pixels size - length of side of square kernel to use sigma - standard deviation of the Gaussian
[ "Perform", "the", "Laplacian", "of", "Gaussian", "transform", "on", "the", "image" ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/filter.py#L252-L291
CellProfiler/centrosome
centrosome/filter.py
canny
def canny(image, mask, sigma, low_threshold, high_threshold): '''Edge filter an image using the Canny algorithm. sigma - the standard deviation of the Gaussian used low_threshold - threshold for edges that connect to high-threshold edges high_threshold - threshold of a high-threshol...
python
def canny(image, mask, sigma, low_threshold, high_threshold): '''Edge filter an image using the Canny algorithm. sigma - the standard deviation of the Gaussian used low_threshold - threshold for edges that connect to high-threshold edges high_threshold - threshold of a high-threshol...
[ "def", "canny", "(", "image", ",", "mask", ",", "sigma", ",", "low_threshold", ",", "high_threshold", ")", ":", "#", "# The steps involved:", "#", "# * Smooth using the Gaussian with sigma above.", "#", "# * Apply the horizontal and vertical Sobel operators to get the gradients...
Edge filter an image using the Canny algorithm. sigma - the standard deviation of the Gaussian used low_threshold - threshold for edges that connect to high-threshold edges high_threshold - threshold of a high-threshold edge Canny, J., A Computational Approach To Edge Detection, IE...
[ "Edge", "filter", "an", "image", "using", "the", "Canny", "algorithm", "." ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/filter.py#L298-L461
CellProfiler/centrosome
centrosome/filter.py
roberts
def roberts(image, mask=None): '''Find edges using the Roberts algorithm image - the image to process mask - mask of relevant points The algorithm returns the magnitude of the output of the two Roberts convolution kernels. The following is the canonical citation for the algorithm: L. Rob...
python
def roberts(image, mask=None): '''Find edges using the Roberts algorithm image - the image to process mask - mask of relevant points The algorithm returns the magnitude of the output of the two Roberts convolution kernels. The following is the canonical citation for the algorithm: L. Rob...
[ "def", "roberts", "(", "image", ",", "mask", "=", "None", ")", ":", "result", "=", "np", ".", "zeros", "(", "image", ".", "shape", ")", "#", "# Four quadrants and two convolutions:", "#", "# q0,0 | q0,1 1 | 0 anti-diagonal", "# q1,0 | q1,1 0 | -1", "#", ...
Find edges using the Roberts algorithm image - the image to process mask - mask of relevant points The algorithm returns the magnitude of the output of the two Roberts convolution kernels. The following is the canonical citation for the algorithm: L. Roberts Machine Perception of 3-D Solids,...
[ "Find", "edges", "using", "the", "Roberts", "algorithm" ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/filter.py#L463-L504
CellProfiler/centrosome
centrosome/filter.py
sobel
def sobel(image, mask=None): '''Calculate the absolute magnitude Sobel to find the edges image - image to process mask - mask of relevant points Take the square root of the sum of the squares of the horizontal and vertical Sobels to get a magnitude that's somewhat insensitive to direction. ...
python
def sobel(image, mask=None): '''Calculate the absolute magnitude Sobel to find the edges image - image to process mask - mask of relevant points Take the square root of the sum of the squares of the horizontal and vertical Sobels to get a magnitude that's somewhat insensitive to direction. ...
[ "def", "sobel", "(", "image", ",", "mask", "=", "None", ")", ":", "return", "np", ".", "sqrt", "(", "hsobel", "(", "image", ",", "mask", ")", "**", "2", "+", "vsobel", "(", "image", ",", "mask", ")", "**", "2", ")" ]
Calculate the absolute magnitude Sobel to find the edges image - image to process mask - mask of relevant points Take the square root of the sum of the squares of the horizontal and vertical Sobels to get a magnitude that's somewhat insensitive to direction. Note that scipy's Sobel returns a ...
[ "Calculate", "the", "absolute", "magnitude", "Sobel", "to", "find", "the", "edges" ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/filter.py#L506-L519
CellProfiler/centrosome
centrosome/filter.py
prewitt
def prewitt(image, mask=None): '''Find the edge magnitude using the Prewitt transform image - image to process mask - mask of relevant points Return the square root of the sum of squares of the horizontal and vertical Prewitt transforms. ''' return np.sqrt(hprewitt(image,mask)**2 + vprewi...
python
def prewitt(image, mask=None): '''Find the edge magnitude using the Prewitt transform image - image to process mask - mask of relevant points Return the square root of the sum of squares of the horizontal and vertical Prewitt transforms. ''' return np.sqrt(hprewitt(image,mask)**2 + vprewi...
[ "def", "prewitt", "(", "image", ",", "mask", "=", "None", ")", ":", "return", "np", ".", "sqrt", "(", "hprewitt", "(", "image", ",", "mask", ")", "**", "2", "+", "vprewitt", "(", "image", ",", "mask", ")", "**", "2", ")" ]
Find the edge magnitude using the Prewitt transform image - image to process mask - mask of relevant points Return the square root of the sum of squares of the horizontal and vertical Prewitt transforms.
[ "Find", "the", "edge", "magnitude", "using", "the", "Prewitt", "transform" ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/filter.py#L567-L576
CellProfiler/centrosome
centrosome/filter.py
hprewitt
def hprewitt(image, mask=None): '''Find the horizontal edges of an image using the Prewitt transform image - image to process mask - mask of relevant points We use the following kernel and return the absolute value of the result at each point: 1 1 1 0 0 0 -1 -1 -1 ''' ...
python
def hprewitt(image, mask=None): '''Find the horizontal edges of an image using the Prewitt transform image - image to process mask - mask of relevant points We use the following kernel and return the absolute value of the result at each point: 1 1 1 0 0 0 -1 -1 -1 ''' ...
[ "def", "hprewitt", "(", "image", ",", "mask", "=", "None", ")", ":", "if", "mask", "is", "None", ":", "mask", "=", "np", ".", "ones", "(", "image", ".", "shape", ",", "bool", ")", "big_mask", "=", "binary_erosion", "(", "mask", ",", "generate_binary_...
Find the horizontal edges of an image using the Prewitt transform image - image to process mask - mask of relevant points We use the following kernel and return the absolute value of the result at each point: 1 1 1 0 0 0 -1 -1 -1
[ "Find", "the", "horizontal", "edges", "of", "an", "image", "using", "the", "Prewitt", "transform" ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/filter.py#L578-L599
CellProfiler/centrosome
centrosome/filter.py
gabor
def gabor(image, labels, frequency, theta): '''Gabor-filter the objects in an image image - 2-d grayscale image to filter labels - a similarly shaped labels matrix frequency - cycles per trip around the circle theta - angle of the filter. 0 to 2 pi Calculate the Gabor filter centered on the ce...
python
def gabor(image, labels, frequency, theta): '''Gabor-filter the objects in an image image - 2-d grayscale image to filter labels - a similarly shaped labels matrix frequency - cycles per trip around the circle theta - angle of the filter. 0 to 2 pi Calculate the Gabor filter centered on the ce...
[ "def", "gabor", "(", "image", ",", "labels", ",", "frequency", ",", "theta", ")", ":", "#", "# The code inscribes the X and Y position of each pixel relative to", "# the centroid of that pixel's object. After that, the Gabor filter", "# for the image can be calculated per-pixel and the...
Gabor-filter the objects in an image image - 2-d grayscale image to filter labels - a similarly shaped labels matrix frequency - cycles per trip around the circle theta - angle of the filter. 0 to 2 pi Calculate the Gabor filter centered on the centroids of each object in the image. Summing th...
[ "Gabor", "-", "filter", "the", "objects", "in", "an", "image" ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/filter.py#L624-L673
CellProfiler/centrosome
centrosome/filter.py
enhance_dark_holes
def enhance_dark_holes(image, min_radius, max_radius, mask=None): '''Enhance dark holes using a rolling ball filter image - grayscale 2-d image radii - a vector of radii: we enhance holes at each given radius ''' # # Do 4-connected erosion # se = np.array([[False, True, False], ...
python
def enhance_dark_holes(image, min_radius, max_radius, mask=None): '''Enhance dark holes using a rolling ball filter image - grayscale 2-d image radii - a vector of radii: we enhance holes at each given radius ''' # # Do 4-connected erosion # se = np.array([[False, True, False], ...
[ "def", "enhance_dark_holes", "(", "image", ",", "min_radius", ",", "max_radius", ",", "mask", "=", "None", ")", ":", "#", "# Do 4-connected erosion", "#", "se", "=", "np", ".", "array", "(", "[", "[", "False", ",", "True", ",", "False", "]", ",", "[", ...
Enhance dark holes using a rolling ball filter image - grayscale 2-d image radii - a vector of radii: we enhance holes at each given radius
[ "Enhance", "dark", "holes", "using", "a", "rolling", "ball", "filter" ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/filter.py#L675-L702
CellProfiler/centrosome
centrosome/filter.py
granulometry_filter
def granulometry_filter(image, min_radius, max_radius, mask=None): '''Enhances bright structures within a min and max radius using a rolling ball filter image - grayscale 2-d image radii - a vector of radii: we enhance holes at each given radius ''' # # Do 4-connected erosion # se = np....
python
def granulometry_filter(image, min_radius, max_radius, mask=None): '''Enhances bright structures within a min and max radius using a rolling ball filter image - grayscale 2-d image radii - a vector of radii: we enhance holes at each given radius ''' # # Do 4-connected erosion # se = np....
[ "def", "granulometry_filter", "(", "image", ",", "min_radius", ",", "max_radius", ",", "mask", "=", "None", ")", ":", "#", "# Do 4-connected erosion", "#", "se", "=", "np", ".", "array", "(", "[", "[", "False", ",", "True", ",", "False", "]", ",", "[",...
Enhances bright structures within a min and max radius using a rolling ball filter image - grayscale 2-d image radii - a vector of radii: we enhance holes at each given radius
[ "Enhances", "bright", "structures", "within", "a", "min", "and", "max", "radius", "using", "a", "rolling", "ball", "filter" ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/filter.py#L705-L734
CellProfiler/centrosome
centrosome/filter.py
circular_average_filter
def circular_average_filter(image, radius, mask=None): '''Blur an image using a circular averaging filter (pillbox) image - grayscale 2-d image radii - radius of filter in pixels The filter will be within a square matrix of side 2*radius+1 This code is translated straight from MATLAB's fspecial f...
python
def circular_average_filter(image, radius, mask=None): '''Blur an image using a circular averaging filter (pillbox) image - grayscale 2-d image radii - radius of filter in pixels The filter will be within a square matrix of side 2*radius+1 This code is translated straight from MATLAB's fspecial f...
[ "def", "circular_average_filter", "(", "image", ",", "radius", ",", "mask", "=", "None", ")", ":", "crad", "=", "int", "(", "np", ".", "ceil", "(", "radius", "-", "0.5", ")", ")", "x", ",", "y", "=", "np", ".", "mgrid", "[", "-", "crad", ":", "...
Blur an image using a circular averaging filter (pillbox) image - grayscale 2-d image radii - radius of filter in pixels The filter will be within a square matrix of side 2*radius+1 This code is translated straight from MATLAB's fspecial function
[ "Blur", "an", "image", "using", "a", "circular", "averaging", "filter", "(", "pillbox", ")" ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/filter.py#L736-L792
CellProfiler/centrosome
centrosome/filter.py
velocity_kalman_model
def velocity_kalman_model(): '''Return a KalmanState set up to model objects with constant velocity The observation and measurement vectors are i,j. The state vector is i,j,vi,vj ''' om = np.array([[1,0,0,0], [0, 1, 0, 0]]) tm = np.array([[1,0,1,0], [0,1,0,1], ...
python
def velocity_kalman_model(): '''Return a KalmanState set up to model objects with constant velocity The observation and measurement vectors are i,j. The state vector is i,j,vi,vj ''' om = np.array([[1,0,0,0], [0, 1, 0, 0]]) tm = np.array([[1,0,1,0], [0,1,0,1], ...
[ "def", "velocity_kalman_model", "(", ")", ":", "om", "=", "np", ".", "array", "(", "[", "[", "1", ",", "0", ",", "0", ",", "0", "]", ",", "[", "0", ",", "1", ",", "0", ",", "0", "]", "]", ")", "tm", "=", "np", ".", "array", "(", "[", "[...
Return a KalmanState set up to model objects with constant velocity The observation and measurement vectors are i,j. The state vector is i,j,vi,vj
[ "Return", "a", "KalmanState", "set", "up", "to", "model", "objects", "with", "constant", "velocity" ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/filter.py#L1010-L1021
CellProfiler/centrosome
centrosome/filter.py
reverse_velocity_kalman_model
def reverse_velocity_kalman_model(): '''Return a KalmanState set up to model going backwards in time''' om = np.array([[1,0,0,0], [0, 1, 0, 0]]) tm = np.array([[1,0,-1,0], [0,1,0,-1], [0,0,1,0], [0,0,0,1]]) return KalmanState(om, tm)
python
def reverse_velocity_kalman_model(): '''Return a KalmanState set up to model going backwards in time''' om = np.array([[1,0,0,0], [0, 1, 0, 0]]) tm = np.array([[1,0,-1,0], [0,1,0,-1], [0,0,1,0], [0,0,0,1]]) return KalmanState(om, tm)
[ "def", "reverse_velocity_kalman_model", "(", ")", ":", "om", "=", "np", ".", "array", "(", "[", "[", "1", ",", "0", ",", "0", ",", "0", "]", ",", "[", "0", ",", "1", ",", "0", ",", "0", "]", "]", ")", "tm", "=", "np", ".", "array", "(", "...
Return a KalmanState set up to model going backwards in time
[ "Return", "a", "KalmanState", "set", "up", "to", "model", "going", "backwards", "in", "time" ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/filter.py#L1023-L1030
CellProfiler/centrosome
centrosome/filter.py
kalman_filter
def kalman_filter(kalman_state, old_indices, coordinates, q, r): '''Return the kalman filter for the features in the new frame kalman_state - state from last frame old_indices - the index per feature in the last frame or -1 for new coordinates - Coordinates of the features in the new frame. q - ...
python
def kalman_filter(kalman_state, old_indices, coordinates, q, r): '''Return the kalman filter for the features in the new frame kalman_state - state from last frame old_indices - the index per feature in the last frame or -1 for new coordinates - Coordinates of the features in the new frame. q - ...
[ "def", "kalman_filter", "(", "kalman_state", ",", "old_indices", ",", "coordinates", ",", "q", ",", "r", ")", ":", "assert", "isinstance", "(", "kalman_state", ",", "KalmanState", ")", "old_indices", "=", "np", ".", "array", "(", "old_indices", ")", "if", ...
Return the kalman filter for the features in the new frame kalman_state - state from last frame old_indices - the index per feature in the last frame or -1 for new coordinates - Coordinates of the features in the new frame. q - the process error covariance - see equ 1.3 and 1.10 from Welch r - ...
[ "Return", "the", "kalman", "filter", "for", "the", "features", "in", "the", "new", "frame" ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/filter.py#L1039-L1171
CellProfiler/centrosome
centrosome/filter.py
line_integration
def line_integration(image, angle, decay, sigma): '''Integrate the image along the given angle DIC images are the directional derivative of the underlying image. This filter reconstructs the original image by integrating along that direction. image - a 2-dimensional array angle - shear angle ...
python
def line_integration(image, angle, decay, sigma): '''Integrate the image along the given angle DIC images are the directional derivative of the underlying image. This filter reconstructs the original image by integrating along that direction. image - a 2-dimensional array angle - shear angle ...
[ "def", "line_integration", "(", "image", ",", "angle", ",", "decay", ",", "sigma", ")", ":", "#", "# Normalize the image so that the mean is zero", "#", "normalized", "=", "image", "-", "np", ".", "mean", "(", "image", ")", "#", "# Rotate the image so the J direct...
Integrate the image along the given angle DIC images are the directional derivative of the underlying image. This filter reconstructs the original image by integrating along that direction. image - a 2-dimensional array angle - shear angle in radians. We integrate perpendicular to this angle ...
[ "Integrate", "the", "image", "along", "the", "given", "angle" ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/filter.py#L1173-L1230
CellProfiler/centrosome
centrosome/filter.py
variance_transform
def variance_transform(img, sigma, mask=None): '''Calculate a weighted variance of the image This function caluclates the variance of an image, weighting the local contributions by a Gaussian. img - image to be transformed sigma - standard deviation of the Gaussian mask - mask of relevant pixe...
python
def variance_transform(img, sigma, mask=None): '''Calculate a weighted variance of the image This function caluclates the variance of an image, weighting the local contributions by a Gaussian. img - image to be transformed sigma - standard deviation of the Gaussian mask - mask of relevant pixe...
[ "def", "variance_transform", "(", "img", ",", "sigma", ",", "mask", "=", "None", ")", ":", "if", "mask", "is", "None", ":", "mask", "=", "np", ".", "ones", "(", "img", ".", "shape", ",", "bool", ")", "else", ":", "img", "=", "img", ".", "copy", ...
Calculate a weighted variance of the image This function caluclates the variance of an image, weighting the local contributions by a Gaussian. img - image to be transformed sigma - standard deviation of the Gaussian mask - mask of relevant pixels in the image
[ "Calculate", "a", "weighted", "variance", "of", "the", "image" ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/filter.py#L1232-L1258
CellProfiler/centrosome
centrosome/filter.py
inv_n
def inv_n(x): '''given N matrices, return N inverses''' # # The inverse of a small matrix (e.g. 3x3) is # # 1 # ----- C(j,i) # det(A) # # where C(j,i) is the cofactor of matrix A at position j,i # assert x.ndim == 3 assert x.shape[1] == x.shape[2] c = np.array([ [...
python
def inv_n(x): '''given N matrices, return N inverses''' # # The inverse of a small matrix (e.g. 3x3) is # # 1 # ----- C(j,i) # det(A) # # where C(j,i) is the cofactor of matrix A at position j,i # assert x.ndim == 3 assert x.shape[1] == x.shape[2] c = np.array([ [...
[ "def", "inv_n", "(", "x", ")", ":", "#", "# The inverse of a small matrix (e.g. 3x3) is", "#", "# 1", "# ----- C(j,i)", "# det(A)", "#", "# where C(j,i) is the cofactor of matrix A at position j,i", "#", "assert", "x", ".", "ndim", "==", "3", "assert", "x", ".", "...
given N matrices, return N inverses
[ "given", "N", "matrices", "return", "N", "inverses" ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/filter.py#L1313-L1329
CellProfiler/centrosome
centrosome/filter.py
det_n
def det_n(x): '''given N matrices, return N determinants''' assert x.ndim == 3 assert x.shape[1] == x.shape[2] if x.shape[1] == 1: return x[:,0,0] result = np.zeros(x.shape[0]) for permutation in permutations(np.arange(x.shape[1])): sign = parity(permutation) result += np...
python
def det_n(x): '''given N matrices, return N determinants''' assert x.ndim == 3 assert x.shape[1] == x.shape[2] if x.shape[1] == 1: return x[:,0,0] result = np.zeros(x.shape[0]) for permutation in permutations(np.arange(x.shape[1])): sign = parity(permutation) result += np...
[ "def", "det_n", "(", "x", ")", ":", "assert", "x", ".", "ndim", "==", "3", "assert", "x", ".", "shape", "[", "1", "]", "==", "x", ".", "shape", "[", "2", "]", "if", "x", ".", "shape", "[", "1", "]", "==", "1", ":", "return", "x", "[", ":"...
given N matrices, return N determinants
[ "given", "N", "matrices", "return", "N", "determinants" ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/filter.py#L1331-L1343
CellProfiler/centrosome
centrosome/filter.py
parity
def parity(x): '''The parity of a permutation The parity of a permutation is even if the permutation can be formed by an even number of transpositions and is odd otherwise. The parity of a permutation is even if there are an even number of compositions of even size and odd otherwise. A composition...
python
def parity(x): '''The parity of a permutation The parity of a permutation is even if the permutation can be formed by an even number of transpositions and is odd otherwise. The parity of a permutation is even if there are an even number of compositions of even size and odd otherwise. A composition...
[ "def", "parity", "(", "x", ")", ":", "order", "=", "np", ".", "lexsort", "(", "(", "x", ",", ")", ")", "hit", "=", "np", ".", "zeros", "(", "len", "(", "x", ")", ",", "bool", ")", "p", "=", "0", "for", "j", "in", "range", "(", "len", "(",...
The parity of a permutation The parity of a permutation is even if the permutation can be formed by an even number of transpositions and is odd otherwise. The parity of a permutation is even if there are an even number of compositions of even size and odd otherwise. A composition is a cycle: for i...
[ "The", "parity", "of", "a", "permutation" ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/filter.py#L1345-L1372
CellProfiler/centrosome
centrosome/filter.py
cofactor_n
def cofactor_n(x, i, j): '''Return the cofactor of n matrices x[n,i,j] at position i,j The cofactor is the determinant of the matrix formed by removing row i and column j. ''' m = x.shape[1] mr = np.arange(m) i_idx = mr[mr != i] j_idx = mr[mr != j] return det_n(x[:, i_idx[:, np.newa...
python
def cofactor_n(x, i, j): '''Return the cofactor of n matrices x[n,i,j] at position i,j The cofactor is the determinant of the matrix formed by removing row i and column j. ''' m = x.shape[1] mr = np.arange(m) i_idx = mr[mr != i] j_idx = mr[mr != j] return det_n(x[:, i_idx[:, np.newa...
[ "def", "cofactor_n", "(", "x", ",", "i", ",", "j", ")", ":", "m", "=", "x", ".", "shape", "[", "1", "]", "mr", "=", "np", ".", "arange", "(", "m", ")", "i_idx", "=", "mr", "[", "mr", "!=", "i", "]", "j_idx", "=", "mr", "[", "mr", "!=", ...
Return the cofactor of n matrices x[n,i,j] at position i,j The cofactor is the determinant of the matrix formed by removing row i and column j.
[ "Return", "the", "cofactor", "of", "n", "matrices", "x", "[", "n", "i", "j", "]", "at", "position", "i", "j" ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/filter.py#L1374-L1385
CellProfiler/centrosome
centrosome/filter.py
dot_n
def dot_n(x, y): '''given two tensors N x I x K and N x K x J return N dot products If either x or y is 2-dimensional, broadcast it over all N. Dot products are size N x I x J. Example: x = np.array([[[1,2], [3,4], [5,6]],[[7,8], [9,10],[11,12]]]) y = np.array([[[1,2,3], [4,5,6]],[[7,8,9],[10,...
python
def dot_n(x, y): '''given two tensors N x I x K and N x K x J return N dot products If either x or y is 2-dimensional, broadcast it over all N. Dot products are size N x I x J. Example: x = np.array([[[1,2], [3,4], [5,6]],[[7,8], [9,10],[11,12]]]) y = np.array([[[1,2,3], [4,5,6]],[[7,8,9],[10,...
[ "def", "dot_n", "(", "x", ",", "y", ")", ":", "if", "x", ".", "ndim", "==", "2", ":", "if", "y", ".", "ndim", "==", "2", ":", "return", "np", ".", "dot", "(", "x", ",", "y", ")", "x3", "=", "False", "y3", "=", "True", "nlen", "=", "y", ...
given two tensors N x I x K and N x K x J return N dot products If either x or y is 2-dimensional, broadcast it over all N. Dot products are size N x I x J. Example: x = np.array([[[1,2], [3,4], [5,6]],[[7,8], [9,10],[11,12]]]) y = np.array([[[1,2,3], [4,5,6]],[[7,8,9],[10,11,12]]]) print dot_...
[ "given", "two", "tensors", "N", "x", "I", "x", "K", "and", "N", "x", "K", "x", "J", "return", "N", "dot", "products" ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/filter.py#L1387-L1425
CellProfiler/centrosome
centrosome/filter.py
permutations
def permutations(x): '''Given a listlike, x, return all permutations of x Returns the permutations of x in the lexical order of their indices: e.g. >>> x = [ 1, 2, 3, 4 ] >>> for p in permutations(x): >>> print p [ 1, 2, 3, 4 ] [ 1, 2, 4, 3 ] [ 1, 3, 2, 4 ] [ 1, 3, 4, 2 ] ...
python
def permutations(x): '''Given a listlike, x, return all permutations of x Returns the permutations of x in the lexical order of their indices: e.g. >>> x = [ 1, 2, 3, 4 ] >>> for p in permutations(x): >>> print p [ 1, 2, 3, 4 ] [ 1, 2, 4, 3 ] [ 1, 3, 2, 4 ] [ 1, 3, 4, 2 ] ...
[ "def", "permutations", "(", "x", ")", ":", "#", "# The algorithm is attributed to Narayana Pandit from his", "# Ganita Kaumundi (1356). The following is from", "#", "# http://en.wikipedia.org/wiki/Permutation#Systematic_generation_of_all_permutations", "#", "# 1. Find the largest index k suc...
Given a listlike, x, return all permutations of x Returns the permutations of x in the lexical order of their indices: e.g. >>> x = [ 1, 2, 3, 4 ] >>> for p in permutations(x): >>> print p [ 1, 2, 3, 4 ] [ 1, 2, 4, 3 ] [ 1, 3, 2, 4 ] [ 1, 3, 4, 2 ] [ 1, 4, 2, 3 ] [ 1, 4, 3...
[ "Given", "a", "listlike", "x", "return", "all", "permutations", "of", "x" ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/filter.py#L1427-L1476
CellProfiler/centrosome
centrosome/filter.py
convex_hull_transform
def convex_hull_transform(image, levels=256, mask = None, chunksize = CONVEX_HULL_CHUNKSIZE, pass_cutoff = 16): '''Perform the convex hull transform of this image image - image composed of integer intensity values levels - # of levels that we separate the...
python
def convex_hull_transform(image, levels=256, mask = None, chunksize = CONVEX_HULL_CHUNKSIZE, pass_cutoff = 16): '''Perform the convex hull transform of this image image - image composed of integer intensity values levels - # of levels that we separate the...
[ "def", "convex_hull_transform", "(", "image", ",", "levels", "=", "256", ",", "mask", "=", "None", ",", "chunksize", "=", "CONVEX_HULL_CHUNKSIZE", ",", "pass_cutoff", "=", "16", ")", ":", "# Scale the image into the requisite number of levels", "if", "mask", "is", ...
Perform the convex hull transform of this image image - image composed of integer intensity values levels - # of levels that we separate the image into mask - mask of points to consider or None to consider all points chunksize - # of points processed in first pass of convex hull for each intensity...
[ "Perform", "the", "convex", "hull", "transform", "of", "this", "image" ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/filter.py#L1478-L1695
CellProfiler/centrosome
centrosome/filter.py
circular_hough
def circular_hough(img, radius, nangles = None, mask=None): '''Circular Hough transform of an image img - image to be transformed. radius - radius of circle nangles - # of angles to measure, e.g. nangles = 4 means accumulate at 0, 90, 180 and 270 degrees. Return the Hough transform...
python
def circular_hough(img, radius, nangles = None, mask=None): '''Circular Hough transform of an image img - image to be transformed. radius - radius of circle nangles - # of angles to measure, e.g. nangles = 4 means accumulate at 0, 90, 180 and 270 degrees. Return the Hough transform...
[ "def", "circular_hough", "(", "img", ",", "radius", ",", "nangles", "=", "None", ",", "mask", "=", "None", ")", ":", "a", "=", "np", ".", "zeros", "(", "img", ".", "shape", ")", "m", "=", "np", ".", "zeros", "(", "img", ".", "shape", ")", "if",...
Circular Hough transform of an image img - image to be transformed. radius - radius of circle nangles - # of angles to measure, e.g. nangles = 4 means accumulate at 0, 90, 180 and 270 degrees. Return the Hough transform of the image which is the accumulators for the transform x + r...
[ "Circular", "Hough", "transform", "of", "an", "image" ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/filter.py#L1697-L1734
CellProfiler/centrosome
centrosome/filter.py
hessian
def hessian(image, return_hessian=True, return_eigenvalues=True, return_eigenvectors=True): '''Calculate hessian, its eigenvalues and eigenvectors image - n x m image. Smooth the image with a Gaussian to get derivatives at different scales. return_hessian - true to return an n x m x 2 x 2 matr...
python
def hessian(image, return_hessian=True, return_eigenvalues=True, return_eigenvectors=True): '''Calculate hessian, its eigenvalues and eigenvectors image - n x m image. Smooth the image with a Gaussian to get derivatives at different scales. return_hessian - true to return an n x m x 2 x 2 matr...
[ "def", "hessian", "(", "image", ",", "return_hessian", "=", "True", ",", "return_eigenvalues", "=", "True", ",", "return_eigenvectors", "=", "True", ")", ":", "#The Hessian, d(f(x0, x1))/dxi/dxj for i,j = [0,1] is approximated by the", "#following kernels:", "#d00: [[1], [-2]...
Calculate hessian, its eigenvalues and eigenvectors image - n x m image. Smooth the image with a Gaussian to get derivatives at different scales. return_hessian - true to return an n x m x 2 x 2 matrix of the hessian at each pixel return_eigenvalues - true to return an n ...
[ "Calculate", "hessian", "its", "eigenvalues", "and", "eigenvectors" ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/filter.py#L1736-L1843
CellProfiler/centrosome
centrosome/filter.py
poisson_equation
def poisson_equation(image, gradient=1, max_iter=100, convergence=.01, percentile = 90.0): '''Estimate the solution to the Poisson Equation The Poisson Equation is the solution to gradient(x) = h^2/4 and, in this context, we use a boundary condition where x is zero for background pixels. Also, we set h...
python
def poisson_equation(image, gradient=1, max_iter=100, convergence=.01, percentile = 90.0): '''Estimate the solution to the Poisson Equation The Poisson Equation is the solution to gradient(x) = h^2/4 and, in this context, we use a boundary condition where x is zero for background pixels. Also, we set h...
[ "def", "poisson_equation", "(", "image", ",", "gradient", "=", "1", ",", "max_iter", "=", "100", ",", "convergence", "=", ".01", ",", "percentile", "=", "90.0", ")", ":", "# Evaluate the poisson equation with zero-padded boundaries", "pe", "=", "np", ".", "zeros...
Estimate the solution to the Poisson Equation The Poisson Equation is the solution to gradient(x) = h^2/4 and, in this context, we use a boundary condition where x is zero for background pixels. Also, we set h^2/4 = 1 to indicate that each pixel is a distance of 1 from its neighbors. The estimatio...
[ "Estimate", "the", "solution", "to", "the", "Poisson", "Equation" ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/filter.py#L1845-L1909
CellProfiler/centrosome
centrosome/filter.py
KalmanState.predicted_state_vec
def predicted_state_vec(self): '''The predicted state vector for the next time point From Welch eqn 1.9 ''' if not self.has_cached_predicted_state_vec: self.p_state_vec = dot_n( self.translation_matrix, self.state_vec[:, :, np.newaxis])[:,:,0]...
python
def predicted_state_vec(self): '''The predicted state vector for the next time point From Welch eqn 1.9 ''' if not self.has_cached_predicted_state_vec: self.p_state_vec = dot_n( self.translation_matrix, self.state_vec[:, :, np.newaxis])[:,:,0]...
[ "def", "predicted_state_vec", "(", "self", ")", ":", "if", "not", "self", ".", "has_cached_predicted_state_vec", ":", "self", ".", "p_state_vec", "=", "dot_n", "(", "self", ".", "translation_matrix", ",", "self", ".", "state_vec", "[", ":", ",", ":", ",", ...
The predicted state vector for the next time point From Welch eqn 1.9
[ "The", "predicted", "state", "vector", "for", "the", "next", "time", "point" ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/filter.py#L895-L904
CellProfiler/centrosome
centrosome/filter.py
KalmanState.predicted_obs_vec
def predicted_obs_vec(self): '''The predicted observation vector The observation vector for the next step in the filter. ''' if not self.has_cached_obs_vec: self.obs_vec = dot_n( self.observation_matrix, self.predicted_state_vec[:,:,np.newaxis...
python
def predicted_obs_vec(self): '''The predicted observation vector The observation vector for the next step in the filter. ''' if not self.has_cached_obs_vec: self.obs_vec = dot_n( self.observation_matrix, self.predicted_state_vec[:,:,np.newaxis...
[ "def", "predicted_obs_vec", "(", "self", ")", ":", "if", "not", "self", ".", "has_cached_obs_vec", ":", "self", ".", "obs_vec", "=", "dot_n", "(", "self", ".", "observation_matrix", ",", "self", ".", "predicted_state_vec", "[", ":", ",", ":", ",", "np", ...
The predicted observation vector The observation vector for the next step in the filter.
[ "The", "predicted", "observation", "vector" ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/filter.py#L912-L921
CellProfiler/centrosome
centrosome/filter.py
KalmanState.map_frames
def map_frames(self, old_indices): '''Rewrite the feature indexes based on the next frame's identities old_indices - for each feature in the new frame, the index of the old feature ''' nfeatures = len(old_indices) noldfeatures = len(self.state_vec) ...
python
def map_frames(self, old_indices): '''Rewrite the feature indexes based on the next frame's identities old_indices - for each feature in the new frame, the index of the old feature ''' nfeatures = len(old_indices) noldfeatures = len(self.state_vec) ...
[ "def", "map_frames", "(", "self", ",", "old_indices", ")", ":", "nfeatures", "=", "len", "(", "old_indices", ")", "noldfeatures", "=", "len", "(", "self", ".", "state_vec", ")", "if", "nfeatures", ">", "0", ":", "self", ".", "state_vec", "=", "self", "...
Rewrite the feature indexes based on the next frame's identities old_indices - for each feature in the new frame, the index of the old feature
[ "Rewrite", "the", "feature", "indexes", "based", "on", "the", "next", "frame", "s", "identities" ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/filter.py#L923-L951
CellProfiler/centrosome
centrosome/filter.py
KalmanState.add_features
def add_features(self, kept_indices, new_indices, new_state_vec, new_state_cov, new_noise_var): '''Add new features to the state kept_indices - the mapping from all indices in the state to new indices in the new version new_indices - the indices of t...
python
def add_features(self, kept_indices, new_indices, new_state_vec, new_state_cov, new_noise_var): '''Add new features to the state kept_indices - the mapping from all indices in the state to new indices in the new version new_indices - the indices of t...
[ "def", "add_features", "(", "self", ",", "kept_indices", ",", "new_indices", ",", "new_state_vec", ",", "new_state_cov", ",", "new_noise_var", ")", ":", "assert", "len", "(", "kept_indices", ")", "==", "len", "(", "self", ".", "state_vec", ")", "assert", "le...
Add new features to the state kept_indices - the mapping from all indices in the state to new indices in the new version new_indices - the indices of the new features in the new version new_state_vec - the state vectors for the new indices new_state_cov - the c...
[ "Add", "new", "features", "to", "the", "state" ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/filter.py#L953-L995
CellProfiler/centrosome
centrosome/filter.py
KalmanState.deep_copy
def deep_copy(self): '''Return a deep copy of the state''' c = KalmanState(self.observation_matrix, self.translation_matrix) c.state_vec = self.state_vec.copy() c.state_cov = self.state_cov.copy() c.noise_var = self.noise_var.copy() c.state_noise = self.state_noise.copy()...
python
def deep_copy(self): '''Return a deep copy of the state''' c = KalmanState(self.observation_matrix, self.translation_matrix) c.state_vec = self.state_vec.copy() c.state_cov = self.state_cov.copy() c.noise_var = self.noise_var.copy() c.state_noise = self.state_noise.copy()...
[ "def", "deep_copy", "(", "self", ")", ":", "c", "=", "KalmanState", "(", "self", ".", "observation_matrix", ",", "self", ".", "translation_matrix", ")", "c", ".", "state_vec", "=", "self", ".", "state_vec", ".", "copy", "(", ")", "c", ".", "state_cov", ...
Return a deep copy of the state
[ "Return", "a", "deep", "copy", "of", "the", "state" ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/filter.py#L997-L1005
CellProfiler/centrosome
centrosome/bg_compensate.py
prcntiles
def prcntiles(x,percents): '''Equivalent to matlab prctile(x,p), uses linear interpolation.''' x=np.array(x).flatten() listx = np.sort(x) xpcts=[] lenlistx=len(listx) refs=[] for i in range(0,lenlistx): r=100*((.5+i)/lenlistx) #refs[i] is percentile of listx[i] in matrix x re...
python
def prcntiles(x,percents): '''Equivalent to matlab prctile(x,p), uses linear interpolation.''' x=np.array(x).flatten() listx = np.sort(x) xpcts=[] lenlistx=len(listx) refs=[] for i in range(0,lenlistx): r=100*((.5+i)/lenlistx) #refs[i] is percentile of listx[i] in matrix x re...
[ "def", "prcntiles", "(", "x", ",", "percents", ")", ":", "x", "=", "np", ".", "array", "(", "x", ")", ".", "flatten", "(", ")", "listx", "=", "np", ".", "sort", "(", "x", ")", "xpcts", "=", "[", "]", "lenlistx", "=", "len", "(", "listx", ")",...
Equivalent to matlab prctile(x,p), uses linear interpolation.
[ "Equivalent", "to", "matlab", "prctile", "(", "x", "p", ")", "uses", "linear", "interpolation", "." ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/bg_compensate.py#L22-L48
CellProfiler/centrosome
centrosome/bg_compensate.py
automode
def automode(data): '''Tries to guess if the image contains dark objects on a bright background (1) or if the image contains bright objects on a dark background (-1), or if it contains both dark and bright objects on a gray background (0).''' pct=prcntiles(np.array(data),[1,20,80,99]) upper=...
python
def automode(data): '''Tries to guess if the image contains dark objects on a bright background (1) or if the image contains bright objects on a dark background (-1), or if it contains both dark and bright objects on a gray background (0).''' pct=prcntiles(np.array(data),[1,20,80,99]) upper=...
[ "def", "automode", "(", "data", ")", ":", "pct", "=", "prcntiles", "(", "np", ".", "array", "(", "data", ")", ",", "[", "1", ",", "20", ",", "80", ",", "99", "]", ")", "upper", "=", "pct", "[", "3", "]", "-", "pct", "[", "2", "]", "mid", ...
Tries to guess if the image contains dark objects on a bright background (1) or if the image contains bright objects on a dark background (-1), or if it contains both dark and bright objects on a gray background (0).
[ "Tries", "to", "guess", "if", "the", "image", "contains", "dark", "objects", "on", "a", "bright", "background", "(", "1", ")", "or", "if", "the", "image", "contains", "bright", "objects", "on", "a", "dark", "background", "(", "-", "1", ")", "or", "if",...
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/bg_compensate.py#L51-L97
CellProfiler/centrosome
centrosome/bg_compensate.py
spline_factors
def spline_factors(u): '''u is np.array''' X = np.array([(1.-u)**3 , 4-(6.*(u**2))+(3.*(u**3)) , 1.+(3.*u)+(3.*(u**2))-(3.*(u**3)) , u**3]) * (1./6) return X
python
def spline_factors(u): '''u is np.array''' X = np.array([(1.-u)**3 , 4-(6.*(u**2))+(3.*(u**3)) , 1.+(3.*u)+(3.*(u**2))-(3.*(u**3)) , u**3]) * (1./6) return X
[ "def", "spline_factors", "(", "u", ")", ":", "X", "=", "np", ".", "array", "(", "[", "(", "1.", "-", "u", ")", "**", "3", ",", "4", "-", "(", "6.", "*", "(", "u", "**", "2", ")", ")", "+", "(", "3.", "*", "(", "u", "**", "3", ")", ")"...
u is np.array
[ "u", "is", "np", ".", "array" ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/bg_compensate.py#L99-L104
CellProfiler/centrosome
centrosome/bg_compensate.py
pick
def pick(picklist,val): '''Index to first value in picklist that is larger than val. If none is larger, index=len(picklist).''' assert np.all(np.sort(picklist) == picklist), "pick list is not ordered correctly" val = np.array(val) i_pick, i_val = np.mgrid[0:len(picklist),0:len(val)] # # Mar...
python
def pick(picklist,val): '''Index to first value in picklist that is larger than val. If none is larger, index=len(picklist).''' assert np.all(np.sort(picklist) == picklist), "pick list is not ordered correctly" val = np.array(val) i_pick, i_val = np.mgrid[0:len(picklist),0:len(val)] # # Mar...
[ "def", "pick", "(", "picklist", ",", "val", ")", ":", "assert", "np", ".", "all", "(", "np", ".", "sort", "(", "picklist", ")", "==", "picklist", ")", ",", "\"pick list is not ordered correctly\"", "val", "=", "np", ".", "array", "(", "val", ")", "i_pi...
Index to first value in picklist that is larger than val. If none is larger, index=len(picklist).
[ "Index", "to", "first", "value", "in", "picklist", "that", "is", "larger", "than", "val", ".", "If", "none", "is", "larger", "index", "=", "len", "(", "picklist", ")", "." ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/bg_compensate.py#L106-L123
CellProfiler/centrosome
centrosome/bg_compensate.py
confine
def confine(x,low,high): '''Confine x to [low,high]. Values outside are set to low/high. See also restrict.''' y=x.copy() y[y < low] = low y[y > high] = high return y
python
def confine(x,low,high): '''Confine x to [low,high]. Values outside are set to low/high. See also restrict.''' y=x.copy() y[y < low] = low y[y > high] = high return y
[ "def", "confine", "(", "x", ",", "low", ",", "high", ")", ":", "y", "=", "x", ".", "copy", "(", ")", "y", "[", "y", "<", "low", "]", "=", "low", "y", "[", "y", ">", "high", "]", "=", "high", "return", "y" ]
Confine x to [low,high]. Values outside are set to low/high. See also restrict.
[ "Confine", "x", "to", "[", "low", "high", "]", ".", "Values", "outside", "are", "set", "to", "low", "/", "high", ".", "See", "also", "restrict", "." ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/bg_compensate.py#L125-L132
CellProfiler/centrosome
centrosome/bg_compensate.py
gauss
def gauss(x,m_y,sigma): '''returns the gaussian with mean m_y and std. dev. sigma, calculated at the points of x.''' e_y = [np.exp((1.0/(2*float(sigma)**2)*-(n-m_y)**2)) for n in np.array(x)] y = [1.0/(float(sigma) * np.sqrt(2 * np.pi)) * e for e in e_y] return np.array(y)
python
def gauss(x,m_y,sigma): '''returns the gaussian with mean m_y and std. dev. sigma, calculated at the points of x.''' e_y = [np.exp((1.0/(2*float(sigma)**2)*-(n-m_y)**2)) for n in np.array(x)] y = [1.0/(float(sigma) * np.sqrt(2 * np.pi)) * e for e in e_y] return np.array(y)
[ "def", "gauss", "(", "x", ",", "m_y", ",", "sigma", ")", ":", "e_y", "=", "[", "np", ".", "exp", "(", "(", "1.0", "/", "(", "2", "*", "float", "(", "sigma", ")", "**", "2", ")", "*", "-", "(", "n", "-", "m_y", ")", "**", "2", ")", ")", ...
returns the gaussian with mean m_y and std. dev. sigma, calculated at the points of x.
[ "returns", "the", "gaussian", "with", "mean", "m_y", "and", "std", ".", "dev", ".", "sigma", "calculated", "at", "the", "points", "of", "x", "." ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/bg_compensate.py#L134-L141
CellProfiler/centrosome
centrosome/bg_compensate.py
d2gauss
def d2gauss(x,m_y,sigma): '''returns the second derivative of the gaussian with mean m_y, and standard deviation sigma, calculated at the points of x.''' return gauss(x,m_y,sigma)*[-1/sigma**2 + (n-m_y)**2/sigma**4 for n in x]
python
def d2gauss(x,m_y,sigma): '''returns the second derivative of the gaussian with mean m_y, and standard deviation sigma, calculated at the points of x.''' return gauss(x,m_y,sigma)*[-1/sigma**2 + (n-m_y)**2/sigma**4 for n in x]
[ "def", "d2gauss", "(", "x", ",", "m_y", ",", "sigma", ")", ":", "return", "gauss", "(", "x", ",", "m_y", ",", "sigma", ")", "*", "[", "-", "1", "/", "sigma", "**", "2", "+", "(", "n", "-", "m_y", ")", "**", "2", "/", "sigma", "**", "4", "...
returns the second derivative of the gaussian with mean m_y, and standard deviation sigma, calculated at the points of x.
[ "returns", "the", "second", "derivative", "of", "the", "gaussian", "with", "mean", "m_y", "and", "standard", "deviation", "sigma", "calculated", "at", "the", "points", "of", "x", "." ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/bg_compensate.py#L143-L147
CellProfiler/centrosome
centrosome/bg_compensate.py
spline_matrix2d
def spline_matrix2d(x,y,px,py,mask=None): '''For boundary constraints, the first two and last two spline pieces are constrained to be part of the same cubic curve.''' V = np.kron(spline_matrix(x,px),spline_matrix(y,py)) lenV = len(V) if mask is not None: indices = np.nonzero(mask.T.fla...
python
def spline_matrix2d(x,y,px,py,mask=None): '''For boundary constraints, the first two and last two spline pieces are constrained to be part of the same cubic curve.''' V = np.kron(spline_matrix(x,px),spline_matrix(y,py)) lenV = len(V) if mask is not None: indices = np.nonzero(mask.T.fla...
[ "def", "spline_matrix2d", "(", "x", ",", "y", ",", "px", ",", "py", ",", "mask", "=", "None", ")", ":", "V", "=", "np", ".", "kron", "(", "spline_matrix", "(", "x", ",", "px", ")", ",", "spline_matrix", "(", "y", ",", "py", ")", ")", "lenV", ...
For boundary constraints, the first two and last two spline pieces are constrained to be part of the same cubic curve.
[ "For", "boundary", "constraints", "the", "first", "two", "and", "last", "two", "spline", "pieces", "are", "constrained", "to", "be", "part", "of", "the", "same", "cubic", "curve", "." ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/bg_compensate.py#L175-L191
CellProfiler/centrosome
centrosome/bg_compensate.py
splinefit2d
def splinefit2d(x, y, z, px, py, mask=None): '''Make a least squares fit of the spline (px,py,pz) to the surface (x,y,z). If mask is given, only masked points are used for the regression.''' if mask is None: V = np.array(spline_matrix2d(x, y, px, py)) a = np.array(z.T.flatten()) pz ...
python
def splinefit2d(x, y, z, px, py, mask=None): '''Make a least squares fit of the spline (px,py,pz) to the surface (x,y,z). If mask is given, only masked points are used for the regression.''' if mask is None: V = np.array(spline_matrix2d(x, y, px, py)) a = np.array(z.T.flatten()) pz ...
[ "def", "splinefit2d", "(", "x", ",", "y", ",", "z", ",", "px", ",", "py", ",", "mask", "=", "None", ")", ":", "if", "mask", "is", "None", ":", "V", "=", "np", ".", "array", "(", "spline_matrix2d", "(", "x", ",", "y", ",", "px", ",", "py", "...
Make a least squares fit of the spline (px,py,pz) to the surface (x,y,z). If mask is given, only masked points are used for the regression.
[ "Make", "a", "least", "squares", "fit", "of", "the", "spline", "(", "px", "py", "pz", ")", "to", "the", "surface", "(", "x", "y", "z", ")", ".", "If", "mask", "is", "given", "only", "masked", "points", "are", "used", "for", "the", "regression", "."...
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/bg_compensate.py#L194-L213
CellProfiler/centrosome
centrosome/bg_compensate.py
backgr
def backgr(img, mask = None, mode=MODE_AUTO, thresh=2, splinepoints=5, scale=1, maxiter=40, convergence = .001): '''Iterative spline-based background correction. mode - one of MODE_AUTO, MODE_DARK, MODE_BRIGHT or MODE_GRAY thresh - thresh is threshold to cut at, in units of sigma. spli...
python
def backgr(img, mask = None, mode=MODE_AUTO, thresh=2, splinepoints=5, scale=1, maxiter=40, convergence = .001): '''Iterative spline-based background correction. mode - one of MODE_AUTO, MODE_DARK, MODE_BRIGHT or MODE_GRAY thresh - thresh is threshold to cut at, in units of sigma. spli...
[ "def", "backgr", "(", "img", ",", "mask", "=", "None", ",", "mode", "=", "MODE_AUTO", ",", "thresh", "=", "2", ",", "splinepoints", "=", "5", ",", "scale", "=", "1", ",", "maxiter", "=", "40", ",", "convergence", "=", ".001", ")", ":", "assert", ...
Iterative spline-based background correction. mode - one of MODE_AUTO, MODE_DARK, MODE_BRIGHT or MODE_GRAY thresh - thresh is threshold to cut at, in units of sigma. splinepoints - # of points in spline in each direction scale - scale the image by this factor (e.g. 2 = operate on 1/2 of the points...
[ "Iterative", "spline", "-", "based", "background", "correction", ".", "mode", "-", "one", "of", "MODE_AUTO", "MODE_DARK", "MODE_BRIGHT", "or", "MODE_GRAY", "thresh", "-", "thresh", "is", "threshold", "to", "cut", "at", "in", "units", "of", "sigma", ".", "spl...
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/bg_compensate.py#L246-L356
CellProfiler/centrosome
centrosome/bg_compensate.py
bg_compensate
def bg_compensate(img, sigma, splinepoints, scale): '''Reads file, subtracts background. Returns [compensated image, background].''' from PIL import Image import pylab from matplotlib.image import pil_to_array from centrosome.filter import canny import matplotlib img = Image.open(img) ...
python
def bg_compensate(img, sigma, splinepoints, scale): '''Reads file, subtracts background. Returns [compensated image, background].''' from PIL import Image import pylab from matplotlib.image import pil_to_array from centrosome.filter import canny import matplotlib img = Image.open(img) ...
[ "def", "bg_compensate", "(", "img", ",", "sigma", ",", "splinepoints", ",", "scale", ")", ":", "from", "PIL", "import", "Image", "import", "pylab", "from", "matplotlib", ".", "image", "import", "pil_to_array", "from", "centrosome", ".", "filter", "import", "...
Reads file, subtracts background. Returns [compensated image, background].
[ "Reads", "file", "subtracts", "background", ".", "Returns", "[", "compensated", "image", "background", "]", "." ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/bg_compensate.py#L358-L414
CellProfiler/centrosome
centrosome/mode.py
mode
def mode(a): '''Compute the mode of an array a: an array returns a vector of values which are the most frequent (more than one if there is a tie). ''' a = np.asanyarray(a) if a.size == 0: return np.zeros(0, a.dtype) aa = a.flatten() aa.sort() indices = np.hstack...
python
def mode(a): '''Compute the mode of an array a: an array returns a vector of values which are the most frequent (more than one if there is a tie). ''' a = np.asanyarray(a) if a.size == 0: return np.zeros(0, a.dtype) aa = a.flatten() aa.sort() indices = np.hstack...
[ "def", "mode", "(", "a", ")", ":", "a", "=", "np", ".", "asanyarray", "(", "a", ")", "if", "a", ".", "size", "==", "0", ":", "return", "np", ".", "zeros", "(", "0", ",", "a", ".", "dtype", ")", "aa", "=", "a", ".", "flatten", "(", ")", "a...
Compute the mode of an array a: an array returns a vector of values which are the most frequent (more than one if there is a tie).
[ "Compute", "the", "mode", "of", "an", "array", "a", ":", "an", "array", "returns", "a", "vector", "of", "values", "which", "are", "the", "most", "frequent", "(", "more", "than", "one", "if", "there", "is", "a", "tie", ")", "." ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/mode.py#L4-L20
CellProfiler/centrosome
centrosome/otsu.py
otsu
def otsu(data, min_threshold=None, max_threshold=None,bins=256): """Compute a threshold using Otsu's method data - an array of intensity values between zero and one min_threshold - only consider thresholds above this minimum value max_threshold - only consider thresholds below this maxi...
python
def otsu(data, min_threshold=None, max_threshold=None,bins=256): """Compute a threshold using Otsu's method data - an array of intensity values between zero and one min_threshold - only consider thresholds above this minimum value max_threshold - only consider thresholds below this maxi...
[ "def", "otsu", "(", "data", ",", "min_threshold", "=", "None", ",", "max_threshold", "=", "None", ",", "bins", "=", "256", ")", ":", "assert", "min_threshold", "is", "None", "or", "max_threshold", "is", "None", "or", "min_threshold", "<", "max_threshold", ...
Compute a threshold using Otsu's method data - an array of intensity values between zero and one min_threshold - only consider thresholds above this minimum value max_threshold - only consider thresholds below this maximum value bins - we bin the data into this many equally-sp...
[ "Compute", "a", "threshold", "using", "Otsu", "s", "method", "data", "-", "an", "array", "of", "intensity", "values", "between", "zero", "and", "one", "min_threshold", "-", "only", "consider", "thresholds", "above", "this", "minimum", "value", "max_threshold", ...
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/otsu.py#L5-L59
CellProfiler/centrosome
centrosome/otsu.py
entropy
def entropy(data, bins=256): """Compute a threshold using Ray's entropy measurement data - an array of intensity values between zero and one bins - we bin the data into this many equally-spaced bins, then pick the bin index that optimizes the metric """ ...
python
def entropy(data, bins=256): """Compute a threshold using Ray's entropy measurement data - an array of intensity values between zero and one bins - we bin the data into this many equally-spaced bins, then pick the bin index that optimizes the metric """ ...
[ "def", "entropy", "(", "data", ",", "bins", "=", "256", ")", ":", "data", "=", "np", ".", "atleast_1d", "(", "data", ")", "data", "=", "data", "[", "~", "np", ".", "isnan", "(", "data", ")", "]", "if", "len", "(", "data", ")", "==", "0", ":",...
Compute a threshold using Ray's entropy measurement data - an array of intensity values between zero and one bins - we bin the data into this many equally-spaced bins, then pick the bin index that optimizes the metric
[ "Compute", "a", "threshold", "using", "Ray", "s", "entropy", "measurement", "data", "-", "an", "array", "of", "intensity", "values", "between", "zero", "and", "one", "bins", "-", "we", "bin", "the", "data", "into", "this", "many", "equally", "-", "spaced",...
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/otsu.py#L61-L108
CellProfiler/centrosome
centrosome/otsu.py
otsu3
def otsu3(data, min_threshold=None, max_threshold=None,bins=128): """Compute a threshold using a 3-category Otsu-like method data - an array of intensity values between zero and one min_threshold - only consider thresholds above this minimum value max_threshold - only consider thres...
python
def otsu3(data, min_threshold=None, max_threshold=None,bins=128): """Compute a threshold using a 3-category Otsu-like method data - an array of intensity values between zero and one min_threshold - only consider thresholds above this minimum value max_threshold - only consider thres...
[ "def", "otsu3", "(", "data", ",", "min_threshold", "=", "None", ",", "max_threshold", "=", "None", ",", "bins", "=", "128", ")", ":", "assert", "min_threshold", "is", "None", "or", "max_threshold", "is", "None", "or", "min_threshold", "<", "max_threshold", ...
Compute a threshold using a 3-category Otsu-like method data - an array of intensity values between zero and one min_threshold - only consider thresholds above this minimum value max_threshold - only consider thresholds below this maximum value bins - we bin the data into this...
[ "Compute", "a", "threshold", "using", "a", "3", "-", "category", "Otsu", "-", "like", "method", "data", "-", "an", "array", "of", "intensity", "values", "between", "zero", "and", "one", "min_threshold", "-", "only", "consider", "thresholds", "above", "this",...
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/otsu.py#L110-L158
CellProfiler/centrosome
centrosome/otsu.py
entropy_score
def entropy_score(var,bins, w=None, decimate=True): '''Compute entropy scores, given a variance and # of bins ''' if w is None: n = len(var) w = np.arange(0,n,n//bins) / float(n) if decimate: n = len(var) var = var[0:n:n//bins] score = w * np.log(var * w * np.sqr...
python
def entropy_score(var,bins, w=None, decimate=True): '''Compute entropy scores, given a variance and # of bins ''' if w is None: n = len(var) w = np.arange(0,n,n//bins) / float(n) if decimate: n = len(var) var = var[0:n:n//bins] score = w * np.log(var * w * np.sqr...
[ "def", "entropy_score", "(", "var", ",", "bins", ",", "w", "=", "None", ",", "decimate", "=", "True", ")", ":", "if", "w", "is", "None", ":", "n", "=", "len", "(", "var", ")", "w", "=", "np", ".", "arange", "(", "0", ",", "n", ",", "n", "//...
Compute entropy scores, given a variance and # of bins
[ "Compute", "entropy", "scores", "given", "a", "variance", "and", "#", "of", "bins" ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/otsu.py#L205-L217
CellProfiler/centrosome
centrosome/otsu.py
running_variance
def running_variance(x): '''Given a vector x, compute the variance for x[0:i] Thank you http://www.johndcook.com/standard_deviation.html S[i] = S[i-1]+(x[i]-mean[i-1])*(x[i]-mean[i]) var(i) = S[i] / (i-1) ''' n = len(x) # The mean of x[0:i] m = x.cumsum() / np.arange(1,n+1) # x[...
python
def running_variance(x): '''Given a vector x, compute the variance for x[0:i] Thank you http://www.johndcook.com/standard_deviation.html S[i] = S[i-1]+(x[i]-mean[i-1])*(x[i]-mean[i]) var(i) = S[i] / (i-1) ''' n = len(x) # The mean of x[0:i] m = x.cumsum() / np.arange(1,n+1) # x[...
[ "def", "running_variance", "(", "x", ")", ":", "n", "=", "len", "(", "x", ")", "# The mean of x[0:i]", "m", "=", "x", ".", "cumsum", "(", ")", "/", "np", ".", "arange", "(", "1", ",", "n", "+", "1", ")", "# x[i]-mean[i-1] for i=1...", "x_minus_mprev", ...
Given a vector x, compute the variance for x[0:i] Thank you http://www.johndcook.com/standard_deviation.html S[i] = S[i-1]+(x[i]-mean[i-1])*(x[i]-mean[i]) var(i) = S[i] / (i-1)
[ "Given", "a", "vector", "x", "compute", "the", "variance", "for", "x", "[", "0", ":", "i", "]", "Thank", "you", "http", ":", "//", "www", ".", "johndcook", ".", "com", "/", "standard_deviation", ".", "html", "S", "[", "i", "]", "=", "S", "[", "i"...
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/otsu.py#L236-L254
CellProfiler/centrosome
centrosome/outline.py
outline
def outline(labels): """Given a label matrix, return a matrix of the outlines of the labeled objects If a pixel is not zero and has at least one neighbor with a different value, then it is part of the outline. """ output = numpy.zeros(labels.shape, labels.dtype) lr_different = labels[1...
python
def outline(labels): """Given a label matrix, return a matrix of the outlines of the labeled objects If a pixel is not zero and has at least one neighbor with a different value, then it is part of the outline. """ output = numpy.zeros(labels.shape, labels.dtype) lr_different = labels[1...
[ "def", "outline", "(", "labels", ")", ":", "output", "=", "numpy", ".", "zeros", "(", "labels", ".", "shape", ",", "labels", ".", "dtype", ")", "lr_different", "=", "labels", "[", "1", ":", ",", ":", "]", "!=", "labels", "[", ":", "-", "1", ",", ...
Given a label matrix, return a matrix of the outlines of the labeled objects If a pixel is not zero and has at least one neighbor with a different value, then it is part of the outline.
[ "Given", "a", "label", "matrix", "return", "a", "matrix", "of", "the", "outlines", "of", "the", "labeled", "objects", "If", "a", "pixel", "is", "not", "zero", "and", "has", "at", "least", "one", "neighbor", "with", "a", "different", "value", "then", "it"...
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/outline.py#L4-L34
CellProfiler/centrosome
centrosome/neighmovetrack.py
euclidean_dist
def euclidean_dist(point1, point2): """Compute the Euclidean distance between two points. Parameters ---------- point1, point2 : 2-tuples of float The input points. Returns ------- d : float The distance between the input points. Examples -------- >>> point1 = ...
python
def euclidean_dist(point1, point2): """Compute the Euclidean distance between two points. Parameters ---------- point1, point2 : 2-tuples of float The input points. Returns ------- d : float The distance between the input points. Examples -------- >>> point1 = ...
[ "def", "euclidean_dist", "(", "point1", ",", "point2", ")", ":", "(", "x1", ",", "y1", ")", "=", "point1", "(", "x2", ",", "y2", ")", "=", "point2", "return", "math", ".", "sqrt", "(", "(", "x1", "-", "x2", ")", "**", "2", "+", "(", "y1", "-"...
Compute the Euclidean distance between two points. Parameters ---------- point1, point2 : 2-tuples of float The input points. Returns ------- d : float The distance between the input points. Examples -------- >>> point1 = (1.0, 2.0) >>> point2 = (4.0, 6.0) # (...
[ "Compute", "the", "Euclidean", "distance", "between", "two", "points", "." ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/neighmovetrack.py#L14-L36
CellProfiler/centrosome
centrosome/neighmovetrack.py
CellFeatures.from_labels
def from_labels(labels): """ Creates list of cell features based on label image (1-oo pixel values) @return: list of cell features in the same order as labels """ labels = labels.astype(int) areas = scipy.ndimage.measurements.sum(labels != 0, labels, list(range(1, numpy...
python
def from_labels(labels): """ Creates list of cell features based on label image (1-oo pixel values) @return: list of cell features in the same order as labels """ labels = labels.astype(int) areas = scipy.ndimage.measurements.sum(labels != 0, labels, list(range(1, numpy...
[ "def", "from_labels", "(", "labels", ")", ":", "labels", "=", "labels", ".", "astype", "(", "int", ")", "areas", "=", "scipy", ".", "ndimage", ".", "measurements", ".", "sum", "(", "labels", "!=", "0", ",", "labels", ",", "list", "(", "range", "(", ...
Creates list of cell features based on label image (1-oo pixel values) @return: list of cell features in the same order as labels
[ "Creates", "list", "of", "cell", "features", "based", "on", "label", "image", "(", "1", "-", "oo", "pixel", "values", ")" ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/neighmovetrack.py#L105-L126
CellProfiler/centrosome
centrosome/neighmovetrack.py
Trace.from_detections_assignment
def from_detections_assignment(detections_1, detections_2, assignments): """ Creates traces out of given assignment and cell data. """ traces = [] for d1n, d2n in six.iteritems(assignments): # check if the match is between existing cells if d1n < len(dete...
python
def from_detections_assignment(detections_1, detections_2, assignments): """ Creates traces out of given assignment and cell data. """ traces = [] for d1n, d2n in six.iteritems(assignments): # check if the match is between existing cells if d1n < len(dete...
[ "def", "from_detections_assignment", "(", "detections_1", ",", "detections_2", ",", "assignments", ")", ":", "traces", "=", "[", "]", "for", "d1n", ",", "d2n", "in", "six", ".", "iteritems", "(", "assignments", ")", ":", "# check if the match is between existing c...
Creates traces out of given assignment and cell data.
[ "Creates", "traces", "out", "of", "given", "assignment", "and", "cell", "data", "." ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/neighmovetrack.py#L171-L182
CellProfiler/centrosome
centrosome/neighmovetrack.py
NeighbourMovementTracking.run_tracking
def run_tracking(self, label_image_1, label_image_2): """ Tracks cells between input label images. @returns: injective function from old objects to new objects (pairs of [old, new]). Number are compatible with labels. """ self.scale = self.parameters_tracking["avgCellDiameter"] ...
python
def run_tracking(self, label_image_1, label_image_2): """ Tracks cells between input label images. @returns: injective function from old objects to new objects (pairs of [old, new]). Number are compatible with labels. """ self.scale = self.parameters_tracking["avgCellDiameter"] ...
[ "def", "run_tracking", "(", "self", ",", "label_image_1", ",", "label_image_2", ")", ":", "self", ".", "scale", "=", "self", ".", "parameters_tracking", "[", "\"avgCellDiameter\"", "]", "/", "35.0", "detections_1", "=", "self", ".", "derive_detections", "(", "...
Tracks cells between input label images. @returns: injective function from old objects to new objects (pairs of [old, new]). Number are compatible with labels.
[ "Tracks", "cells", "between", "input", "label", "images", "." ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/neighmovetrack.py#L198-L218
CellProfiler/centrosome
centrosome/neighmovetrack.py
NeighbourMovementTracking.is_cell_big
def is_cell_big(self, cell_detection): """ Check if the cell is considered big. @param CellFeature cell_detection: @return: """ return cell_detection.area > self.parameters_tracking["big_size"] * self.scale * self.scale
python
def is_cell_big(self, cell_detection): """ Check if the cell is considered big. @param CellFeature cell_detection: @return: """ return cell_detection.area > self.parameters_tracking["big_size"] * self.scale * self.scale
[ "def", "is_cell_big", "(", "self", ",", "cell_detection", ")", ":", "return", "cell_detection", ".", "area", ">", "self", ".", "parameters_tracking", "[", "\"big_size\"", "]", "*", "self", ".", "scale", "*", "self", ".", "scale" ]
Check if the cell is considered big. @param CellFeature cell_detection: @return:
[ "Check", "if", "the", "cell", "is", "considered", "big", "." ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/neighmovetrack.py#L220-L228
CellProfiler/centrosome
centrosome/neighmovetrack.py
NeighbourMovementTracking.find_closest_neighbours
def find_closest_neighbours(cell, all_cells, k, max_dist): """ Find k closest neighbours of the given cell. :param CellFeatures cell: cell of interest :param all_cells: cell to consider as neighbours :param int k: number of neighbours to be returned :param int max_dist: m...
python
def find_closest_neighbours(cell, all_cells, k, max_dist): """ Find k closest neighbours of the given cell. :param CellFeatures cell: cell of interest :param all_cells: cell to consider as neighbours :param int k: number of neighbours to be returned :param int max_dist: m...
[ "def", "find_closest_neighbours", "(", "cell", ",", "all_cells", ",", "k", ",", "max_dist", ")", ":", "all_cells", "=", "[", "c", "for", "c", "in", "all_cells", "if", "c", "!=", "cell", "]", "sorted_cells", "=", "sorted", "(", "[", "(", "cell", ".", ...
Find k closest neighbours of the given cell. :param CellFeatures cell: cell of interest :param all_cells: cell to consider as neighbours :param int k: number of neighbours to be returned :param int max_dist: maximal distance in pixels to consider neighbours :return: k closest nei...
[ "Find", "k", "closest", "neighbours", "of", "the", "given", "cell", ".", ":", "param", "CellFeatures", "cell", ":", "cell", "of", "interest", ":", "param", "all_cells", ":", "cell", "to", "consider", "as", "neighbours", ":", "param", "int", "k", ":", "nu...
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/neighmovetrack.py#L252-L265
CellProfiler/centrosome
centrosome/neighmovetrack.py
NeighbourMovementTracking.calculate_basic_cost
def calculate_basic_cost(self, d1, d2): """ Calculates assignment cost between two cells. """ distance = euclidean_dist(d1.center, d2.center) / self.scale area_change = 1 - min(d1.area, d2.area) / max(d1.area, d2.area) return distance + self.parameters_cost_initial["are...
python
def calculate_basic_cost(self, d1, d2): """ Calculates assignment cost between two cells. """ distance = euclidean_dist(d1.center, d2.center) / self.scale area_change = 1 - min(d1.area, d2.area) / max(d1.area, d2.area) return distance + self.parameters_cost_initial["are...
[ "def", "calculate_basic_cost", "(", "self", ",", "d1", ",", "d2", ")", ":", "distance", "=", "euclidean_dist", "(", "d1", ".", "center", ",", "d2", ".", "center", ")", "/", "self", ".", "scale", "area_change", "=", "1", "-", "min", "(", "d1", ".", ...
Calculates assignment cost between two cells.
[ "Calculates", "assignment", "cost", "between", "two", "cells", "." ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/neighmovetrack.py#L267-L275
CellProfiler/centrosome
centrosome/neighmovetrack.py
NeighbourMovementTracking.calculate_localised_cost
def calculate_localised_cost(self, d1, d2, neighbours, motions): """ Calculates assignment cost between two cells taking into account the movement of cells neighbours. :param CellFeatures d1: detection in first frame :param CellFeatures d2: detection in second frame """ ...
python
def calculate_localised_cost(self, d1, d2, neighbours, motions): """ Calculates assignment cost between two cells taking into account the movement of cells neighbours. :param CellFeatures d1: detection in first frame :param CellFeatures d2: detection in second frame """ ...
[ "def", "calculate_localised_cost", "(", "self", ",", "d1", ",", "d2", ",", "neighbours", ",", "motions", ")", ":", "my_nbrs_with_motion", "=", "[", "n", "for", "n", "in", "neighbours", "[", "d1", "]", "if", "n", "in", "motions", "]", "my_motion", "=", ...
Calculates assignment cost between two cells taking into account the movement of cells neighbours. :param CellFeatures d1: detection in first frame :param CellFeatures d2: detection in second frame
[ "Calculates", "assignment", "cost", "between", "two", "cells", "taking", "into", "account", "the", "movement", "of", "cells", "neighbours", "." ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/neighmovetrack.py#L277-L296
CellProfiler/centrosome
centrosome/neighmovetrack.py
NeighbourMovementTracking.calculate_costs
def calculate_costs(self, detections_1, detections_2, calculate_match_cost, params): """ Calculates assignment costs between detections and 'empty' spaces. The smaller cost the better. @param detections_1: cell list of size n in previous frame @param detections_2: cell list of size m in...
python
def calculate_costs(self, detections_1, detections_2, calculate_match_cost, params): """ Calculates assignment costs between detections and 'empty' spaces. The smaller cost the better. @param detections_1: cell list of size n in previous frame @param detections_2: cell list of size m in...
[ "def", "calculate_costs", "(", "self", ",", "detections_1", ",", "detections_2", ",", "calculate_match_cost", ",", "params", ")", ":", "global", "invalid_match", "size_sum", "=", "len", "(", "detections_1", ")", "+", "len", "(", "detections_2", ")", "# Cost matr...
Calculates assignment costs between detections and 'empty' spaces. The smaller cost the better. @param detections_1: cell list of size n in previous frame @param detections_2: cell list of size m in current frame @return: cost matrix (n+m)x(n+m) extended by cost of matching cells with emptines...
[ "Calculates", "assignment", "costs", "between", "detections", "and", "empty", "spaces", ".", "The", "smaller", "cost", "the", "better", "." ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/neighmovetrack.py#L298-L341
CellProfiler/centrosome
centrosome/neighmovetrack.py
NeighbourMovementTracking.solve_assignement
def solve_assignement(self, costs): """ Solves assignment problem using Hungarian implementation by Brian M. Clapper. @param costs: square cost matrix @return: assignment function @rtype: int->int """ if costs is None or len(costs) == 0: return dict...
python
def solve_assignement(self, costs): """ Solves assignment problem using Hungarian implementation by Brian M. Clapper. @param costs: square cost matrix @return: assignment function @rtype: int->int """ if costs is None or len(costs) == 0: return dict...
[ "def", "solve_assignement", "(", "self", ",", "costs", ")", ":", "if", "costs", "is", "None", "or", "len", "(", "costs", ")", "==", "0", ":", "return", "dict", "(", ")", "n", "=", "costs", ".", "shape", "[", "0", "]", "pairs", "=", "[", "(", "i...
Solves assignment problem using Hungarian implementation by Brian M. Clapper. @param costs: square cost matrix @return: assignment function @rtype: int->int
[ "Solves", "assignment", "problem", "using", "Hungarian", "implementation", "by", "Brian", "M", ".", "Clapper", "." ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/neighmovetrack.py#L363-L386
CellProfiler/centrosome
centrosome/smooth.py
smooth_with_noise
def smooth_with_noise(image, bits): """Smooth the image with a per-pixel random multiplier image - the image to perturb bits - the noise is this many bits below the pixel value The noise is random with normal distribution, so the individual pixels get either multiplied or divided by a norm...
python
def smooth_with_noise(image, bits): """Smooth the image with a per-pixel random multiplier image - the image to perturb bits - the noise is this many bits below the pixel value The noise is random with normal distribution, so the individual pixels get either multiplied or divided by a norm...
[ "def", "smooth_with_noise", "(", "image", ",", "bits", ")", ":", "rr", "=", "np", ".", "random", ".", "RandomState", "(", ")", "rr", ".", "seed", "(", "0", ")", "r", "=", "rr", ".", "normal", "(", "size", "=", "image", ".", "shape", ")", "delta",...
Smooth the image with a per-pixel random multiplier image - the image to perturb bits - the noise is this many bits below the pixel value The noise is random with normal distribution, so the individual pixels get either multiplied or divided by a normally distributed # of bits
[ "Smooth", "the", "image", "with", "a", "per", "-", "pixel", "random", "multiplier", "image", "-", "the", "image", "to", "perturb", "bits", "-", "the", "noise", "is", "this", "many", "bits", "below", "the", "pixel", "value", "The", "noise", "is", "random"...
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/smooth.py#L6-L25
CellProfiler/centrosome
centrosome/smooth.py
smooth_with_function_and_mask
def smooth_with_function_and_mask(image, function, mask): """Smooth an image with a linear function, ignoring the contribution of masked pixels image - image to smooth function - a function that takes an image and returns a smoothed image mask - mask with 1's for significant pixels, 0 for masked p...
python
def smooth_with_function_and_mask(image, function, mask): """Smooth an image with a linear function, ignoring the contribution of masked pixels image - image to smooth function - a function that takes an image and returns a smoothed image mask - mask with 1's for significant pixels, 0 for masked p...
[ "def", "smooth_with_function_and_mask", "(", "image", ",", "function", ",", "mask", ")", ":", "not_mask", "=", "np", ".", "logical_not", "(", "mask", ")", "bleed_over", "=", "function", "(", "mask", ".", "astype", "(", "float", ")", ")", "masked_image", "=...
Smooth an image with a linear function, ignoring the contribution of masked pixels image - image to smooth function - a function that takes an image and returns a smoothed image mask - mask with 1's for significant pixels, 0 for masked pixels This function calculates the fractional contributi...
[ "Smooth", "an", "image", "with", "a", "linear", "function", "ignoring", "the", "contribution", "of", "masked", "pixels", "image", "-", "image", "to", "smooth", "function", "-", "a", "function", "that", "takes", "an", "image", "and", "returns", "a", "smoothed...
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/smooth.py#L27-L47
CellProfiler/centrosome
centrosome/smooth.py
circular_gaussian_kernel
def circular_gaussian_kernel(sd,radius): """Create a 2-d Gaussian convolution kernel sd - standard deviation of the gaussian in pixels radius - build a circular kernel that convolves all points in the circle bounded by this radius """ i,j = np.mgrid[-radius:radius+1,-radius:ra...
python
def circular_gaussian_kernel(sd,radius): """Create a 2-d Gaussian convolution kernel sd - standard deviation of the gaussian in pixels radius - build a circular kernel that convolves all points in the circle bounded by this radius """ i,j = np.mgrid[-radius:radius+1,-radius:ra...
[ "def", "circular_gaussian_kernel", "(", "sd", ",", "radius", ")", ":", "i", ",", "j", "=", "np", ".", "mgrid", "[", "-", "radius", ":", "radius", "+", "1", ",", "-", "radius", ":", "radius", "+", "1", "]", ".", "astype", "(", "float", ")", "/", ...
Create a 2-d Gaussian convolution kernel sd - standard deviation of the gaussian in pixels radius - build a circular kernel that convolves all points in the circle bounded by this radius
[ "Create", "a", "2", "-", "d", "Gaussian", "convolution", "kernel", "sd", "-", "standard", "deviation", "of", "the", "gaussian", "in", "pixels", "radius", "-", "build", "a", "circular", "kernel", "that", "convolves", "all", "points", "in", "the", "circle", ...
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/smooth.py#L49-L68
CellProfiler/centrosome
centrosome/smooth.py
fit_polynomial
def fit_polynomial(pixel_data, mask, clip=True): '''Return an "image" which is a polynomial fit to the pixel data Fit the image to the polynomial Ax**2+By**2+Cxy+Dx+Ey+F pixel_data - a two-dimensional numpy array to be fitted mask - a mask of pixels whose intensities should be considered ...
python
def fit_polynomial(pixel_data, mask, clip=True): '''Return an "image" which is a polynomial fit to the pixel data Fit the image to the polynomial Ax**2+By**2+Cxy+Dx+Ey+F pixel_data - a two-dimensional numpy array to be fitted mask - a mask of pixels whose intensities should be considered ...
[ "def", "fit_polynomial", "(", "pixel_data", ",", "mask", ",", "clip", "=", "True", ")", ":", "mask", "=", "np", ".", "logical_and", "(", "mask", ",", "pixel_data", ">", "0", ")", "if", "not", "np", ".", "any", "(", "mask", ")", ":", "return", "pixe...
Return an "image" which is a polynomial fit to the pixel data Fit the image to the polynomial Ax**2+By**2+Cxy+Dx+Ey+F pixel_data - a two-dimensional numpy array to be fitted mask - a mask of pixels whose intensities should be considered in the least squares fit clip...
[ "Return", "an", "image", "which", "is", "a", "polynomial", "fit", "to", "the", "pixel", "data", "Fit", "the", "image", "to", "the", "polynomial", "Ax", "**", "2", "+", "By", "**", "2", "+", "Cxy", "+", "Dx", "+", "Ey", "+", "F", "pixel_data", "-", ...
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/smooth.py#L70-L99
CellProfiler/centrosome
centrosome/threshold.py
get_threshold
def get_threshold(threshold_method, threshold_modifier, image, mask=None, labels = None, threshold_range_min = None, threshold_range_max = None, threshold_correction_factor = 1.0, adaptive_window_size = 10, **kwargs): """Compute a threshold fo...
python
def get_threshold(threshold_method, threshold_modifier, image, mask=None, labels = None, threshold_range_min = None, threshold_range_max = None, threshold_correction_factor = 1.0, adaptive_window_size = 10, **kwargs): """Compute a threshold fo...
[ "def", "get_threshold", "(", "threshold_method", ",", "threshold_modifier", ",", "image", ",", "mask", "=", "None", ",", "labels", "=", "None", ",", "threshold_range_min", "=", "None", ",", "threshold_range_max", "=", "None", ",", "threshold_correction_factor", "=...
Compute a threshold for an image threshold_method - one of the TM_ methods above threshold_modifier - TM_GLOBAL to calculate one threshold over entire image TM_ADAPTIVE to calculate a per-pixel threshold TM_PER_OBJECT to calculate a different threshold for ...
[ "Compute", "a", "threshold", "for", "an", "image", "threshold_method", "-", "one", "of", "the", "TM_", "methods", "above", "threshold_modifier", "-", "TM_GLOBAL", "to", "calculate", "one", "threshold", "over", "entire", "image", "TM_ADAPTIVE", "to", "calculate", ...
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/threshold.py#L64-L153
CellProfiler/centrosome
centrosome/threshold.py
get_global_threshold
def get_global_threshold(threshold_method, image, mask = None, **kwargs): """Compute a single threshold over the whole image""" if mask is not None and not np.any(mask): return 1 if threshold_method == TM_OTSU: fn = get_otsu_threshold elif threshold_method == TM_MOG: fn = ge...
python
def get_global_threshold(threshold_method, image, mask = None, **kwargs): """Compute a single threshold over the whole image""" if mask is not None and not np.any(mask): return 1 if threshold_method == TM_OTSU: fn = get_otsu_threshold elif threshold_method == TM_MOG: fn = ge...
[ "def", "get_global_threshold", "(", "threshold_method", ",", "image", ",", "mask", "=", "None", ",", "*", "*", "kwargs", ")", ":", "if", "mask", "is", "not", "None", "and", "not", "np", ".", "any", "(", "mask", ")", ":", "return", "1", "if", "thresho...
Compute a single threshold over the whole image
[ "Compute", "a", "single", "threshold", "over", "the", "whole", "image" ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/threshold.py#L155-L178
CellProfiler/centrosome
centrosome/threshold.py
get_adaptive_threshold
def get_adaptive_threshold(threshold_method, image, threshold, mask = None, adaptive_window_size = 10, **kwargs): """Given a global threshold, compute a threshold per pixel Break the image into blocks, computing the thres...
python
def get_adaptive_threshold(threshold_method, image, threshold, mask = None, adaptive_window_size = 10, **kwargs): """Given a global threshold, compute a threshold per pixel Break the image into blocks, computing the thres...
[ "def", "get_adaptive_threshold", "(", "threshold_method", ",", "image", ",", "threshold", ",", "mask", "=", "None", ",", "adaptive_window_size", "=", "10", ",", "*", "*", "kwargs", ")", ":", "# for the X and Y direction, find the # of blocks, given the", "# size constra...
Given a global threshold, compute a threshold per pixel Break the image into blocks, computing the threshold per block. Afterwards, constrain the block threshold to .7 T < t < 1.5 T. Block sizes must be at least 50x50. Images > 500 x 500 get 10x10 blocks.
[ "Given", "a", "global", "threshold", "compute", "a", "threshold", "per", "pixel", "Break", "the", "image", "into", "blocks", "computing", "the", "threshold", "per", "block", ".", "Afterwards", "constrain", "the", "block", "threshold", "to", ".", "7", "T", "<...
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/threshold.py#L180-L247
CellProfiler/centrosome
centrosome/threshold.py
get_per_object_threshold
def get_per_object_threshold(method, image, threshold, mask=None, labels=None, threshold_range_min = None, threshold_range_max = None, **kwargs): """Return a matrix giving threshold per pixel calculated per-object image ...
python
def get_per_object_threshold(method, image, threshold, mask=None, labels=None, threshold_range_min = None, threshold_range_max = None, **kwargs): """Return a matrix giving threshold per pixel calculated per-object image ...
[ "def", "get_per_object_threshold", "(", "method", ",", "image", ",", "threshold", ",", "mask", "=", "None", ",", "labels", "=", "None", ",", "threshold_range_min", "=", "None", ",", "threshold_range_max", "=", "None", ",", "*", "*", "kwargs", ")", ":", "if...
Return a matrix giving threshold per pixel calculated per-object image - image to be thresholded mask - mask out "don't care" pixels labels - a label mask indicating object boundaries threshold - the global threshold
[ "Return", "a", "matrix", "giving", "threshold", "per", "pixel", "calculated", "per", "-", "object", "image", "-", "image", "to", "be", "thresholded", "mask", "-", "mask", "out", "don", "t", "care", "pixels", "labels", "-", "a", "label", "mask", "indicating...
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/threshold.py#L249-L274
CellProfiler/centrosome
centrosome/threshold.py
get_mog_threshold
def get_mog_threshold(image, mask=None, object_fraction = 0.2): """Compute a background using a mixture of gaussians This function finds a suitable threshold for the input image Block. It assumes that the pixels in the image belong to either a background class or an object class. 'pObject' is a...
python
def get_mog_threshold(image, mask=None, object_fraction = 0.2): """Compute a background using a mixture of gaussians This function finds a suitable threshold for the input image Block. It assumes that the pixels in the image belong to either a background class or an object class. 'pObject' is a...
[ "def", "get_mog_threshold", "(", "image", ",", "mask", "=", "None", ",", "object_fraction", "=", "0.2", ")", ":", "cropped_image", "=", "np", ".", "array", "(", "image", ".", "flat", ")", "if", "mask", "is", "None", "else", "image", "[", "mask", "]", ...
Compute a background using a mixture of gaussians This function finds a suitable threshold for the input image Block. It assumes that the pixels in the image belong to either a background class or an object class. 'pObject' is an initial guess of the prior probability of an object pixel, or equ...
[ "Compute", "a", "background", "using", "a", "mixture", "of", "gaussians", "This", "function", "finds", "a", "suitable", "threshold", "for", "the", "input", "image", "Block", ".", "It", "assumes", "that", "the", "pixels", "in", "the", "image", "belong", "to",...
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/threshold.py#L304-L432
CellProfiler/centrosome
centrosome/threshold.py
get_background_threshold
def get_background_threshold(image, mask = None): """Get threshold based on the mode of the image The threshold is calculated by calculating the mode and multiplying by 2 (an arbitrary empirical factor). The user will presumably adjust the multiplication factor as needed.""" cropped_image = np.array...
python
def get_background_threshold(image, mask = None): """Get threshold based on the mode of the image The threshold is calculated by calculating the mode and multiplying by 2 (an arbitrary empirical factor). The user will presumably adjust the multiplication factor as needed.""" cropped_image = np.array...
[ "def", "get_background_threshold", "(", "image", ",", "mask", "=", "None", ")", ":", "cropped_image", "=", "np", ".", "array", "(", "image", ".", "flat", ")", "if", "mask", "is", "None", "else", "image", "[", "mask", "]", "if", "np", ".", "product", ...
Get threshold based on the mode of the image The threshold is calculated by calculating the mode and multiplying by 2 (an arbitrary empirical factor). The user will presumably adjust the multiplication factor as needed.
[ "Get", "threshold", "based", "on", "the", "mode", "of", "the", "image", "The", "threshold", "is", "calculated", "by", "calculating", "the", "mode", "and", "multiplying", "by", "2", "(", "an", "arbitrary", "empirical", "factor", ")", ".", "The", "user", "wi...
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/threshold.py#L436-L468
CellProfiler/centrosome
centrosome/threshold.py
get_robust_background_threshold
def get_robust_background_threshold(image, mask = None, lower_outlier_fraction = 0.05, upper_outlier_fraction = 0.05, deviations_above_average = 2.0, ...
python
def get_robust_background_threshold(image, mask = None, lower_outlier_fraction = 0.05, upper_outlier_fraction = 0.05, deviations_above_average = 2.0, ...
[ "def", "get_robust_background_threshold", "(", "image", ",", "mask", "=", "None", ",", "lower_outlier_fraction", "=", "0.05", ",", "upper_outlier_fraction", "=", "0.05", ",", "deviations_above_average", "=", "2.0", ",", "average_fn", "=", "np", ".", "mean", ",", ...
Calculate threshold based on mean & standard deviation The threshold is calculated by trimming the top and bottom 5% of pixels off the image, then calculating the mean and standard deviation of the remaining image. The threshold is then set at 2 (empirical value) standard deviations above th...
[ "Calculate", "threshold", "based", "on", "mean", "&", "standard", "deviation", "The", "threshold", "is", "calculated", "by", "trimming", "the", "top", "and", "bottom", "5%", "of", "pixels", "off", "the", "image", "then", "calculating", "the", "mean", "and", ...
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/threshold.py#L472-L515
CellProfiler/centrosome
centrosome/threshold.py
mad
def mad(a): '''Calculate the median absolute deviation of a sample a - a numpy array-like collection of values returns the median of the deviation of a from its median. ''' a = np.asfarray(a).flatten() return np.median(np.abs(a - np.median(a)))
python
def mad(a): '''Calculate the median absolute deviation of a sample a - a numpy array-like collection of values returns the median of the deviation of a from its median. ''' a = np.asfarray(a).flatten() return np.median(np.abs(a - np.median(a)))
[ "def", "mad", "(", "a", ")", ":", "a", "=", "np", ".", "asfarray", "(", "a", ")", ".", "flatten", "(", ")", "return", "np", ".", "median", "(", "np", ".", "abs", "(", "a", "-", "np", ".", "median", "(", "a", ")", ")", ")" ]
Calculate the median absolute deviation of a sample a - a numpy array-like collection of values returns the median of the deviation of a from its median.
[ "Calculate", "the", "median", "absolute", "deviation", "of", "a", "sample", "a", "-", "a", "numpy", "array", "-", "like", "collection", "of", "values", "returns", "the", "median", "of", "the", "deviation", "of", "a", "from", "its", "median", "." ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/threshold.py#L520-L528
CellProfiler/centrosome
centrosome/threshold.py
binned_mode
def binned_mode(a): '''Calculate a binned mode of a sample a - array of values This routine bins the sample into np.sqrt(len(a)) bins. This is a number that is a compromise between fineness of measurement and the stochastic nature of counting which roughly scales as the square root of ...
python
def binned_mode(a): '''Calculate a binned mode of a sample a - array of values This routine bins the sample into np.sqrt(len(a)) bins. This is a number that is a compromise between fineness of measurement and the stochastic nature of counting which roughly scales as the square root of ...
[ "def", "binned_mode", "(", "a", ")", ":", "a", "=", "np", ".", "asarray", "(", "a", ")", ".", "flatten", "(", ")", "a_min", "=", "np", ".", "min", "(", "a", ")", "a_max", "=", "np", ".", "max", "(", "a", ")", "n_bins", "=", "np", ".", "ceil...
Calculate a binned mode of a sample a - array of values This routine bins the sample into np.sqrt(len(a)) bins. This is a number that is a compromise between fineness of measurement and the stochastic nature of counting which roughly scales as the square root of the sample size.
[ "Calculate", "a", "binned", "mode", "of", "a", "sample", "a", "-", "array", "of", "values", "This", "routine", "bins", "the", "sample", "into", "np", ".", "sqrt", "(", "len", "(", "a", "))", "bins", ".", "This", "is", "a", "number", "that", "is", "...
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/threshold.py#L530-L546
CellProfiler/centrosome
centrosome/threshold.py
get_ridler_calvard_threshold
def get_ridler_calvard_threshold(image, mask = None): """Find a threshold using the method of Ridler and Calvard The reference for this method is: "Picture Thresholding Using an Iterative Selection Method" by T. Ridler and S. Calvard, in IEEE Transactions on Systems, Man and Cybernetics, vol. ...
python
def get_ridler_calvard_threshold(image, mask = None): """Find a threshold using the method of Ridler and Calvard The reference for this method is: "Picture Thresholding Using an Iterative Selection Method" by T. Ridler and S. Calvard, in IEEE Transactions on Systems, Man and Cybernetics, vol. ...
[ "def", "get_ridler_calvard_threshold", "(", "image", ",", "mask", "=", "None", ")", ":", "cropped_image", "=", "np", ".", "array", "(", "image", ".", "flat", ")", "if", "mask", "is", "None", "else", "image", "[", "mask", "]", "if", "np", ".", "product"...
Find a threshold using the method of Ridler and Calvard The reference for this method is: "Picture Thresholding Using an Iterative Selection Method" by T. Ridler and S. Calvard, in IEEE Transactions on Systems, Man and Cybernetics, vol. 8, no. 8, August 1978.
[ "Find", "a", "threshold", "using", "the", "method", "of", "Ridler", "and", "Calvard", "The", "reference", "for", "this", "method", "is", ":", "Picture", "Thresholding", "Using", "an", "Iterative", "Selection", "Method", "by", "T", ".", "Ridler", "and", "S", ...
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/threshold.py#L548-L582
CellProfiler/centrosome
centrosome/threshold.py
get_kapur_threshold
def get_kapur_threshold(image, mask=None): """The Kapur, Sahoo, & Wong method of thresholding, adapted to log-space.""" cropped_image = np.array(image.flat) if mask is None else image[mask] if np.product(cropped_image.shape)<3: return 0 if np.min(cropped_image) == np.max(cropped_image): ...
python
def get_kapur_threshold(image, mask=None): """The Kapur, Sahoo, & Wong method of thresholding, adapted to log-space.""" cropped_image = np.array(image.flat) if mask is None else image[mask] if np.product(cropped_image.shape)<3: return 0 if np.min(cropped_image) == np.max(cropped_image): ...
[ "def", "get_kapur_threshold", "(", "image", ",", "mask", "=", "None", ")", ":", "cropped_image", "=", "np", ".", "array", "(", "image", ".", "flat", ")", "if", "mask", "is", "None", "else", "image", "[", "mask", "]", "if", "np", ".", "product", "(", ...
The Kapur, Sahoo, & Wong method of thresholding, adapted to log-space.
[ "The", "Kapur", "Sahoo", "&", "Wong", "method", "of", "thresholding", "adapted", "to", "log", "-", "space", "." ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/threshold.py#L587-L625
CellProfiler/centrosome
centrosome/threshold.py
get_maximum_correlation_threshold
def get_maximum_correlation_threshold(image, mask = None, bins = 256): '''Return the maximum correlation threshold of the image image - image to be thresholded mask - mask of relevant pixels bins - # of value bins to use This is an implementation of the maximum correlation thresh...
python
def get_maximum_correlation_threshold(image, mask = None, bins = 256): '''Return the maximum correlation threshold of the image image - image to be thresholded mask - mask of relevant pixels bins - # of value bins to use This is an implementation of the maximum correlation thresh...
[ "def", "get_maximum_correlation_threshold", "(", "image", ",", "mask", "=", "None", ",", "bins", "=", "256", ")", ":", "if", "mask", "is", "not", "None", ":", "image", "=", "image", "[", "mask", "]", "image", "=", "image", ".", "ravel", "(", ")", "nm...
Return the maximum correlation threshold of the image image - image to be thresholded mask - mask of relevant pixels bins - # of value bins to use This is an implementation of the maximum correlation threshold as described in Padmanabhan, "A novel algorithm for optimal image thre...
[ "Return", "the", "maximum", "correlation", "threshold", "of", "the", "image", "image", "-", "image", "to", "be", "thresholded", "mask", "-", "mask", "of", "relevant", "pixels", "bins", "-", "#", "of", "value", "bins", "to", "use", "This", "is", "an", "im...
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/threshold.py#L629-L686
CellProfiler/centrosome
centrosome/threshold.py
weighted_variance
def weighted_variance(image, mask, binary_image): """Compute the log-transformed variance of foreground and background image - intensity image used for thresholding mask - mask of ignored pixels binary_image - binary image marking foreground and background """ if not np.any(mask):...
python
def weighted_variance(image, mask, binary_image): """Compute the log-transformed variance of foreground and background image - intensity image used for thresholding mask - mask of ignored pixels binary_image - binary image marking foreground and background """ if not np.any(mask):...
[ "def", "weighted_variance", "(", "image", ",", "mask", ",", "binary_image", ")", ":", "if", "not", "np", ".", "any", "(", "mask", ")", ":", "return", "0", "#", "# Clamp the dynamic range of the foreground", "#", "minval", "=", "np", ".", "max", "(", "image...
Compute the log-transformed variance of foreground and background image - intensity image used for thresholding mask - mask of ignored pixels binary_image - binary image marking foreground and background
[ "Compute", "the", "log", "-", "transformed", "variance", "of", "foreground", "and", "background", "image", "-", "intensity", "image", "used", "for", "thresholding", "mask", "-", "mask", "of", "ignored", "pixels", "binary_image", "-", "binary", "image", "marking"...
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/threshold.py#L691-L718
CellProfiler/centrosome
centrosome/threshold.py
sum_of_entropies
def sum_of_entropies(image, mask, binary_image): """Bin the foreground and background pixels and compute the entropy of the distribution of points among the bins """ mask=mask.copy() mask[np.isnan(image)] = False if not np.any(mask): return 0 # # Clamp the dynamic range of the f...
python
def sum_of_entropies(image, mask, binary_image): """Bin the foreground and background pixels and compute the entropy of the distribution of points among the bins """ mask=mask.copy() mask[np.isnan(image)] = False if not np.any(mask): return 0 # # Clamp the dynamic range of the f...
[ "def", "sum_of_entropies", "(", "image", ",", "mask", ",", "binary_image", ")", ":", "mask", "=", "mask", ".", "copy", "(", ")", "mask", "[", "np", ".", "isnan", "(", "image", ")", "]", "=", "False", "if", "not", "np", ".", "any", "(", "mask", ")...
Bin the foreground and background pixels and compute the entropy of the distribution of points among the bins
[ "Bin", "the", "foreground", "and", "background", "pixels", "and", "compute", "the", "entropy", "of", "the", "distribution", "of", "points", "among", "the", "bins" ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/threshold.py#L720-L782
CellProfiler/centrosome
centrosome/threshold.py
log_transform
def log_transform(image): '''Renormalize image intensities to log space Returns a tuple of transformed image and a dictionary to be passed into inverse_log_transform. The minimum and maximum from the dictionary can be applied to an image by the inverse_log_transform to convert it back to its f...
python
def log_transform(image): '''Renormalize image intensities to log space Returns a tuple of transformed image and a dictionary to be passed into inverse_log_transform. The minimum and maximum from the dictionary can be applied to an image by the inverse_log_transform to convert it back to its f...
[ "def", "log_transform", "(", "image", ")", ":", "orig_min", ",", "orig_max", "=", "scipy", ".", "ndimage", ".", "extrema", "(", "image", ")", "[", ":", "2", "]", "#", "# We add 1/2 bit noise to an 8 bit image to give the log a bottom", "#", "limage", "=", "image...
Renormalize image intensities to log space Returns a tuple of transformed image and a dictionary to be passed into inverse_log_transform. The minimum and maximum from the dictionary can be applied to an image by the inverse_log_transform to convert it back to its former intensity values.
[ "Renormalize", "image", "intensities", "to", "log", "space", "Returns", "a", "tuple", "of", "transformed", "image", "and", "a", "dictionary", "to", "be", "passed", "into", "inverse_log_transform", ".", "The", "minimum", "and", "maximum", "from", "the", "dictiona...
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/threshold.py#L784-L804
CellProfiler/centrosome
centrosome/threshold.py
numpy_histogram
def numpy_histogram(a, bins=10, range=None, normed=False, weights=None): '''A version of numpy.histogram that accounts for numpy's version''' args = inspect.getargs(np.histogram.__code__)[0] if args[-1] == "new": return np.histogram(a, bins, range, normed, weights, new=True) return np.histogram(...
python
def numpy_histogram(a, bins=10, range=None, normed=False, weights=None): '''A version of numpy.histogram that accounts for numpy's version''' args = inspect.getargs(np.histogram.__code__)[0] if args[-1] == "new": return np.histogram(a, bins, range, normed, weights, new=True) return np.histogram(...
[ "def", "numpy_histogram", "(", "a", ",", "bins", "=", "10", ",", "range", "=", "None", ",", "normed", "=", "False", ",", "weights", "=", "None", ")", ":", "args", "=", "inspect", ".", "getargs", "(", "np", ".", "histogram", ".", "__code__", ")", "[...
A version of numpy.histogram that accounts for numpy's version
[ "A", "version", "of", "numpy", ".", "histogram", "that", "accounts", "for", "numpy", "s", "version" ]
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/threshold.py#L814-L819
CellProfiler/centrosome
centrosome/rankorder.py
rank_order
def rank_order(image, nbins=None): """Return an image of the same shape where each pixel has the rank-order value of the corresponding pixel in the image. The returned image's elements are of type np.uint32 which simplifies processing in C code. """ flat_image = image.ravel() sort_order = fl...
python
def rank_order(image, nbins=None): """Return an image of the same shape where each pixel has the rank-order value of the corresponding pixel in the image. The returned image's elements are of type np.uint32 which simplifies processing in C code. """ flat_image = image.ravel() sort_order = fl...
[ "def", "rank_order", "(", "image", ",", "nbins", "=", "None", ")", ":", "flat_image", "=", "image", ".", "ravel", "(", ")", "sort_order", "=", "flat_image", ".", "argsort", "(", ")", ".", "astype", "(", "np", ".", "uint32", ")", "flat_image", "=", "f...
Return an image of the same shape where each pixel has the rank-order value of the corresponding pixel in the image. The returned image's elements are of type np.uint32 which simplifies processing in C code.
[ "Return", "an", "image", "of", "the", "same", "shape", "where", "each", "pixel", "has", "the", "rank", "-", "order", "value", "of", "the", "corresponding", "pixel", "in", "the", "image", ".", "The", "returned", "image", "s", "elements", "are", "of", "typ...
train
https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/rankorder.py#L4-L61