def closest_objects(labeled,n_cpu=1): from ops.process import feature_table from scipy.spatial import cKDTree features = { 'i' : lambda r: r.centroid[0], 'j' : lambda r: r.centroid[1], 'label' : lambda r: r.label } df = feature_table(labeled,labeled,features) kdt = cKDTree(df[['i','j']]) distances,indexes = kdt.query(df[['i','j']],3,n_jobs=n_cpu) df['first_neighbor'],df['first_neighbor_distance'] = indexes[:,1],distances[:,1] df['second_neighbor'],df['second_neighbor_distance'] = indexes[:,2],distances[:,2] first_neighbors = df[['i','j']].values[df['first_neighbor'].values] second_neighbors = df[['i','j']].values[df['second_neighbor'].values] angles = [angle(v,p0,p1) for v,p0,p1 in zip(df[['i','j']].values,first_neighbors,second_neighbors)] df['angle_between_neighbors'] = np.array(angles)*(180/np.pi) return df.drop(columns=['i','j']).set_index('label')
def _extract_features(data, labels, wildcards, features=None): """Extracts features in dictionary and combines with generic region features. """ from ops.process import feature_table from ops.features import features_basic features = features.copy() if features else dict() features.update(features_basic) df = feature_table(data, labels, features) for k, v in sorted(wildcards.items()): df[k] = v return df
def _extract_features_bare(data, labels, features=None, wildcards=None,**kwargs): """Extracts features in dictionary and combines with generic region features. """ from ops.process import feature_table features = features.copy() if features else dict() features.update({'label': lambda r: r.label}) df = feature_table(data, labels, features) if wildcards is not None: for k,v in sorted(wildcards.items()): df[k] = v return df
filetypes=(("image files","*.tif"), ("all files","*.*") ) ) ) root_2.destroy() _,ext_2= splitext(filename_2) if ext_2 not in image_ext: raise Exception('intensity image file must be .tif or .tiff') else: img_file = filename_2 img_labels = read(label_file) df = (feature_table(img_labels, img_labels, features_basic) .assign(label_file=label_file,img_file=img_file) ) else: table_file = filename_1 raise Exception('input table file must be .csv or .hdf') elif len(sys.argv) == 2: filename_1 = sys.argv[1] _,ext_1= splitext(filename_1) if ext_1 not in table_ext: raise Exception('input table file must be .csv or .hdf') else: table_file = filename_1 df = pd.read_hdf(table_file) elif len(sys.argv) > 2: