缩放坐标列表#

假设你有一个从图像中得到的坐标列表。如果图像有指定的像素大小,你可以将像素坐标转换为物理坐标。

from skimage.io import imread
import pyclesperanto_prototype as cle
import stackview
image = imread("../../data/blobs.tif")[:50,:50]

label_image = cle.voronoi_otsu_labeling(image, spot_sigma=4)

label_image
cle._ image
shape(50, 50)
dtypeuint32
size9.8 kB
min0.0
max6.0

从这个标签图像中的对象,我们可以得到质心坐标。

centroids = cle.centroids_of_labels(label_image)
centroids
cle.array([[ 0.7586207  7.7894735 17.849672  24.59091   29.01266   43.57143  ]
 [26.275862  44.63158   17.79085    4.071429  47.02532   26.266666 ]], dtype=float32)

这样的点列表有 d 乘以 n 个数字,对应 d 个维度(通常是2或3)和 n 个点。

centroids.shape
(2, 6)

如果已知像素大小,我们可以计算出物理单位的质心坐标。

pixel_size_in_microns = [0.1, 0.1]
centroids_in_microns = centroids * cle.asarray([pixel_size_in_microns]).T

centroids_in_microns
cle.array([[0.07586207 0.77894735 1.7849673  2.459091   2.9012659  4.357143  ]
 [2.6275861  4.463158   1.779085   0.40714288 4.702532   2.6266668 ]], dtype=float32)