Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Contrast Enhancement with UNet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nuno Pimpão Santos Martins
Contrast Enhancement with UNet
Commits
ccef6c78
Commit
ccef6c78
authored
1 year ago
by
Nuno Pimpão Santos Martins
Browse files
Options
Downloads
Patches
Plain Diff
new script to restore mask of a single folder
parent
003268ae
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
iou_restore_mask_oneolderonly.py
+104
-0
104 additions, 0 deletions
iou_restore_mask_oneolderonly.py
with
104 additions
and
0 deletions
iou_restore_mask_oneolderonly.py
0 → 100644
+
104
−
0
View file @
ccef6c78
import
os
import
numpy
as
np
import
matplotlib.pyplot
as
plt
import
tifffile
from
utils
import
*
from
segmentation
import
*
import
time
import
datetime
from
tqdm
import
tqdm
# ---
# Load threshold data
# ---
table_path
=
'
w:
\\
NPC_adult_new
\\
quantification_data
\\
iou_quantification
\\
iou_quantification_dlwithbiasx3_2023-07-20
\\
'
table_list
=
os
.
listdir
(
table_path
)
table_list
.
sort
()
table_list
=
[
x
for
x
in
table_list
if
x
.
find
(
'
.csv
'
)
>
0
]
# ---
# Data Import
# ---
# results paths
results_path
=
'
w:
\\
NPC_adult_new
\\
dl_training
\\
results
\\
contrastenhance_128x128px_maeloss_20pxblurrad_poissonnoise_adaptive0p6to0p5_unet5
\\
'
pred1_mask_path
=
results_path
+
'
results_20230129_x3
\\
'
pred1_suffix_substring
=
'
.tif
'
pred1_save_path
=
os
.
path
.
join
(
pred1_mask_path
,
'
masks
'
)
if
not
os
.
path
.
exists
(
pred1_save_path
):
os
.
mkdir
(
pred1_save_path
)
# pred2_mask_path = results_path+'results_x2\\'
# pred2_suffix_substring = '_x2.tif'
# pred2_save_path = os.path.join(pred2_mask_path, 'masks')
# if not os.path.exists(pred2_save_path):
# os.mkdir(pred2_save_path)
# pred3_mask_path = results_path+'results_x3\\'
# pred3_suffix_substring = '_x3.tif'
# pred3_save_path = os.path.join(pred3_mask_path, 'masks')
# if not os.path.exists(pred3_save_path):
# os.mkdir(pred3_save_path)
time_start_script
=
time
.
time
()
for
table_name
in
tqdm
(
table_list
,
total
=
len
(
table_list
)):
data_table
=
[]
with
open
(
os
.
path
.
join
(
table_path
,
table_name
),
"
r
"
)
as
file
:
for
line
in
file
:
line_proc
=
line
.
split
(
'
,
'
)
try
:
test
=
float
(
line_proc
[
0
])
except
:
continue
parsed_line
=
[]
for
i
in
range
(
len
(
line_proc
)):
try
:
item
=
float
(
line_proc
[
i
])
except
:
continue
parsed_line
.
append
(
item
)
data_table
.
append
(
parsed_line
)
data_table
=
np
.
asarray
(
data_table
,
dtype
=
'
float32
'
)
# print('data len: ', data_table.shape)
# print('line len: ', data_table[0].shape)
table_name_noext
=
table_name
[
12
:
table_name
.
index
(
'
_mask
'
)]
print
(
table_name_noext
)
time_image
=
time
.
time
()
# to check if loaded images are the same
print
(
'
Loading image:
'
,
table_name_noext
)
print
(
'
Loading pred1 image name:
'
)
table_1
=
data_table
[:,
2
]
image_pred
=
tifffile
.
imread
(
os
.
path
.
join
(
pred1_mask_path
,
table_name_noext
+
pred1_suffix_substring
)).
astype
(
'
float32
'
)
pred1_mask
=
make_mask_from_values
(
image_pred
,
table_1
)
tifffile
.
imwrite
(
os
.
path
.
join
(
pred1_save_path
,
table_name_noext
+
pred1_suffix_substring
),
pred1_mask
)
# print('Loading pred2 image name: ')
# table_2 = data_table[:, 4]
# # print(table_2.shape)
# # print(table_2[:10])
# # stop
# image_pred2 = tifffile.imread(os.path.join(pred2_mask_path, table_name_noext+pred2_suffix_substring)).astype('float32')
# pred2_mask = make_mask_from_values(image_pred2, table_2)
# tifffile.imwrite(os.path.join(pred2_save_path, table_name_noext+pred2_suffix_substring), pred2_mask)
# print('Loading pred3 image name: ')
# table_3 = data_table[:, 6]
# image_pred3 = tifffile.imread(os.path.join(pred3_mask_path, table_name_noext+pred3_suffix_substring)).astype('float32')
# pred3_mask = make_mask_from_values(image_pred3, table_3)
# tifffile.imwrite(os.path.join(pred3_save_path, table_name_noext+pred3_suffix_substring), pred3_mask)
print
(
'
Time per image:
'
,
time
.
time
()
-
time_image
)
print
(
'
Time:
'
,
time
.
time
()
-
time_start_script
)
print
(
'
Done
'
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment