Skip to content

Commit

Permalink
0.3.0: correct UM
Browse files Browse the repository at this point in the history
  • Loading branch information
zvezdochiot committed Jan 13, 2023
1 parent abf2506 commit 65ecae5
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 72 deletions.
48 changes: 24 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,18 @@ stbnhwmetrics ${IMAGE_ORIG_PATH} ${IMAGE_COMPARE_PATH} [metric.out.png]
Trends:

```
UM = -216.75*MPE+1.73
UM = 1.10*sqrt(PNSR)-6.07
UM = 2.38*cor_sigma(cor_sigma(cor_sigma(SSIM)))-0.24
UM = 1.87*cor_sigma(cor_sigma(MS_SSIM))-0.02
UM = 0.0747*SMALLFRY-6.91
UM = 1.48*SHARPENBAD-0.26
UM = 3.00*COR-1.50
UM = 0.56*sqrt(sqrt(1.0/NHW-C))-0.95
UM = 0.62*sqrt(sqrt(1.0/NHW-N))-1.05
UM = 0.59*sqrt(sqrt(1.0/NHW-R))-1.12
cor_sigma(M) = 1.0-sqrt(1.0-M*M)
UM = 0.148 * sqrt(sqrt(1.0 / MSE)) - 0.53
UM = 0.94 * sqrt(PNSR) - 4.94
UM = 8.57 * cor_sigma(cor_sigma(cor_sigma(SSIM))) + 0.34
UM = 2.21 * cor_sigma(VIFP1) + 0.36
UM = 0.0735 * SMALLFRY - 6.50
UM = 1.46 * SHARPENBAD - 0.04
UM = 3.92 * cor_sigma(cor_sigma(COR)) - 1.79
UM = -0.049 * sqrt(sqrt(1.0 / NHW-N)) + 0.83
UM = 1.36 * sqrt(sqrt(1.0 / NHW-C)) - 2.61
UM = 0.96 * sqrt(sqrt(1.0 / NHW-R)) - 1.98
cor_sigma(M) = 1.0 - sqrt(1.0 - M * M)
```

Origin and Compare:
Expand All @@ -135,18 +135,18 @@ Save png: lena.quant444.psnr.png

```

* ![metric](https://raw.githubusercontent.com/ImageProcessing-ElectronicPublications/stb-image-metrics-demo/main/images/lena.quant444.mse.png) MSE: 0.013604, UM: -1.218735
* ![metric](https://raw.githubusercontent.com/ImageProcessing-ElectronicPublications/stb-image-metrics-demo/main/images/lena.quant444.psnr.png) PSNR: 18.663233, UM: -1.317894
* ![metric](https://raw.githubusercontent.com/ImageProcessing-ElectronicPublications/stb-image-metrics-demo/main/images/lena.quant444.mse-c.png) MSE-C: 0.006495, UM: -
* ![metric](https://raw.githubusercontent.com/ImageProcessing-ElectronicPublications/stb-image-metrics-demo/main/images/lena.quant444.psnr-c.png) PSNR-C: 21.873943, UM: -
* ![metric](https://raw.githubusercontent.com/ImageProcessing-ElectronicPublications/stb-image-metrics-demo/main/images/lena.quant444.ssim.png) SSIM: 0.618509, UM: -0.239359
* ![metric](https://raw.githubusercontent.com/ImageProcessing-ElectronicPublications/stb-image-metrics-demo/main/images/lena.quant444.vifp1.png) VIFP1: 0.170903, UM: -
* ![metric](https://raw.githubusercontent.com/ImageProcessing-ElectronicPublications/stb-image-metrics-demo/main/images/lena.quant444.smallfry.png) SMALLFRY: 83.753342, UM: -0.653625
* ![metric](https://raw.githubusercontent.com/ImageProcessing-ElectronicPublications/stb-image-metrics-demo/main/images/lena.quant444.shbad.png) SHARPENBAD: -0.213132, UM: -0.575435
* ![metric](https://raw.githubusercontent.com/ImageProcessing-ElectronicPublications/stb-image-metrics-demo/main/images/lena.quant444.cor.png) Corelation: 0.953666, UM: -0.644979
* ![metric](https://raw.githubusercontent.com/ImageProcessing-ElectronicPublications/stb-image-metrics-demo/main/images/lena.quant444.nhw-n.png) NHW-N: 0.072673, UM: 0.144120
* ![metric](https://raw.githubusercontent.com/ImageProcessing-ElectronicPublications/stb-image-metrics-demo/main/images/lena.quant444.nhw-c.png) NHW-C: 0.145290, UM: -0.042954
* ![metric](https://raw.githubusercontent.com/ImageProcessing-ElectronicPublications/stb-image-metrics-demo/main/images/lena.quant444.nhw-r.png) NHW-R: 0.116387, UM: -0.109872
* ![metric](https://raw.githubusercontent.com/ImageProcessing-ElectronicPublications/stb-image-metrics-demo/main/images/lena.quant444.mse.png) MSE: 0.013604, UM: -0.090790
* ![metric](https://raw.githubusercontent.com/ImageProcessing-ElectronicPublications/stb-image-metrics-demo/main/images/lena.quant444.mse-c.png) MSE-C: 0.006495, UM: -0.001628
* ![metric](https://raw.githubusercontent.com/ImageProcessing-ElectronicPublications/stb-image-metrics-demo/main/images/lena.quant444.psnr.png) PSNR: 18.663233, UM: -0.879109
* ![metric](https://raw.githubusercontent.com/ImageProcessing-ElectronicPublications/stb-image-metrics-demo/main/images/lena.quant444.psnr-c.png) PSNR-C: 21.873943, UM: -0.543659
* ![metric](https://raw.githubusercontent.com/ImageProcessing-ElectronicPublications/stb-image-metrics-demo/main/images/lena.quant444.cor.png) Corelation: 0.953666, UM: -0.672773
* ![metric](https://raw.githubusercontent.com/ImageProcessing-ElectronicPublications/stb-image-metrics-demo/main/images/lena.quant444.ssim.png) SSIM: 0.618509, UM: 0.342309
* ![metric](https://raw.githubusercontent.com/ImageProcessing-ElectronicPublications/stb-image-metrics-demo/main/images/lena.quant444.vifp1.png) VIFP1: 0.170903, UM: 0.392514
* ![metric](https://raw.githubusercontent.com/ImageProcessing-ElectronicPublications/stb-image-metrics-demo/main/images/lena.quant444.smallfry.png) SMALLFRY: 83.753342, UM: -0.344130
* ![metric](https://raw.githubusercontent.com/ImageProcessing-ElectronicPublications/stb-image-metrics-demo/main/images/lena.quant444.shbad.png) SHARPENBAD: -0.213132, UM: -0.351173
* ![metric](https://raw.githubusercontent.com/ImageProcessing-ElectronicPublications/stb-image-metrics-demo/main/images/lena.quant444.nhw-n.png) NHW-N: 0.072673, UM: 0.735626
* ![metric](https://raw.githubusercontent.com/ImageProcessing-ElectronicPublications/stb-image-metrics-demo/main/images/lena.quant444.nhw-c.png) NHW-C: 0.145290, UM: -0.407173
* ![metric](https://raw.githubusercontent.com/ImageProcessing-ElectronicPublications/stb-image-metrics-demo/main/images/lena.quant444.nhw-r.png) NHW-R: 0.116387, UM: -0.336402

---

Expand Down
25 changes: 13 additions & 12 deletions man/man1/stbimmetrics.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH "StbImMetrics" 1 0.2.8 "9 Jan 2023" "User Manual"
.TH "StbImMetrics" 1 0.3.0 "13 Jan 2023" "User Manual"

.SH NAME
stbimmetrics
Expand Down Expand Up @@ -93,17 +93,18 @@ stbnhwmetrics -m nhw-r lena.png lena.quant444.png lena.quant444.nhw-r.png
.PP
Trends:

UM = -216.75*MPE+1.73
UM = 1.10*sqrt(PNSR)-6.07
UM = 2.38*cor_sigma(cor_sigma(cor_sigma(SSIM)))-0.24
UM = 1.87*cor_sigma(cor_sigma(MS_SSIM))-0.02
UM = 0.0747*SMALLFRY-6.91
UM = 1.48*SHARPENBAD-0.26
UM = 3.00*COR-1.50
UM = 0.56*sqrt(sqrt(1.0/NHW-C))-0.95
UM = 0.62*sqrt(sqrt(1.0/NHW-N))-1.05
UM = 0.59*sqrt(sqrt(1.0/NHW-R))-1.12
cor_sigma(M) = 1.0-sqrt(1.0-M*M)
UM = 0.148 * sqrt(sqrt(1.0 / MSE)) - 0.53
UM = 0.94 * sqrt(PNSR) - 4.94
UM = 8.57 * cor_sigma(cor_sigma(cor_sigma(SSIM))) + 0.34
UM = 2.21 * cor_sigma(VIFP1) + 0.36
UM = 0.0735 * SMALLFRY - 6.50
UM = 1.46 * SHARPENBAD - 0.04
UM = 3.92 * cor_sigma(cor_sigma(COR)) - 1.79
UM = -0.049 * sqrt(sqrt(1.0 / NHW-N)) + 0.83
UM = 1.36 * sqrt(sqrt(1.0 / NHW-C)) - 2.61
UM = 0.96 * sqrt(sqrt(1.0 / NHW-R)) - 1.98

cor_sigma(M) = 1.0 - sqrt(1.0 - M * M)

.SH COPYRIGHT
This is free and unencumbered software released into the public domain.
Expand Down
4 changes: 2 additions & 2 deletions src/metricsnhw.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
****************************************************************************
* Metrics NHW *
* file: metricsnhw.h *
* version: 0.2.9 *
* version: 0.3.0 *
* *
****************************************************************************
***************************************************************************/
Expand All @@ -18,7 +18,7 @@
#ifndef __METRICS_NHW__H
#define __METRICS_NHW__H

#define METRICSNHW_VERSION "0.2.9"
#define METRICSNHW_VERSION "0.3.0"

#ifdef METRICS_STATIC
#define METRICSAPI static
Expand Down
4 changes: 2 additions & 2 deletions src/metricspsnr.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
****************************************************************************
* Metrics PSNR *
* file: metricspsnr.h *
* version: 0.2.9 *
* version: 0.3.0 *
* *
****************************************************************************
***************************************************************************/
Expand All @@ -14,7 +14,7 @@
#ifndef __METRICS_PSNR__H
#define __METRICS_PSNR__H

#define METRICS_PSNR_VERSION "0.2.9"
#define METRICS_PSNR_VERSION "0.3.0"

#ifdef METRICS_STATIC
#define METRICSAPI static
Expand Down
123 changes: 97 additions & 26 deletions src/metricsum.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
****************************************************************************
* Metrics UM *
* file: metricsum.h *
* version: 0.2.9 *
* version: 0.3.0 *
* *
****************************************************************************
***************************************************************************/
Expand All @@ -15,7 +15,7 @@
#ifndef __METRICS_UM__H
#define __METRICS_UM__H

#define METRICS_VERSION "0.2.9"
#define METRICS_VERSION "0.3.0"

#ifdef METRICS_STATIC
#define METRICSAPI static
Expand All @@ -27,6 +27,7 @@
extern "C" {
#endif
METRICSAPI float metric_um(char* metric, float value);
METRICSAPI float metric_um_image(unsigned char* delta, int height, int width, int channels, char* metric, float umval);
#ifdef __cplusplus
}
#endif
Expand Down Expand Up @@ -54,48 +55,57 @@ float metricssigma(float cor)
/* Universal scale of Metrics */
METRICSAPI float metric_um(char* metric, float value)
{
if (strcmp(metric, "mse") == 0)
if ((strcmp(metric, "mse") == 0) || (strcmp(metric, "mse-c") == 0))
{
value *= -216.75f;
value += 1.73f;
if (value > 0.0f)
{
value = 1.0f / value;
value = sqrt(value);
value = sqrt(value);
value *= 0.148f;
value -= 0.53f;
}
else
{
value = 1.0f;
}
}
else if (strcmp(metric, "psnr") == 0)
else if ((strcmp(metric, "psnr") == 0) || (strcmp(metric, "psnr-c") == 0))
{
value = sqrt(value);
value *= 1.10f;
value -= 6.07f;
value *= 0.94f;
value -= 4.94f;
}
else if (strcmp(metric, "ssim") == 0)
{
value = metricssigma(value);
value = metricssigma(value);
value = metricssigma(value);
value *= 2.38f;
value -= 0.24f;
value *= 8.57f;
value += 0.34f;
}
else if (strcmp(metric, "ms-ssim") == 0)
else if (strcmp(metric, "vifp1") == 0)
{
value = metricssigma(value);
value = metricssigma(value);
value *= 1.87f;
value -= 0.02f;
value *= 2.21f;
value += 0.36f;
}
else if (strcmp(metric, "smallfry") == 0)
{
value *= 0.0747f;
value -= 6.91f;
value *= 0.0735f;
value -= 6.50f;
}
else if (strcmp(metric, "shbad") == 0)
{
value *= 1.48f;
value -= 0.26f;
value *= 1.46f;
value -= 0.04f;
}
else if (strcmp(metric, "cor") == 0)
{
value = metricssigma(value);
value = metricssigma(value);
value *= 3.00f;
value -= 1.50f;
value *= 3.92f;
value -= 1.79f;
}
else if (strcmp(metric, "nhw-c") == 0)
{
Expand All @@ -104,8 +114,8 @@ METRICSAPI float metric_um(char* metric, float value)
value = 1.0f / value;
value = sqrt(value);
value = sqrt(value);
value *= 0.56f;
value -= 0.95f;
value *= 1.36f;
value -= 2.61f;
}
else
{
Expand All @@ -119,8 +129,8 @@ METRICSAPI float metric_um(char* metric, float value)
value = 1.0f / value;
value = sqrt(value);
value = sqrt(value);
value *= 0.62f;
value -= 1.05f;
value *= -0.049f;
value += 0.83f;
}
else
{
Expand All @@ -134,8 +144,8 @@ METRICSAPI float metric_um(char* metric, float value)
value = 1.0f / value;
value = sqrt(value);
value = sqrt(value);
value *= 0.59f;
value -= 1.12f;
value *= 0.96f;
value -= 1.98f;
}
else
{
Expand All @@ -146,6 +156,67 @@ METRICSAPI float metric_um(char* metric, float value)
return value;
}

METRICSAPI float metric_um_image(unsigned char* delta, int height, int width, int channels, char* metric, float umval)
{
float value, suml, sum = 0.0f;
size_t k;
int y, x, d, cval;


if (delta)
{
k = 0;
sum = 0;
for (y = 0; y < height; y++)
{
suml = 0.0f;
for (x = 0; x < width; x++)
{
for (d = 0; d < channels; d++)
{
value = (float)delta[k];
value /= 255;
if ((strcmp(metric, "mse") == 0) || (strcmp(metric, "mse-c") == 0))
{
value *= value;
}
else if ((strcmp(metric, "psnr") == 0) || (strcmp(metric, "psnr-c") == 0))
{
value *= 255.0f;
}
else if (strcmp(metric, "shbad") == 0)
{
value -= 0.5f;
value *= 2.0f;
}
else if (strcmp(metric, "smallfry") == 0)
{
value *= 255.0f;
}
else if (strcmp(metric, "nhw-n") == 0)
{
value -= 0.5f;
}
value = metric_um(metric, value);
value -= umval;
value *= 127.5;
value += 0.5f;
cval = (int)((value < 0.0f) ? 0 : (value < 255.0f) ? value : 255);
value -= 0.5f;
suml += (value > cval) ? (value - (float)cval) : ((float)cval - value);
if (delta) delta[k] = (unsigned char)cval;
k++;
}
}
sum += suml;
}
sum /= (float)k;
sum /= 255.0f;
}

return sum;
}

#endif /* METRICS_UM_IMPLEMENTATION */

#endif // __METRICS_UM__H
4 changes: 2 additions & 2 deletions src/smallfry.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
****************************************************************************
* Metrics PSNR *
* file: metricspsnr.h *
* version: 0.2.9 *
* version: 0.3.0 *
* *
****************************************************************************
***************************************************************************/
Expand All @@ -31,7 +31,7 @@
#ifndef __METRICS_SMALLFRY__H
#define __METRICS_SMALLFRY__H

#define METRICS_SMALLFRY_VERSION "0.2.9"
#define METRICS_SMALLFRY_VERSION "0.3.0"

#ifdef METRICS_STATIC
#define METRICSAPI static
Expand Down
4 changes: 2 additions & 2 deletions src/ssim.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
****************************************************************************
* Metrics SSIM *
* file: ssim.h *
* version: 0.2.9 *
* version: 0.3.0 *
* *
****************************************************************************
***************************************************************************/
Expand All @@ -19,7 +19,7 @@
#ifndef SSIM_H_
#define SSIM_H_

#define METRICS_SSIM_VERSION "0.2.9"
#define METRICS_SSIM_VERSION "0.3.0"

#ifdef METRICS_STATIC
#define METRICSAPI static
Expand Down
4 changes: 4 additions & 0 deletions src/stbimmetrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ int main(int argc, char **argv)
if (fum)
{
neatness = metric_um(metric, neatness);
if (name_m)
{
(void)metric_um_image(data_m, height, width, channels, metric, neatness);
}
}
if (!fquiet)
{
Expand Down
Loading

0 comments on commit 65ecae5

Please sign in to comment.