Exemplo n.º 1
0
def normalized_distance_to_center(filled_image):
	"""regions outside of labeled image have normalized distance of 1"""

	distance_to_edge = distance_transform(np.pad(filled_image,1,'constant'))[1:-1,1:-1]

	max_distance = distance_to_edge.max()

	# median of all points furthest from edge
	center = tuple(np.median(np.where(distance_to_edge==max_distance),axis=1).astype(int))

	mask = np.ones(filled_image.shape)
	mask[center[0],center[1]] = 0

	distance_to_center = distance_transform(mask)

	return distance_to_center/(distance_to_center+distance_to_edge),center
Exemplo n.º 2
0
	GT_FMT = imset.lower()+'_%06d_pixeltruth.mat'
	GT_MAT_NAME = 'truth_img'

	res = .5
	nb = int(50./res)
	dist_hist = np.zeros((nb), dtype=np.uint64)

	for idx in range(1, num_img+1):
		logit_im = loadmat(join(PRED_PATH, LOGIT_FMT % idx))[LOGIT_MAT_NAME][...,1:].reshape(-1, num_classes)
		gt = loadmat(join(GT_PATH, GT_FMT % idx))[GT_MAT_NAME]
		
		fg = np.ones_like(gt)
		fg[(gt==0) | (gt==255)] = 0
		#weightmap = np.minimum(20, distance_transform(fg)).ravel()/20.
		weightmap = distance_transform(fg).ravel()
	
		for i, (tr, logits) in enumerate(zip(gt.ravel(), logit_im)):
			if tr == bg_class or tr == 255: continue
			
			pred = np.argmax(logits)
			if tr-1 == pred: continue
			
			dist_hist[min(int(np.floor(min(weightmap[i], 50)/res)), nb-1)] += 1
		
	savemat('incorr_dist_hist.mat', {'dist_hist': dist_hist})
else:
	dist_hist = loadmat('incorr_dist_hist.mat')['dist_hist']
	
	
import matplotlib.pyplot as plt
Exemplo n.º 3
0
shape_features = {
	'area'    : lambda r: r.area,
	'perimeter' : lambda r: r.perimeter,
	'form_factor': lambda r:4*np.pi*r.area/(r.perimeter)**2, #isoperimetric quotient
	'solidity': lambda r: r.solidity,
	'extent': lambda r: r.extent,
	'euler_number': lambda r: r.euler_number,
	'centroid_r': lambda r: r.local_centroid[0], # ACTUALLY SHOULD BE POINT FARTHEST FROM EDGE?
	'centroid_c': lambda r: r.local_centroid[1], # ACTUALLY SHOULD BE POINT FARTHEST FROM EDGE?
	'eccentricity': lambda r: r.eccentricity,
	'major_axis' : lambda r: r.major_axis_length,
    'minor_axis' : lambda r: r.minor_axis_length,
    'orientation' : lambda r: r.orientation,
    'compactness' : lambda r: 2*np.pi*(r.moments_central[0,2]+r.moments_central[2,0])/(r.area**2),
    'max_radius' : lambda r: distance_transform(np.pad(r.filled_image,1,'constant')).max(), #filled_image or image?
    'median_radius' : lambda r: np.median(distance_transform(np.pad(r.filled_image,1,'constant'))[1:-1,1:-1][r.filled_image]), #filled_image or image?
    'mean_radius' : lambda r: distance_transform(np.pad(r.filled_image,1,'constant'))[1:-1,1:-1][r.filled_image].mean(), #filled_image or image?
    'feret_diameter' : lambda r: min_max_feret_diameter(r.coords),
    # 'min_feret' : lambda r: minimum_feret_diameter(r.coords),
    # 'max_feret' : lambda r: maximum_feret_diameter(r.coords),
    'zernike' : lambda r: zernike_minimum_enclosing_circle(r.coords, degree=ZERNIKE_DEGREE) # cp/centrosome zernike divides zernike magnitudes by minimum enclosing circle magnitude; unclear why
}

zernike_nums = ['zernike_'+str(radial)+'_'+str(azimuthal) 
for radial in range(ZERNIKE_DEGREE+1) 
for azimuthal in range(radial%2,radial+2,2)]

shape_columns = {'zernike_'+str(num):zernike_num for num,zernike_num in enumerate(zernike_nums)}
shape_columns.update({
	'feret_diameter_0':'min_feret_diameter',
def max_median_mean_radius(filled_image):
    transformed = distance_transform(np.pad(filled_image, 1,
                                            'constant'))[1:-1,
                                                         1:-1][filled_image]

    return (transformed.max(), np.median(transformed), transformed.mean())