Created
February 14, 2019 10:33
-
-
Save thomasaarholt/00c223f579d28af921a28574e5dd2ddf to your computer and use it in GitHub Desktop.
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
def border_elems(image_2d, pixels=1): # Input array : a, Edgewidth : W | |
n = image_2d.shape[0] | |
r = np.minimum(np.arange(n)[::-1], np.arange(n)) | |
return image_2d[np.minimum(r[:,None],r)<pixels] | |
def remove_integrated_edge_cells(i_points, i_record, p_record, | |
pixels=1, inplace=False): | |
''' | |
Removes any cells that touch within a number of pixels of | |
the image border. | |
Parameters: | |
Returns: | |
(if inplace==False): | |
i_points : | |
i_record : | |
p_record : | |
''' | |
if not inplace: | |
i_points = i_points.copy(), | |
i_record = i_record.deepcopy() | |
p_record = p_record.copy() | |
border = border_elems(p_record, pixels) | |
border_indices = np.array(list(set(border))) | |
indices = np.in1d(p_record, border_indices).reshape(p_record.shape) | |
i[border_indices] = np.nan | |
i_record.data[indices_of_edge_cell] = np.nan | |
p_record[indices_of_edge_cell] = -1 | |
if not inplace: | |
return i_points, i_record, p_record | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment