Set scale of pixels in microns in python

Viewed 366

I have the following problem: after having segmented some objects across several slices in a stack, I am now trying to analyse them to extract several measurements, such as volume and major and minimum axes lengths. I would like to set the pixel size before extracting any measurements, i.e. to convert the XYZ axis to the corresponding pixel size in microns and then calculate the actual values (e.g. volume, axis length etc.)

For instance:

import os
from glob import glob
import pandas as pd
import numpy as np
from skimage.io import imread, imsave
from skimage.measure import regionprops, regionprops_table

pathname = "path/to/image.tif"
Y = sorted(glob(pathname+'/*.tif'))
Y = list(map(imread,Y))
pixelsize = (0.11, 0.11, 0.25) #xyz
table = pd.DataFrame(regionprops_table(mask.astype(int), properties=['label', 'area', 'major_axis_length'))

At the moment I am doing this, for instance:

table["major_axis_length"] = table["major_axis_length"].apply(lambda x: x*pixelsize[0])

This can work for 2D, but not for 3D measurements. How can I just set the scale before performing any measurement?

Thank you !

0 Answers
Related