Created
November 14, 2017 18:30
-
-
Save nrweir/8bfebae67ea1cca1833f49ec3b565828 to your computer and use it in GitHub Desktop.
For matching parent cells to foci in an image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# c_foci = an array with numbers indicating where foci are (e.g. all voxels corresponding to focus #1 = 1, all vx corresp to foci #2 = 2, etc.) | |
# segmented_cells = an array with #s indicating where cells are, same format as c_foci | |
# x = focus ID that is being checked for parent cells | |
if verbose: | |
print('current ID: ' + str(x)) | |
parent_cell, cell_cts = np.unique( | |
self.segmented_cells[i][c_foci == x], | |
return_counts=True | |
) | |
cell_cts = cell_cts[parent_cell != 0] # rm bgrd | |
parent_cell = parent_cell[parent_cell != 0] # rm bgrd | |
if verbose: | |
print(' overlapping parent cell(s): ') | |
print(parent_cell) | |
print(' # of pixels overlapping with parent(s):') | |
print(cell_cts) | |
if parent_cell.size > 1: # if part of >1 cell | |
# assign to cell containing more of the focus's px | |
if verbose: | |
print(' more than one overlapping cell.') | |
print(' determining which cell overlaps more.') | |
parent_cell = parent_cell[np.argmax(cell_cts)] | |
if verbose: | |
print(' parent cell: ' + str(parent_cell)) | |
elif parent_cell.size == 1: | |
if verbose: | |
print('matched to one parent cell.') | |
parent_cell = parent_cell[0] # extract value from arr |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment