Commit 7d6c4caf authored by Martinez-Carvajal German's avatar Martinez-Carvajal German
Browse files

This is a new programm that takes as argument

an image with connected pores (obtained using
the FIJI's pluggin connected regions over the
void's phase of a segmentation)
and computes
the volume of each reagion
the min and max X,Y,Z coordinate
the lenght of the pore in each direction (of the
 inscribing box)
a bool saying if the pore is connected to the top
of the sample (top = when z = 0)
parent 6c6767a3
# -*- coding: utf-8 -*-
"""
Created on Wed Sep 11 19:09:06 2019
@author: german.martinez-carvajal
"""
# -*- coding: utf-8 -*-
"""
Created on Wed Sep 11 18:25:20 2019
@author: german.martinez-carvajal
"""
import tifffile
from os import chdir
import numpy as np
import pandas as pd
def statistics(path_read, file, paht_save, sample_name):
# reading
chdir(path_read)
print("reading...", path_read, file)
image = tifffile.imread(file)
# counting number of pores
print("extracting labels...")
labels = np.unique(image)
labels = labels[labels !=0]
print("{} labels where found !".format(len(labels)))
# number of pores
num_pores = len(labels)
# Variables
v = np.zeros(num_pores, dtype = int) # volume of pores
x0 = np.zeros(num_pores, dtype = int)
y0 = np.zeros(num_pores, dtype = int)
z0 = np.zeros(num_pores, dtype = int)
xf = np.zeros(num_pores, dtype = int)
yf = np.zeros(num_pores, dtype = int)
zf = np.zeros(num_pores, dtype = int)
for i in range(num_pores):
label = labels[i]
pore = (image == label)
v[i] = np.count_nonzero(pore)
coords = np.where(image == label) # z, y, x
x0[i] = np.min(coords[2])
y0[i] = np.min(coords[1])
z0[i] = np.min(coords[0])
xf[i] = np.max(coords[2])
yf[i] = np.max(coords[1])
zf[i] = np.max(coords[0])
delta_x = xf - x0
delta_y = yf - y0
delta_z = zf - z0
connected_to_top = (z0 == 0)
my_data = dict()
frame = pd.DataFrame(my_data)
frame["Label"] = labels
frame["volume (vox)"] = v
frame["x0"] = x0
frame["xf"] = xf
frame["delta_x"] = delta_x
frame["y0"] = y0
frame["yf"] = yf
frame["delta_y"] = delta_y
frame["z0"] = z0
frame["zf"] = zf
frame["delta_z"] = delta_z
frame["connected to top"] = np.array(connected_to_top, dtype = np.int)
chdir(path_save)
frame.to_csv("statistics_CR_{}.csv".format(sample_name) ,sep = ';')
print('finished treating sample {}'.format(sample_name))
path_read = '/home/german.martinez-carvajal/Desktop/These/Connecting_CR/test'
path_save = path_read
file = 'small_top.tif'
sample_name = "small_top"
statistics(path_read, file, path_save, sample_name)
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment