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

the last version of the relabelling

ne marchait pas bien.
Celle là oui!
parent f0c4b05f
......@@ -73,9 +73,6 @@ def connect_CR(path_read, file_top, file_bot, path_save, sample_name):
print("eliminating circle artifact")
top = eliminating_circle_artifact(top)
bot = eliminating_circle_artifact(bot)
chdir(path_save)
tifffile.imsave('bot.tif', bot)
tifffile.imsave('top.tif', top)
a = len(np.unique(top))
b = len(np.unique(bot))
......@@ -258,43 +255,34 @@ def connect_CR(path_read, file_top, file_bot, path_save, sample_name):
print("Final relabel...")
pores = np.sort(np.unique(connected_image))
ll_1 = len(pores)
print(ll_1)
print(pores)
old_labels = np.unique(connected_image)
print(old_labels, len(old_labels))
ll_1 = len(old_labels)
#lables_to_be_replaced
ltbr = old_labels[old_labels >= ll_1]
print(ltbr, len(ltbr))
for i in range(ll_1):
progression = int((i/ll_1)*100)
if progression % 2 == 0:
print("{}%".format(progression))
new_label = i
if new_label in pores :
print("no need to relabel")
continue
else:
old_label = pores[i]
mask = (connected_image == old_label)
connected_image[mask] = new_label
#print("Pore {} has been relabeld to {}".format(old_label, new_label))
# final_label = 0
# for pore in pores:
#
new_label = 0
counter = 0
for old_label in ltbr:
while new_label in old_labels:
print("old label {} cannot be replaced by new_label {} ".format(old_label, new_label))
new_label += 1
print("old label {} WILL be replaced by new_label {} ".format(old_label, new_label))
mask = connected_image == old_label
connected_image[mask] = new_label
if counter % 2 == 0:
print('... progression {}/{}'.format(counter+1, len(ltbr)))
counter += 1
new_label += 1
# mask = (connected_image == pore)
# connected_image[mask] = final_label
# final_label +=1
pores = np.sort(np.unique(connected_image))
ll_2 = len(pores)
print(ll_2)
assert(ll_1==ll_2)
chdir(path_save)
tifffile.imsave("CR_{}.tif".format(sample_name) , connected_image)
new_labels = np.unique(connected_image)
print(new_labels, len(new_labels))
ll_2 = len(new_labels)
assert(ll_2 == ll_1)
assert(np.max(new_labels) + 1 == ll_2)
print('Connection OK !')
path_read = "/home/german.martinez-carvajal/Bureau/These/Connecting_CR/test"
......
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