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

Very simple modifications:

all these changes were writen to follow in the message file the evolution of the growinf procedure
parent f3ee5d38
......@@ -51,7 +51,8 @@ def interface_filling(B_Air,B_OrM,B_Grv, slices_VS):
Air,OrM,Grv = np.count_nonzero(B_Air),np.count_nonzero(B_OrM),np.count_nonzero(B_Grv)
Total = Air + OrM + Grv
Attributed_Voxels_Interface.append ([Counter_GrowSteps_Interface,Air,OrM,Grv,Total])
counter = 0
while np.count_nonzero(Grown_Image==0) > 0:
Counter_GrowSteps_Interface += 1
print("step=",Counter_GrowSteps_Interface)
......@@ -71,6 +72,14 @@ def interface_filling(B_Air,B_OrM,B_Grv, slices_VS):
Grown_Image = Grown_Image + np.array(B_new_OrM,dtype=np.uint8)*128
Grown_Image = Grown_Image + np.array(B_new_Grv,dtype=np.uint8)*192
print("Remaining Interface Voxels to fill = " , np.count_nonzero(Grown_Image==0))
Messages.append("Step Interface filling = {} ".format(counter))
Messages.append("Remaining Interface Voxels to fill = {}".format(np.count_nonzero(Grown_Image==0)))
MessagesDF = pd.DataFrame({"Message":Messages})
Title = 'Messages_' + Scan_File.replace(Dir + '/' , "")[:-4] + '.csv'
chdir(path_lr)
MessagesDF.to_csv(Title, encoding = "utf-8")
counter += 1
# Reasigning names for next loop
B_Air = B_new_Air
B_OrM = B_new_OrM
......@@ -81,6 +90,7 @@ def interface_filling(B_Air,B_OrM,B_Grv, slices_VS):
Air,OrM,Grv = np.count_nonzero(B_Air),np.count_nonzero(B_OrM),np.count_nonzero(B_Grv)
Total = Air + OrM + Grv
Attributed_Voxels_Interface.append ([Counter_GrowSteps_Interface,Air,OrM,Grv,Total])
Messages.append("# of Interface filling Steps = " + str(Counter_GrowSteps_Interface))
# Retrieving memory
......@@ -133,6 +143,7 @@ def region_growing(Seed_Image, slices_VS, Save_Step):
# For Loop
Max_iterations = np.max(Image.shape)
Messages.append("")
for Counter in range(Max_iterations):
# Performing the dilation
......@@ -226,47 +237,79 @@ def region_growing(Seed_Image, slices_VS, Save_Step):
del Interface
# Loop control - checking growth - and printing messages for each case
print("Step =", str(Counter))
print("Number of remaining uncertain Voxels =", str(Remaining_Voxels_this_step))
if (np.logical_and(Counter>0,Remaining_Voxels[Counter]==Remaining_Voxels[Counter-1])):
Message = "Loop Broken - Growing stopped, remaining uncertain voxels step(-i) = step(i) = " + str(Remaining_Voxels_this_step) +" voxels"
print(Message)
Messages.append(Message)
Messages.append("")
MessagesDF = pd.DataFrame({"Message":Messages})
Title = 'Messages_' + Scan_File.replace(Dir + '/' , "")[:-4] + '.csv'
chdir(path_lr)
MessagesDF.to_csv(Title, encoding = "utf-8")
break
elif (Remaining_Voxels_this_step == 0):
print ("Succes : Loop Broken - All Voxels were attributed durring Growing")
Messages.append("Succes : Loop Broken at step:" + str(Counter) + "- All Voxels were attributed durring Growing")
Messages.append("")
MessagesDF = pd.DataFrame({"Message":Messages})
Title = 'Messages_' + Scan_File.replace(Dir + '/' , "")[:-4] + '.csv'
chdir(path_lr)
MessagesDF.to_csv(Title, encoding = "utf-8")
break
elif (Counter == Max_iterations-1):
print ("Failure: Max_iterations reached")
Messages.append("Failure: Max_iterations reached: "+ str(Max_iterations) )
Messages.append("Failure: Max_iterations reached: "+ str(Max_iterations) )
Messages.append("")
MessagesDF = pd.DataFrame({"Message":Messages})
Title = 'Messages_' + Scan_File.replace(Dir + '/' , "")[:-4] + '.csv'
chdir(path_lr)
MessagesDF.to_csv(Title, encoding = "utf-8")
else:
print("Growing loop going on")
print("Number of remaining uncertain Voxels =", str(Remaining_Voxels_this_step))
Messages.append('Loop Going on : step = ' + str(Counter))
Messages.append('Number of remaining uncertain Voxels = ' + str(Remaining_Voxels_this_step))
MessagesDF = pd.DataFrame({"Message":Messages})
Title = 'Messages_' + Scan_File.replace(Dir + '/' , "")[:-4] + '.csv'
chdir(path_lr)
MessagesDF.to_csv(Title, encoding = "utf-8")
del Grown_Image
if Counter == 0:
stats_RAM = get_RAM_usage(stage = 'End of the growing step', path = path_lr, frame_stats =stats_RAM)
# Tracking atributed and not attributed Voxels
Attributed_Voxels_Growing = pd.DataFrame({"Air":Air,"OrM":OrM,"Grv":Grv,"Itf":Itf,"Tot":Tot})
# Ploting
plt.figure()
# In fig()
plt.plot(Attributed_Voxels_Growing.index,Attributed_Voxels_Growing.Air,color="k",lw=1, label = "Air Voxels", linestyle = '-')
plt.plot(Attributed_Voxels_Growing.index,Attributed_Voxels_Growing.OrM,color="k",lw=1, label = "OrM Voxels", linestyle = '--')
plt.plot(Attributed_Voxels_Growing.index,Attributed_Voxels_Growing.Grv,color="k",lw=1, label = "Grv Voxels", linestyle = '-.')
plt.plot(Attributed_Voxels_Growing.index,Attributed_Voxels_Growing.Itf,color="k",lw=1, label = "Int Voxels", linestyle = ':')
plt.plot(Attributed_Voxels_Growing.index,Attributed_Voxels_Growing.Tot,color="k",lw=2, label = "Sum", linestyle = '-')
plt.axhline(y = np.product(Image.shape), label = " Image Size", color = "red")
plt.title('Growing')
plt.xlabel('Step')
plt.ylabel('# Attributed Voxels')
plt.legend(fontsize = "small", loc = 'upper left')
# Saving the figure
chdir(path_lr)
Title = 'Growing_of_' + Scan_File.replace(Dir + '/' , "")[:-4]
plt.savefig(Title)
# Tracking atributed and not attributed Voxels
Attributed_Voxels_Growing = pd.DataFrame({"Air":Air,"OrM":OrM,"Grv":Grv,"Itf":Itf,"Tot":Tot})
# Ploting
plt.figure()
# In fig()
plt.plot(Attributed_Voxels_Growing.index,Attributed_Voxels_Growing.Air,color="k",lw=1, label = "Air Voxels", linestyle = '-')
plt.plot(Attributed_Voxels_Growing.index,Attributed_Voxels_Growing.OrM,color="k",lw=1, label = "OrM Voxels", linestyle = '--')
plt.plot(Attributed_Voxels_Growing.index,Attributed_Voxels_Growing.Grv,color="k",lw=1, label = "Grv Voxels", linestyle = '-.')
plt.plot(Attributed_Voxels_Growing.index,Attributed_Voxels_Growing.Itf,color="k",lw=1, label = "Int Voxels", linestyle = ':')
plt.plot(Attributed_Voxels_Growing.index,Attributed_Voxels_Growing.Tot,color="k",lw=2, label = "Sum", linestyle = '-')
plt.axhline(y = np.product(Image.shape), label = " Image Size", color = "red")
plt.title('Growing')
plt.xlabel('Step')
plt.ylabel('# Attributed Voxels')
plt.legend(fontsize = "small", loc = 'upper left')
# Saving the figure
chdir(path_lr)
Title = 'Growing_of_' + Scan_File.replace(Dir + '/' , "")[:-4]
plt.savefig(Title)
plt.close('all')
return (B_Air,B_OrM,B_Grv)
......@@ -363,7 +406,7 @@ def Compute_Thresholds(Tolerance, Parameters, Image_type, Histograms_without_PVE
Cut_1 = norm.ppf( Tolerance)*Parameters['Sigma1']+ Parameters['Mu1'] # ppf = percent point function
Cut_2a = norm.ppf(0.5-0.5*Tolerance)*Parameters['Sigma2']+ Parameters['Mu2']
Cut_2b = norm.ppf(0.5+0.5*Tolerance)*Parameters['Sigma2']+ Parameters['Mu2']
Cut_3 = norm.ppf(1 - 0.99)*Parameters['Sigma3']+ Parameters['Mu3']
Cut_3 = norm.ppf(1 - 0.999)*Parameters['Sigma3']+ Parameters['Mu3']
elif mode == 2:
Cut_1 = Parameters['Mu2'] - np.sqrt(-2*(Parameters['Sigma2']**2)*np.log(Tolerance))
Cut_2a = Parameters['Mu1'] + np.sqrt(-2*(Parameters['Sigma1']**2)*np.log(Tolerance))
......@@ -536,8 +579,8 @@ def Fitting_Three_Gaussians (Image_type, Histograms_without_PVE, N_bins, Mu, sli
if (Mu1<Mu2) & (Mu2<Mu3) & (Mu1>0) & (Mu2>0) & (Mu3>0) :
Messages.append ("Mu OK : Mu1 < Mu2 < Mu3 ")
else:
Messages.append ("Mu are NOT OK, Mu OK : Mu1 > Mu2 > Mu3")
print ("Mu are NOT OK", Mu1, Mu2, Mu3)
Messages.append ("Mu for section {} are NOT OK".format(VS+1))
print ("Mu for section {} are NOT OK".format(VS+1), Mu1, Mu2, Mu3)
raise ValueError
# Checking sigmas are not very high
......@@ -891,6 +934,7 @@ def Segmentation_Hashemi (Dir, Scan_File, Edges_File, PVE_percentiles = [60], Mu
Title = 'Messages_' + Scan_File.replace(Dir + '/' , "")[:-4] + '.csv'
chdir(path_lr)
MessagesDF.to_csv(Title, encoding = "utf-8")
stats_RAM = get_RAM_usage(stage = 'After Seed Creation', path = path_lr, frame_stats =stats_RAM)
......@@ -997,7 +1041,7 @@ def main():
# computing
f = decorateur_timeit(Segmentation_Hashemi)
f(Dir, Scan_File, Edges_File, PVE_percentiles, Mu, slices_VS, Tolerances, Save_Step, Mode_Threshold = 1, flag = flag, center = center, radius = radius)
main()
#main()
def main2():
global start , Dir, Scan_File, scan_file, PVE_percentile, Tolerance
......@@ -1018,4 +1062,4 @@ def main2():
# computing
f = decorateur_timeit(Segmentation_Hashemi)
f(Dir, Scan_File, Edges_File, PVE_percentiles, Mu, slices_VS, Tolerances, Save_Step, Mode_Threshold = 1, flag = flag, center = center, radius = radius)
main2()
\ No newline at end of file
main2()
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