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

important:

Adding a "rw" parameter, which means the the fraction
of the radius that will be taken into account
to compute the profiles.
In the relabel function, pixels ouside a cilinder
of radius r = len(image)*"rw" will be labeled
with a value = 1 -> pixels outside the cylinder

Not very important:
A new parameter sample_name: to create output
files with shorter names, not like.
parent 8c741501
......@@ -38,15 +38,8 @@ def raw_profile_if_ram_limitation(Image, Labels):
Vol_Frac_Total = np.array(Vol_Frac_Total)
return (Vol_Frac_1, Vol_Frac_2, Vol_Frac_3, Vol_Frac_Total)
def clean_name(image_name):
# Cleaning the name of the file
name = image_name.replace(".tif","")
name = name.replace("_ROI_Filtered_aniso", "")
name = name.replace("Hash_Segm_of_", "")
name = name.replace("Hashemi_Segmentation_of_", "")
return name
def plot_raw_profile(path_save, name, z, VF1, VF2, VF3):
def plot_raw_profile(path_save, sample_name, z, VF1, VF2, VF3, rw):
plt.close("all")
fig, ax = plt.subplots()
......@@ -57,12 +50,15 @@ def plot_raw_profile(path_save, name, z, VF1, VF2, VF3):
ax.set_ylabel('Depth (mm)')
ax.set_xlim([0,1])
ax.legend()
title = "Raw_VF_Profile_Raw_of_{}.png".format(clean_name(name))
if rw == None:
title = "Raw_VFP_of_{}.png".format(sample_name)
else:
title = "Raw_VFP_of_{}_rw_{}.png".format(sample_name, rw)
chdir(path_save)
fig.savefig(title)
return (fig, ax)
def plot_smooth_profile(path_save, name, z, VF1, VF2, VF3, w_size):
def plot_smooth_profile(path_save, sample_name, z, VF1, VF2, VF3, rw):
"""
w_size = window_size in mm
"""
......@@ -76,7 +72,10 @@ def plot_smooth_profile(path_save, name, z, VF1, VF2, VF3, w_size):
ax.set_ylabel('Depth (mm)')
ax.set_xlim([0,1])
ax.legend()
title = "Smooth_VF_Profile_Raw_of_{}_ws_{}mm.png".format(clean_name(name),w_size )
if rw == None:
title = "Smooth_VFP_of_{}.png".format(sample_name)
else:
title = "Smooth_VFP_of_{}_rw_{}.png".format(sample_name, rw)
chdir(path_save)
fig.savefig(title)
return (fig, ax)
......@@ -118,7 +117,7 @@ def sector_mask(shape,centre,radius,angle_range):
return circmask*anglemask
def relabel_the_outside(image,labels):
def relabel_the_outside(image,labels, rw = None):
""" if pixels outside the cylinder that contains the sample have the same value for air
they will be relabeled with the value label[1]
so, if you follow the conventions for label values
......@@ -134,7 +133,10 @@ def relabel_the_outside(image,labels):
# The cylinder is supposed to be the biggest "circle" inscribed in a squared image
z,x,y = np.shape(image)[0], np.shape(image)[1], np.shape(image)[2]
center = int(x/2), int(y/2)
radius = int((x/2))
if rw == None:
radius = int((x/2))
else:
radius = int((x/2))*rw
#Selecting circular ROI (region of interest)
mask_2D = sector_mask((x,y),center,radius,(0,360 ))
mask_3D = np.zeros(image.shape, dtype = np.bool)
......@@ -145,7 +147,7 @@ def relabel_the_outside(image,labels):
return image
def Compute_Volume_Fraction_Profile (path, path_save, image_name, labels, neighbors, resolution, flag_TZ = False, lims = (None, None), flag_RAM_limitation = False, flag_relabel = False):
def Compute_Volume_Fraction_Profile (path, path_save, image_name, sample_name, labels, neighbors, resolution, flag_TZ = False, lims = (None, None), flag_RAM_limitation = False, flag_relabel = False, rw = None):
""" Input Labels = list with int numbers that represent the phases of the image, in this version there are 4 phases
Label[0] = outside the cylinder
Label[1] = voids
......@@ -160,7 +162,7 @@ def Compute_Volume_Fraction_Profile (path, path_save, image_name, labels, neighb
image = tifffile.imread(image_name)
if flag_relabel == True:
image = relabel_the_outside(image, labels)
image = relabel_the_outside(image, labels, rw)
##################
......@@ -174,7 +176,6 @@ def Compute_Volume_Fraction_Profile (path, path_save, image_name, labels, neighb
if test == False:
raise AssertionError("You must verify that there are EXACTLY {} labels for phases in your image".format(len(labels)))
###################################
# computing Raw Profile
###################################
if flag_RAM_limitation == False:
......@@ -187,16 +188,20 @@ def Compute_Volume_Fraction_Profile (path, path_save, image_name, labels, neighb
##################
z = -1*resolution*np.arange(len(image)) # result in mm
raw_data = np.transpose([z, VF1, VF2, VF3, VFT])
columns = ['z (mm)','Air (%v/v)','FM (%v/v)','Grv (%v/v)', 'Total']
columns = ['z (mm)','Voids (%v/v)','FM (%v/v)','Gravel (%v/v)', 'Total']
raw_data = pd.DataFrame(raw_data, columns = columns)
csv_file_name = 'Raw_Vertical_profile_of_{}.csv'.format(clean_name(image_name))
if rw == None:
csv_file_name = 'Raw_VFP_of_{}.csv'.format(sample_name)
else:
csv_file_name = 'Raw_VFP_of_{}_rw_{}.csv'.format(sample_name, rw)
chdir (path_save)
raw_data.to_csv(csv_file_name)
##################
# plotting raw profile
##################
plot_raw_profile(path_save, clean_name(image_name), z, VF1, VF2, VF3)
plot_raw_profile(path_save, sample_name, z, VF1, VF2, VF3, rw)
###################################
# Compute smooth profiles
......@@ -214,14 +219,18 @@ def Compute_Volume_Fraction_Profile (path, path_save, image_name, labels, neighb
columns = ['z (mm)','Air (%v/v)','FM (%v/v)','Grv (%v/v)', 'Total']
smooth_data = pd.DataFrame(smooth_data, columns = columns)
w_size = neighbors*resolution
csv_file_name = 'Smooth_Vertical_profile_of_{}_ws_{}mm.csv'.format(clean_name(image_name),w_size)
if rw == None:
csv_file_name = 'Smooth_VFP_of_{}.csv'.format(sample_name)
else:
csv_file_name = 'Smooth_VFP_of_{}_rw_{}.csv'.format(sample_name, rw)
chdir(path_save)
smooth_data.to_csv(csv_file_name)
##################
# plotting smooth profile
##################
fig, ax = plot_smooth_profile(path_save, clean_name(image_name), z, S_VF1, S_VF2, S_VF3, w_size = w_size)
fig, ax = plot_smooth_profile(path_save, sample_name, z, S_VF1, S_VF2, S_VF3, rw)
###################################
# 3) SMOOTHED PROFILES With Transition Region Between Deposit and gravel
......@@ -259,6 +268,8 @@ def main():
path_save = '/home/german.martinez-carvajal/Desktop/These/Volume_fraction_profiles/Test'
# Image Name
image_name ='Hash_Segm_of_Image_Filtered_PVE_50_Tol_0.75_NumVS_1.tif'
# Sample Name
sample_name = "Image_Filtered"
# cheking
check_paths_and_files(path_read, path_save, image_name)
......@@ -280,8 +291,11 @@ def main():
# RAM limitation ?
flag_RAM_limitation = False
# Compute only inside a circular ROI of size rw (radius of window) as a fraction
rw = 0.99
# Computing
Compute_Volume_Fraction_Profile (path_read, path_save, image_name, labels, neighbors, resolution, flag_TZ = flag_TZ, lims = lims, flag_RAM_limitation = flag_RAM_limitation, flag_relabel = flag_relabel)
Compute_Volume_Fraction_Profile (path_read, path_save, image_name, sample_name, labels, neighbors, resolution, flag_TZ = flag_TZ, lims = lims, flag_RAM_limitation = flag_RAM_limitation, flag_relabel = flag_relabel, rw = rw)
main()
print('Finished')
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