本文整理汇总了Python中skimage.morphology.medial_axis函数的典型用法代码示例。如果您正苦于以下问题:Python medial_axis函数的具体用法?Python medial_axis怎么用?Python medial_axis使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了medial_axis函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: convert_binary_image_to_sdf
def convert_binary_image_to_sdf(self, binary_img, vis = False):
binary_data = np.array(binary_img)
skel, sdf_in = morph.medial_axis(binary_data, return_distance = True)
useless_skel, sdf_out = morph.medial_axis(self.upper_bound_ - binary_data, return_distance = True)
sdf = sdf_out - sdf_in
# display the sdf and skeleton
if vis:
dist_on_skel = sdf * skel
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(8, 4))
ax1.imshow(binary_data, cmap=plt.cm.gray, interpolation='nearest')
ax1.axis('off')
ax2.imshow(dist_on_skel, cmap=plt.cm.spectral, interpolation='nearest')
ax2.contour(binary_data, [0.5], colors='w')
ax2.axis('off')
fig.subplots_adjust(hspace=0.01, wspace=0.01, top=1, bottom=0, left=0, right=1)
plt.show()
plt.imshow(sdf)
plt.show()
plt.imshow(skel)
plt.show()
return sdf, skel
开发者ID:brianhou,项目名称:GPIS,代码行数:28,代码来源:triangulate_silhouette.py
示例2: run
def run(self):
print 'Gerando Caracteristicas....'
images = self.__image_list(image_path('circinatum'), image_path('kelloggii'), image_path('negundo'))
arquivo = open(data_path(),'w')
count = 0
for i in images:
count+=1
img, vetor, arclen, classe = self.__features(i)
# Media Curvatura
arquivo.write(str(np.mean(np.abs(vetor))) + ',')
# Comprimento de Arco
arquivo.write(str(arclen) + ',')
# Area
arquivo.write(str(np.sum(img)) + ',')
# Numero Pixels Esqueleto
arquivo.write(str(np.sum(morphology.medial_axis(img))) + ',')
# Classe Folhas
arquivo.write(classe)
arquivo.write("\n")
arquivo.close()
print '100%'
print 'Total Imagens: ' + str(count)
开发者ID:glesio,项目名称:visaocomputacional,代码行数:27,代码来源:caracteristica.py
示例3: label_nuclei
def label_nuclei(binary, min_size):
'''Label, watershed and remove small objects'''
distance = medial_axis(binary, return_distance=True)[1]
distance_blured = gaussian_filter(distance, 5)
local_maxi = peak_local_max(distance_blured, indices=False, labels=binary, min_distance = 30)
markers = measure_label(local_maxi)
# markers[~binary] = -1
# labels_rw = segmentation.random_walker(binary, markers)
# labels_rw[labels_rw == -1] = 0
# labels_rw = segmentation.relabel_sequential(labels_rw)
labels_ws = watershed(-distance, markers, mask=binary)
labels_large = remove_small_objects(labels_ws,min_size)
labels_clean_border = clear_border(labels_large)
labels_from_one = relabel_sequential(labels_clean_border)
# plt.imshow(ndimage.morphology.binary_dilation(markers))
# plt.show()
return labels_from_one[0]
开发者ID:SimaGuseva,项目名称:darfi,代码行数:31,代码来源:pic_an_calc.py
示例4: skeletonize_mitochondria
def skeletonize_mitochondria(mch_channel):
mch_collector = np.max(mch_channel, axis=0) # TODO: check max projection v.s. sum
skeleton_labels = np.zeros(mch_collector.shape, dtype=np.uint8)
# thresh = np.max(mch_collector)/2.
thresh = threshold_otsu(mch_collector)
# use adaptative threshold? => otsu seems to be sufficient in this case
skeleton_labels[mch_collector > thresh] = 1
skeleton2 = skeletonize(skeleton_labels)
skeleton, distance = medial_axis(skeleton_labels, return_distance=True)
active_threshold = np.mean(mch_collector[skeleton_labels]) * 5
# print active_threshold
transform_filter = np.zeros(mch_collector.shape, dtype=np.uint8)
transform_filter[np.logical_and(skeleton > 0, mch_collector > active_threshold)] = 1
skeleton = transform_filter * distance
skeleton_ma = np.ma.masked_array(skeleton, skeleton > 0)
skeleton_convolve = ndi.convolve(skeleton_ma, np.ones((3, 3)), mode='constant', cval=0.0)
divider_convolve = ndi.convolve(transform_filter, np.ones((3, 3)), mode='constant', cval=0.0)
skeleton_convolve[divider_convolve > 0] = skeleton_convolve[divider_convolve > 0] / \
divider_convolve[divider_convolve > 0]
new_skeleton = np.zeros_like(skeleton)
new_skeleton[skeleton2] = skeleton_convolve[skeleton2]
skeleton = new_skeleton
return skeleton_labels, mch_collector, skeleton, transform_filter
开发者ID:chiffa,项目名称:Chromo_vision,代码行数:28,代码来源:layered_zstack_processing.py
示例5: execute_Skeleton
def execute_Skeleton(proxy,obj):
from skimage.morphology import medial_axis
threshold=0.1*obj.threshold
try:
img2=obj.sourceObject.Proxy.img
img=img2.copy()
except:
sayexc()
img=cv2.imread(__dir__+'/icons/freek.png')
data = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# Compute the medial axis (skeleton) and the distance transform
skel, distance = medial_axis(data, return_distance=True)
# Distance to the background for pixels of the skeleton
dist_on_skel = distance * skel
# entferne ganz duenne linien
dist_on_skelw =(dist_on_skel >= threshold)* distance
say("size of the image ...")
say(dist_on_skelw.shape)
# skel = np.array(dist_on_skelw,np.uint8)
skel = np.array(dist_on_skelw *255/np.max(dist_on_skelw),np.uint8)
obj.Proxy.img=cv2.cvtColor(skel*100, cv2.COLOR_GRAY2BGR)
obj.Proxy.dist_on_skel=dist_on_skelw
开发者ID:microelly2,项目名称:reconstruction,代码行数:30,代码来源:CV2.py
示例6: segment_cells
def segment_cells(frame, mask=None):
"""
Compute the initial segmentation based on ridge detection + watershed.
This works reasonably well, but is not robust enough to use by itself.
"""
blurred = filters.gaussian_filter(frame, 2)
ridges = enhance_ridges(frame)
# threshold ridge image
thresh = filters.threshold_otsu(ridges)
thresh_factor = 0.6
prominent_ridges = ridges > thresh_factor*thresh
prominent_ridges = morphology.remove_small_objects(prominent_ridges, min_size=256)
prominent_ridges = morphology.binary_closing(prominent_ridges)
prominent_ridges = morphology.binary_dilation(prominent_ridges)
# skeletonize
ridge_skeleton = morphology.medial_axis(prominent_ridges)
ridge_skeleton = morphology.binary_dilation(ridge_skeleton)
ridge_skeleton *= mask
ridge_skeleton -= mask
# label
cell_label_im = measure.label(ridge_skeleton)
# morphological closing to fill in the cracks
for cell_num in range(1, cell_label_im.max()+1):
cell_mask = cell_label_im==cell_num
cell_mask = morphology.binary_closing(cell_mask, disk(3))
cell_label_im[cell_mask] = cell_num
return cell_label_im
开发者ID:brikeats,项目名称:Cell-Tracking,代码行数:33,代码来源:track_cell.py
示例7: skeletonize_mitochondria
def skeletonize_mitochondria(mCh_channel):
mch_collector = np.max(mCh_channel, axis=0) # TODO: check how max affects v.s. sum
labels = np.zeros(mch_collector.shape, dtype=np.uint8)
# thresh = np.max(mch_collector)/2.
thresh = threshold_otsu(mch_collector)
# TODO: use adaptative threshold? => otsu seems to be sufficient in this case
# http://scikit-image.org/docs/dev/auto_examples/xx_applications/plot_thresholding.html#sphx
# -glr-auto-examples-xx-applications-plot-thresholding-py
# log-transform? => Nope, does not work
# TODO: hessian/laplacian of gaussian blob detection?
labels[mch_collector > thresh] = 1
skeleton2 = skeletonize(labels)
skeleton, distance = medial_axis(labels, return_distance=True)
active_threshold = np.mean(mch_collector[labels]) * 5
# print active_threshold
transform_filter = np.zeros(mch_collector.shape, dtype=np.uint8)
transform_filter[np.logical_and(skeleton > 0, mch_collector > active_threshold)] = 1
skeleton = transform_filter * distance
skeleton_ma = np.ma.masked_array(skeleton, skeleton > 0)
skeleton_convolve = ndi.convolve(skeleton_ma, np.ones((3, 3)), mode='constant', cval=0.0)
divider_convolve = ndi.convolve(transform_filter, np.ones((3, 3)), mode='constant', cval=0.0)
skeleton_convolve[divider_convolve > 0] = skeleton_convolve[divider_convolve > 0] \
/ divider_convolve[divider_convolve > 0]
new_skeleton = np.zeros_like(skeleton)
new_skeleton[skeleton2] = skeleton_convolve[skeleton2]
skeleton = new_skeleton
return labels, mch_collector, skeleton, transform_filter
开发者ID:chiffa,项目名称:Chromo_vision,代码行数:33,代码来源:Linhao_masks_logic.py
示例8: _process_img_morph
def _process_img_morph(img, threshold=.5, scale=1):
if scale > 1:
up_img = transform.pyramid_expand(img, upscale=scale, order=3) # type: np.ndarray
img = (255. * up_img).astype(img.dtype)
img_min, img_max = img.min(), img.max()
bin_img = (img >= img_min + (img_max - img_min) * threshold)
skel, dist_map = morphology.medial_axis(bin_img, return_distance=True)
return img, bin_img, skel, dist_map
开发者ID:dccastro,项目名称:Morpho-MNIST,代码行数:8,代码来源:morpho.py
示例9: skeleton
def skeleton(seg):
skel, dist = skmorph.medial_axis(seg, return_distance=True)
node, edge, leaf = (spim.label(g, np.ones((3, 3), bool))[0] for g in skel2graph(skel))
trim_edge = (edge != 0) & ~(skmorph.binary_dilation(node != 0, np.ones((3, 3), bool)) != 0)
trim_edge = spim.label(trim_edge, np.ones((3, 3), bool))[0]
leaf_edge_vals = skmorph.binary_dilation(leaf != 0, np.ones((3, 3), bool)) != 0
leaf_edge_vals = np.unique(trim_edge[leaf_edge_vals])
leaf_edge_vals = leaf_edge_vals[leaf_edge_vals > 0]
leaf_edge = leaf != 0
trim_edge = ndshm.fromndarray(trim_edge)
leaf_edge = ndshm.fromndarray(leaf_edge)
Parallel()(delayed(set_msk)(leaf_edge, trim_edge, l) for l in leaf_edge_vals)
trim_edge = np.copy(trim_edge)
leaf_edge = np.copy(leaf_edge)
leaf_edge[(skmorph.binary_dilation(leaf_edge, np.ones((3, 3), bool)) != 0) & (edge != 0)] = True
leaf_edge = spim.label(leaf_edge, np.ones((3, 3), bool))[0]
leaf_edge_node = skmorph.binary_dilation(leaf_edge != 0, np.ones((3, 3), bool)) != 0
leaf_edge_node = ((node != 0) & leaf_edge_node) | leaf_edge
leaf_edge_node = spim.label(leaf_edge_node, np.ones((3, 3), bool))[0]
cand_node = leaf_edge_node * (node != 0)
cand_node = cand_node.nonzero()
cand_node = np.transpose((leaf_edge_node[cand_node],) + cand_node + (2 * dist[cand_node],))
cand_leaf = leaf_edge_node * (leaf != 0)
cand_leaf = cand_leaf.nonzero()
cand_leaf = np.transpose((leaf_edge_node[cand_leaf],) + cand_leaf)
if len(cand_node) > 0 and len(cand_leaf) > 0:
cand_leaf = ndshm.fromndarray(cand_leaf)
cand_node = ndshm.fromndarray(cand_node)
pruned = Parallel()(delayed(prune_leaves)(cand_leaf, cand_node, j) for j in np.unique(cand_node[:, 0]))
cand_leaf = np.copy(cand_leaf)
cand_node = np.copy(cand_node)
pruned_ind = []
for p in pruned:
pruned_ind.extend(p)
pruned_ind = tuple(np.transpose(pruned_ind))
pruned = ~skel
pruned = ndshm.fromndarray(pruned)
leaf_edge = ndshm.fromndarray(leaf_edge)
Parallel()(delayed(set_msk)(pruned, leaf_edge, l) for l in np.unique(leaf_edge[pruned_ind]))
pruned = np.copy(pruned)
leaf_edge = np.copy(leaf_edge)
pruned = ~pruned
else:
pruned = skel
return pruned
开发者ID:VimsLab,项目名称:Chloroplasts,代码行数:58,代码来源:chloroplasts.py
示例10: get_text_image
def get_text_image(text, font, point_size):
text = get_text(text, font, point_size)
io.imsave(IMAGE_FILENAME, text)
thresh = skfilter.threshold_otsu(text)
binary = text > thresh
skel, distance = morphology.medial_axis(binary, return_distance=True)
distance = distance.astype(np.uint16)
skel = skel.astype(np.uint16)
return skel*distance
开发者ID:ryansturmer,项目名称:typesetter,代码行数:9,代码来源:typesetter.py
示例11: make_skeleton
def make_skeleton(image, mindist):
"""Return a skeletonization of the image, filtered and normalized."""
skel, distance = morphology.medial_axis(image, return_distance=True)
dist_on_skel = distance * skel
dist_on_skel = filter_skeleton_distances(dist_on_skel)
normalized = normalize_skeleton(dist_on_skel)
return normalized
开发者ID:OpenGelo,项目名称:robot_nav,代码行数:10,代码来源:skeleton.py
示例12: test_01_01_rectangle
def test_01_01_rectangle(self):
'''Test skeletonize on a rectangle'''
image = np.zeros((9, 15), bool)
image[1:-1, 1:-1] = True
#
# The result should be four diagonals from the
# corners, meeting in a horizontal line
#
expected = np.array([[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,1,0,0,0,0,0,0,0,0,0,0,0,1,0],
[0,0,1,0,0,0,0,0,0,0,0,0,1,0,0],
[0,0,0,1,0,0,0,0,0,0,0,1,0,0,0],
[0,0,0,0,1,1,1,1,1,1,1,0,0,0,0],
[0,0,0,1,0,0,0,0,0,0,0,1,0,0,0],
[0,0,1,0,0,0,0,0,0,0,0,0,1,0,0],
[0,1,0,0,0,0,0,0,0,0,0,0,0,1,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]], bool)
result = medial_axis(image)
assert np.all(result == expected)
result, distance = medial_axis(image, return_distance=True)
assert distance.max() == 4
开发者ID:emmanuelle,项目名称:scikit-image,代码行数:21,代码来源:test_skeletonize.py
示例13: loadImage
def loadImage(filename):
global im
global distanceImage
global lapImage
global skeleton
global resultImage
global im1
global skimage
im = np.asarray(Image.open(filename))
distanceImage, lapImage, resultImage = medial(im)
skeleton = lapImage < 0
im1 = ax.imshow(im, cmap = "gray", interpolation="nearest")
skimage = medial_axis(im, return_distance=False)
lapImage = lapImage - np.max(lapImage)
开发者ID:oew1v07,项目名称:Medial,代码行数:15,代码来源:gui.py
示例14: test_01_02_hole
def test_01_02_hole(self):
'''Test skeletonize on a rectangle with a hole in the middle'''
image = np.zeros((9, 15), bool)
image[1:-1, 1:-1] = True
image[4, 4:-4] = False
expected = np.array([[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,1,0,0,0,0,0,0,0,0,0,0,0,1,0],
[0,0,1,1,1,1,1,1,1,1,1,1,1,0,0],
[0,0,1,0,0,0,0,0,0,0,0,0,1,0,0],
[0,0,1,0,0,0,0,0,0,0,0,0,1,0,0],
[0,0,1,0,0,0,0,0,0,0,0,0,1,0,0],
[0,0,1,1,1,1,1,1,1,1,1,1,1,0,0],
[0,1,0,0,0,0,0,0,0,0,0,0,0,1,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]],bool)
result = medial_axis(image)
assert np.all(result == expected)
开发者ID:emmanuelle,项目名称:scikit-image,代码行数:16,代码来源:test_skeletonize.py
示例15: __transform
def __transform(self):
img_gray = io.imread(self.image_path, True)
#Aplicar otsu para binarizar a imagem
img_otsu = filter.threshold_otsu(img_gray)
self.__img = img_gray < img_otsu
# Procura contornos da imagem binarizada
self.__contours = measure.find_contours(self.__img, 0.5)
arclen=0.0
for n, contour in enumerate(self.__contours):
arclenTemp=0.0
for indice, valor in enumerate(contour):
if indice > 0:
d1 = math.fabs(round(valor[0]) - round(contour[indice-1,0]))
d2 = math.fabs(round(valor[1]) - round(contour[indice-1,1]))
if d1+d2>1.0:
arclenTemp+=math.sqrt(2)
elif d1+d2 == 1:
arclenTemp+=1
if arclenTemp > arclen:
arclen = arclenTemp
bestn = n
#Transforma a lista contours[bestn] em uma matriz[n,2]
aux = np.asarray(self.__contours[bestn])
#--------------------------- Curvatura --------------
vetor = [] #vetor que irá receber as curvaturas k(t)
for i in range(len(aux)-2): #Percorrer ate -2 para não pegar elementos inexistentes
#--------------------------- Curvatura --------------
#Inverter as posições em relação a fórmula pois o x esta no lugar do y
b1 = ( (aux[i-2,1]+aux[i+2,1]) + (2*(aux[i-1,1] + aux[i+1,1])) - (6*aux[i,1]) ) / 12
b2 = ( (aux[i-2,0]+aux[i+2,0]) + (2*(aux[i-1,0] + aux[i+1,0])) - (6*aux[i,0]) ) / 12
c1 = ( (aux[i+2,1]-aux[i-2,1]) + (4*(aux[i+1,1] - aux[i-1,1])) ) / 12
c2 = ( (aux[i+2,0]-aux[i-2,0]) + (4*(aux[i+1,0] - aux[i-1,0])) ) / 12
k = (2*(c1*b1 - c2*b2)) / ((c1**2 + c2**2)**(3/2))
vetor.append(k) #append: insere objeto no final da lista
self.__media_curvatura = np.mean(np.abs(vetor))
self.__comprimento_arco = arclen
self.__area = np.sum(self.__img)
self.__esqueleto_pixel = np.sum(morphology.medial_axis(self.__img))
self.__bestn = bestn
开发者ID:glesio,项目名称:visaocomputacional,代码行数:47,代码来源:curvatura_media.py
示例16: image_features_morphology
def image_features_morphology(img, maxPixel, num_features,imageSize):
# X is the feature vector with one row of features per image
# consisting of the pixel values a, num_featuresnd our metric
X=np.zeros(num_features, dtype=float)
image = resize(img, (maxPixel, maxPixel))
# Compute the medial axis (skeleton) and the distance transform
skel, distance = medial_axis(image, return_distance=True)
# Distance to the background for pixels of the skeleton
dist_on_skel = distance * skel
# Store the rescaled image pixels
X[0:imageSize] = np.reshape(dist_on_skel,(1, imageSize))
return X
开发者ID:kailex,项目名称:Bowl,代码行数:17,代码来源:Prepare_Features.py
示例17: get_skeleton_of_maze
def get_skeleton_of_maze(image_to_analyze, image_to_draw_on=None,
use_medial_axis=True, invert_threshold=False,
locate_critical_points=True, resize_ratio=1):
"""
Computes, returns, and potentially displays the morphological skeleton of the given binary image.
:param image_to_analyze: Image to manipulate in search of results.
:param image_to_draw_on: Image passed in that is to be used for drawing the results of analysis.
:param use_medial_axis: Whether to use an alternative method for finding the skeleton that
allows the computation of the critical points in the image.
:param invert_threshold: Whether the threshold should be inverted before the skeleton is located
:param locate_critical_points: Whether to find and draw critical points on the skeleton.
:param resize_ratio: What ratio to rescale outgoing results to before they're displayed.
:return: The skeleton of the image, and the critical points (If you chose to try to find them)
"""
result = []
# Invert our thresholded image since this will skeletonize white areas
if invert_threshold:
image_to_analyze = cv2.bitwise_not(image_to_analyze)
image_to_analyze = cv2.bitwise_not(image_to_analyze)
if use_medial_axis or locate_critical_points:
# http://scikit-image.org/docs/dev/auto_examples/plot_medial_transform.html
# In short, allows us to find the distance to areas on the skeleton.
# This information can be used to find critical points in the skeleton, theoretically.
path_skeleton, distance = medial_axis(image_to_analyze, return_distance=True)
distance_on_skeleton = path_skeleton * distance
path_skeleton = img_as_ubyte(path_skeleton)
result.append(path_skeleton)
if locate_critical_points:
critical_points = find_critical_points(distance_on_skeleton, number_of_points=10,
minimum_thickness=50, edge_width=20,
image_to_draw_on=image_to_draw_on)
result.append(critical_points)
else:
skeleton = skeletonize(image_to_analyze/255)
path_skeleton = np.array(skeleton*255, np.uint8)
result.append(path_skeleton)
if image_to_draw_on is not None:
path_skeleton_temp = cv2.cvtColor(path_skeleton, cv2.COLOR_GRAY2BGR)
superimposed_skeleton = cv2.add(image_to_draw_on, path_skeleton_temp)
display("Skeleton", superimposed_skeleton, resize_ratio)
return result
开发者ID:Zenohm,项目名称:ACORL_MazeSolver,代码行数:44,代码来源:main.py
示例18: get_skeleton
def get_skeleton(img):
rows, cols = img.shape
for r in xrange(rows):
img[r][0] = 0
img[r][cols - 1] = 0
for c in xrange(cols):
img[0][c] = 0
img[rows - 1][c] = 0
dst = np.asarray(map(lambda row:
np.asarray(map(lambda x: 1 if x == 255 else 0,row)),
img))
dst, _ = morphology.medial_axis(dst, return_distance=True)
dst = np.asarray(map(lambda row:
np.asarray(map(lambda x: 255 if x else 0,row)),
dst))
return dst
开发者ID:kelwinfc,项目名称:Ambush,代码行数:19,代码来源:get_navigation_mesh.py
示例19: __transform
def __transform(self):
img_gray = io.imread(self.__img_path, True)
thresh = filter.threshold_otsu(img_gray)
data = img_gray < thresh
s1, self.__distancia = morphology.medial_axis(data, return_distance=True)
self.__s2 = s1
for i in range(len(s1)):
for j in range(len(s1)):
if (s1[i,j] <> False): #Percorre o esqueleto da imagem
x, y,val = circle_perimeter_aa(i, j, int(self.__distancia[i,j]))
#desenha um circulo ao redor do pixel do esqueleto
#i,j coordenadas do centro -- int(distance[i,j]=raio do circulo)
#x,y = índices dos pixels ---- val = intensidade
#Define quais circulos devem ficar de acordo com o raio
if (int(self.__distancia[i,j]) > 0):
self.__s2[x, y] = True
else:
self.__s2[x, y] = False
else:
self.__s2[i, j] = False
开发者ID:glesio,项目名称:visaocomputacional,代码行数:24,代码来源:reconstrucao.py
示例20: cell_boundaries_detector
def cell_boundaries_detector(data_iterator,
metadata,
show_progress=False,
parameters={}):
"""
Find cell boundary in bright field microscopy image.
Parameters
----------
data_iterator : python iterator
To iterate over data.
metadata : dict
Metadata to scale detected peaks and parameters.
show_progress : bool (default: False)
Print progress bar during detection.
verbose : bool (default: True)
Display informations during detection.
parameters : dict
object_height : float
Typical size of the object in um.
minimal_area : float
Typical area of the object in um^2.
Returns
------()
shapes : :class:`pd.DataFrame`
Contains cell boundary properties for each time_stamp
"""
_parameters = DEFAULT_PARAMETERS.copy()
_parameters.update(parameters)
parameters = _parameters
# Load parameters
sigma = parameters['object_height'] / metadata['PhysicalSizeZ']
minimal_area = parameters['minimal_area'] / metadata['PhysicalSizeX']
sizeX = metadata['SizeX']
sizeY = metadata['SizeY']
# calculate the correlation image from the z-stack
cellprop = []
t_tot = metadata['SizeT']
for t, imt in enumerate(data_iterator):
if show_progress:
p = int(float(t + 1) / t_tot * 100.)
print_progress(p)
if np.any(imt) != 0:
corr = np.zeros((sizeY, sizeX))
for y, x in np.ndindex(sizeY, sizeX):
Iz = imt[:, y, x]
z = np.array(range(len(Iz)))
zf = len(Iz) / 2
corr[y, x] = integrate.simps(Iz[z] * (z - zf) * np.exp(-(zf - z) ** 2 /
(2 * sigma ** 2)), z)
# create binary mask of the correlation image
thresh = threshold_otsu(corr)
mask = corr > thresh
area = 0
n = 2
prevarea = None
prevcellprop = None
# un seuil pas trop petit au cas où il resterait des petits objets
# dans l'image
while area < minimal_area and prevarea != area:
tophat = binary_closing(mask, square(n))
n += 1
skel = medial_axis(tophat)
skel = (skel - 1) * (-1)
cleared = clear_border(skel)
labelized = label(cleared, 8, 0) + 1
# add cell characteristic in the cellprop list
if np.any(labelized):
prevcellprop = regionprops(
labelized, intensity_image=corr)[0]
prevarea = area
if prevcellprop:
area = prevcellprop['area']
if prevcellprop:
cellprop.append(prevcellprop)
else:
if len(cellprop) >= 1:
cellprop.append(cellprop[-1])
else:
cellprop.append(None)
else:
if len(cellprop) >= 1:
cellprop.append(cellprop[-1])
else:
#.........这里部分代码省略.........
开发者ID:glyg,项目名称:scikit-tracker,代码行数:101,代码来源:cell_boundaries_detector.py
注:本文中的skimage.morphology.medial_axis函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论