我有一套480的原始图像和480个标签(每个原件)已经分割和标记通过一个流域过程。我使用标签,labels_ws,在寻找原始图像中各个区域的平均强度时,original_images。这些图像形成了一个时间序列,我希望跟踪这个时间序列的每个标记区域的平均强度。
使用以下代码很容易在scikit图像中找到单个图像中区域的平均强度:
regions = measure.regionprops(labels_ws, intensity_image = original_image)
print(["(%s, %s)" % (r, r.mean_intensity) for r in regions])它打印了大量的输出,如下所示:
'(skimage.measure._regionprops._RegionProperties对象在0x000000000E5F3F98,35.46153846153846)', '(skimage.measure._regionprops._RegionProperties对象在0x000000000E5F3FD0,47.0)', '(skimage.measure._regionprops._RegionProperties对象在0x000000000E7B6048,49.96666666666667)', '(skimage.measure._regionprops._RegionProperties对象在0x000000000E7B6080,23.0‘, '(skimage.measure._regionprops._RegionProperties对象在0x000000000E7B60B8,32.1‘,
每幅图像大概有100到150个区域。这些区域是图像中的区域,在图像拍摄期间,组织样本中有神经元发光。随着时间序列的发展,区域(神经元)以周期性的方式发光,因此每个区域的强度数据应该像一个周期函数。
我遇到的问题是,在每一幅连续图像中,标签/区域略有不同,因为每个区域的发光都遵循其周期性行为。因此,标签/区域在时间序列的持续时间内“突然进入/退出”。我也不能保证,比方说,当第一次发光时,Region_1的大小将与第二次或第三次发光时的大小相同(不过,任何差别都很小,只有几个像素)。
所有这一切,有没有办法把我所有的标签以某种方式组合成一个单一的标签,我可以跟踪?我是否应该以某种方式将所有原始图像组合起来,然后创建一个主标签?如何处理肯定会重叠但可能有几个像素不同形状/大小的区域?谢谢!
发布于 2019-09-09 12:14:24
我有一个类似的问题,我想跟踪变化的分段区域随着时间的推移。我的解决方案是在每个分割区域的中心点改变每幅图像中的所有标签。这具有将标签传播到所有其他图像的效果。
当然,这假设这些地区在整个过程中都处于大致相同的位置。
你可以看到动画中的不同之处:左边的标签不断变化,右边的标签保持一致。尽管缺少帧和变化的区域,它还是有效的。
动画链接:https://imgur.com/a/e1Q7V6O#o4t9HyE (我没有足够的代表直接发布图片)
只需将分割图像和标签图像列表发送到standardise_labels_timeline
def standardise_labels_timeline(images_list, start_at_end = True, count_offset = 1000):
"""
Replace labels on similar images to allow tracking over time
:param images_list: a list of segmented and lablled images as numpy arrays
:param start_at_end: relabels the images beginning at the end of the list
:param count_offset: an int greater than the total number of expected labels in a single image
:returns: a list of relablled images as numpy arrays
"""
import numpy as np
images = list(images_list)
if start_at_end:
images.reverse()
# Relabel all images to ensure there are no duplicates
for image in images:
for label in np.unique(image):
if label > 0:
count_offset += 1
image[image == label] = count_offset
# Ensure labels are propagated through image timeline
for i, image in enumerate(images):
labels = get_labelled_centers(image)
# Apply labels to all subsequent images
for j in range(i, len(images)):
images[j] = replace_image_point_labels(images[j], labels)
if start_at_end:
images.reverse()
return images
def get_labelled_centers(image):
"""
Builds a list of labels and their centers
:param image: a segmented and labelled image as a numpy array
:returns: a list of label, co-ordinate tuples
"""
from skimage.measure import regionprops
# Find all labelled areas, disable caching so properties are only calculated if required
rps = regionprops(image, cache = False)
return [(r.label, r.centroid) for r in rps]
def replace_image_point_labels(image, labels):
"""
Replace the labelled at a list of points with new labels
:param image: a segmented and lablled image as a numpy array
:param labels: a list of label, co-ordinate tuples
:returns: a relabelled image as a numpy array
"""
img = image.copy()
for label, point in labels:
row, col = point
# Find the existing label at the point
index = img[int(row), int(col)]
# Replace the existing label with new, excluding background
if index > 0:
img[img == index] = label
return img发布于 2019-10-10 11:07:36
-编码: utf-8 -
“在%(日期)s上创建
@作者:%(Ahmed Islam ElManawy)s a.elmanawy_90@yahoo.com“”
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
import cv2
from skimage.measure import label, regionprops
from sklearn.cluster import KMeans
import numpy as np
## import image
img=cv2.imread('E:\\Data\\Arabidopsis Thaliana HSI image\\20170508\\binarry\\AQC_RT.jpg',1)
## lablelled image
label_image = label(img[:,:,0])
## combined image center using k-means
Center=[]
Box=[]
for region in regionprops(label_image):
# take regions with large enough areas
if region.area >= 10:
# draw rectangle around segmented coins
Box.append(region.bbox)
Center.append(region.centroid)
Center=np.asarray(Center)
Box=np.asarray(Box)
kmeans=KMeans(n_clusters=12, random_state=0).fit(Center)
label=kmeans.labels_
## plot image with different area
fig, ax = plt.subplots(figsize=(10, 6))
ax.imshow(img)
for l in label:
h=np.where(label==l)
B=Box[h,:]
B=B[0,:,:]
minr, minc, maxr, maxc =np.min(B[:,0]), np.min(B[:,1]), np.max(B[:,2]), np.max(B[:,3])
# plt.imshow(img2[11:88, 2:94,:])
rect = mpatches.Rectangle((minc, minr), maxc - minc, maxr - minr,
fill=False, edgecolor='red', linewidth=2)
ax.add_patch(rect)
ax.set_axis_off()
plt.tight_layout()
plt.show()https://stackoverflow.com/questions/57395048
复制相似问题