pycellfit package

Submodules

pycellfit.utils module

Top-level utility functions for pycellfit module.

pycellfit.utils.read_segmented_image(file_name, visualize=False)[source]

Displays the segmented image using matplotlib

Parameters:
  • file_name (str) – file name of a segmented image in .tif format
  • visualize (bool) – if true, then image will be plotted using matplotlib.pyplot
Raises:

TypeError – only accepts tif/tiff files as input

Returns:

array of pixel values

Return type:

numpy.ndarray

pycellfit.junction module

class pycellfit.junction.Junction(coordinates, cells_set)[source]

Bases: object

add_edge(edge_label)[source]

Adds edge label to set of edge labels

cell_labels
coordinates
degree
edges

set of labels of edges connected to this node

id_iter = count(0)
plot(label=False)[source]
plot_unit_vectors()[source]
remove_edge(edge_label)[source]

Remove an edge and tension vector connected to this node

Parameters:
  • self
  • edge_label
tension_vectors

returns list of Tension vectors connected to this node

x
y

pycellfit.edge module

class pycellfit.edge.Edge(start_node, end_node, intermediate_points, cells)[source]

Bases: object

angular_position(coordinates)[source]

given a (x,y) coordinate, the angular position in radians from 0 to 2*pi around the fit circle is returned

Parameters:coordinates
Returns:
calculate_edge_points()[source]
center
circle_fit()[source]
corresponding_tension_vector
cw_around_circle

true if the edge (start_node to end_node) goes clockwise around the fit circle, false if ccw

Returns:
end_node
end_tangent_angle(method='chord')[source]
id_iter = count(0)
length
linear
location
map_unit_vectors_to_junctions()[source]
outside(background)[source]
plot(label=False)[source]
plot_circle()[source]
plot_tangent(c='y')[source]
radius
split_line_multiple(length=None, n_pieces=None)[source]

Splits a ogr wkbLineString into multiple sub-strings, either of a specified <<length>> or a specified <<n_pieces>>.

line should be an ogr LineString Geometry Length should be a float or int. n_pieces should be an int. Either length or n_pieces should be specified.

Returns a list of ogr wkbLineString Geometries.

split_line_single(line, length)[source]

Returns two ogr line geometries, one which is the first length <<length>> of <<line>>, and one one which is the remainder.

line should be a ogr LineString Geometry. length should be an integer or float.

start_node
start_tangent_angle(method='chord')[source]
xc
yc
pycellfit.edge.collinear(points, epsilon=0.01)[source]

determine if three points are collinear

Parameters:
  • epsilon
  • points (list of 3 2-member tuples) – list of 3 point tuples that might be collinear
Returns:

boolean to tell if the points are collinear or not

Return type:

bool

pycellfit.edge.distance(p1, p2)[source]

pycellfit.tension_vector module

pycellfit.cell module

class pycellfit.cell.Cell(pixel_value)[source]

Bases: object

add_edge_point(edge_point, neighboring_cell_label)[source]
approximate_cell_center()[source]

approximates the coordinates of the center of the cell by averaging the coordinates of points on the perimeter (edge) of the cell

Returns:approximate center of the cell
Return type:tuple
generate_maze(neighboring_cell_label)[source]
label

the label of a Cell is it’s unique pixel value. It is assigned when the Cell object is created.

Returns:
make_edges(master_set)[source]
neighboring_cell_labels
number_of_edge_points

returns the number of edge points in edge_point_list

Returns:number of edge points
plot()[source]

pycellfit.mesh module

class pycellfit.mesh.Mesh(array_of_pixels)[source]

Bases: object

add_cell(cell_pixel_value)[source]
add_edge_points_and_junctions(array_of_pixels)[source]
circle_fit_all_edges()[source]
find_cells_from_array()[source]
generate_mesh(average_nodes_per_edge=4)[source]
make_edges_for_all_cells()[source]
number_of_cells

returns the number of cells in the mesh

Returns:number of cells in mesh
Return type:int
number_of_edges

returns the number of edges in the mesh

Returns:number of edges in the mesh
Return type:int
number_of_junctions

returns the number of junctions in the mesh

Returns:number of junctions in the mesh
Return type:int
number_of_quad_junctions

returns the number of quad junctions in the mesh

Returns:number of edges in the mesh
Return type:int
number_of_triple_junctions

counts and outputs the number of triple junctions in the mesh

:return number of triple junctions in mesh :rtype: int

plot()[source]
plot_tensions()[source]
remove_cell(cell_pixel_value)[source]
solve_tensions()[source]
solve_tensions_new()[source]
solve_tensions_new2()[source]

pycellfit.constrained_circle_fit module

pycellfit.circle_fit_helpers module

pycellfit.segmentation_transform module

functions to convert between watershed and skeleton segmented images

pycellfit.segmentation_transform.skeleton_to_watershed(skeleton_image_array, region_value=0, boundary_value=255, keep_boundaries=False)[source]

converts a segmented skeleton image (all regions are same value with region boundaries being a second value) to a watershed segmented image (each region has a unique value and there are no boundary pixels, background region has value of zero)

Parameters:
  • skeleton_image_array (np.ndarray) – 2D numpy array with pixel values of a skeleton segmented image
  • region_value (float) – value of pixels in regions in skeleton_segmented images (default is 0)
  • boundary_value (float) – value of boundary pixels of regions in skeleton_segmented images (default is 255)
  • keep_boundaries (bool) – if True, watershed image will keep boundaries in returned result
Returns:

watershed_image_array

Rtype watershed_image_array:
 

np.ndarray

pycellfit.segmentation_transform.watershed_to_skeleton(watershed_image_array, region_value=0, boundary_value=255)[source]

converts a watershed segmented image (no boundaries between regions and each region has a different pixel value, background region has value of zero) to a skeleton segmented image (each region has the same pixel value and are separated by boundaries of a second value)

Parameters:
  • watershed_image_array (numpy.ndarray) – 2D numpy array with pixel values of a watershed segmented image
  • region_value (float) – desired value of all regions in the output (skeleton segmented) array
  • boundary_value (float) – desired value of boundary pixels in the output (skeleton segmented) array
Returns:

skeleton_image_array

Rtype skeleton_image_array:
 

np.ndarray

pycellfit.segmentation_transform_utils module

pycellfit.segmentation_transform_utils.fill_region(array_of_pixels, position, new_value)[source]

fills a region of a 2D numpy array with the same value

Parameters:
  • array_of_pixels (np.ndarray) – 2D numpy array of all pixel values
  • position (tuple) – tuple with (row, col) location of pixel in the region to modify
  • new_value (float) – new value for pixel at position and all pixels in same region
Returns:

None

pycellfit.segmentation_transform_utils.pad_with(vector, pad_width, iaxis, kwargs)[source]

helper function that is called by np.pad to surround a nparray with a constant value Example: [[0,0],[0,0]] becomes [[-1,-1,-1, -1],[-1, 0, 0, -1],[-1, 0, 0, -1],[-1,-1,-1, -1]]

Module contents