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
8dd47386
Commit
8dd47386
authored
1 year ago
by
Nuno Pimpão Santos Martins
Browse files
Options
Downloads
Patches
Plain Diff
add best psnr from n2v source
parent
ffa55b59
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
utils.py
+38
-4
38 additions, 4 deletions
utils.py
with
38 additions
and
4 deletions
utils.py
+
38
−
4
View file @
8dd47386
...
...
@@ -6,6 +6,7 @@ import warnings
import
pywt
from
skimage.filters
import
gaussian
from
skimage.transform
import
rescale
from
csbdeep.utils.utils
import
normalize_minmse
# warnings.simplefilter('ignore', category=NumbaDeprecationWarning)
# warnings.simplefilter('ignore', category=NumbaPendingDeprecationWarning)
...
...
@@ -280,12 +281,45 @@ def PSNR(gt, pred, range_=4095.0):
psnr_indices
=
np
.
zeros
((
gt
.
shape
[
0
]),
dtype
=
'
float32
'
)
for
z
in
range
(
gt
.
shape
[
0
]):
mse
=
np
.
mean
((
gt
[
z
]
-
pred
[
z
])
**
2
)
psnr
=
20
*
np
.
log10
((
range_
)
/
np
.
sqrt
(
mse
))
psnr_indices
[
z
]
=
psnr
#
mse = np.mean((gt[z] - pred[z])**2)
#
psnr = 20 * np.log10((range_)/np.sqrt(mse))
psnr_indices
[
z
]
=
best_PSNR
(
gt
[
z
],
pred
[
z
],
range_
)
return
psnr_indices
def
PSNR_single
(
gt
,
img
,
range
):
"""
Compute Peak Signal-to-Noise Ratio.
Parameters:
gt: np.array
The ground truth target image.
img: np.array
The image of interest.
range: float
Intensity range e.g. gt.max() - gt.min() used for the PSNR
computation.
"""
mse
=
np
.
mean
(
np
.
square
(
gt
-
img
))
return
20
*
np
.
log10
(
range
)
-
10
*
np
.
log10
(
mse
)
def
best_PSNR
(
gt
,
img
,
range
):
"""
Compute best Peak Signal-to-Noise Ratio by normalizing img such that
MSE is minimized to the gt image.
Parameters:
gt: np.array
The ground truth target image.
img: np.array
The image of interest.
range: float
Intensity range e.g. gt.max() - gt.min() used for the PSNR
computation.
"""
img_n
=
normalize_minmse
(
img
,
gt
)
return
PSNR_single
(
gt
,
img_n
,
range
=
range
)
def
MSE
(
gt
,
pred
):
"""
TODO add description
...
...
@@ -310,4 +344,4 @@ def MAE(gt, pred):
for
z
in
range
(
gt
.
shape
[
0
]):
mae_values
[
z
]
=
np
.
mean
((
gt
[
z
]
-
pred
[
z
]))
return
mae_values
\ No newline at end of file
return
mae_values
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