From 65ecae56c83c8373f96d55751a773406abfb6260 Mon Sep 17 00:00:00 2001 From: zvezdochiot Date: Fri, 13 Jan 2023 18:49:32 +0300 Subject: [PATCH] 0.3.0: correct UM --- README.md | 48 ++++++++-------- man/man1/stbimmetrics.1 | 25 ++++---- src/metricsnhw.h | 4 +- src/metricspsnr.h | 4 +- src/metricsum.h | 123 +++++++++++++++++++++++++++++++--------- src/smallfry.h | 4 +- src/ssim.h | 4 +- src/stbimmetrics.c | 4 ++ src/ycbcr.h | 4 +- 9 files changed, 148 insertions(+), 72 deletions(-) diff --git a/README.md b/README.md index 303b501..978c70b 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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 --- diff --git a/man/man1/stbimmetrics.1 b/man/man1/stbimmetrics.1 index 47ed045..d789f2d 100644 --- a/man/man1/stbimmetrics.1 +++ b/man/man1/stbimmetrics.1 @@ -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 @@ -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. diff --git a/src/metricsnhw.h b/src/metricsnhw.h index 2664789..7770c26 100644 --- a/src/metricsnhw.h +++ b/src/metricsnhw.h @@ -6,7 +6,7 @@ **************************************************************************** * Metrics NHW * * file: metricsnhw.h * -* version: 0.2.9 * +* version: 0.3.0 * * * **************************************************************************** ***************************************************************************/ @@ -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 diff --git a/src/metricspsnr.h b/src/metricspsnr.h index 9338932..98f64db 100644 --- a/src/metricspsnr.h +++ b/src/metricspsnr.h @@ -2,7 +2,7 @@ **************************************************************************** * Metrics PSNR * * file: metricspsnr.h * -* version: 0.2.9 * +* version: 0.3.0 * * * **************************************************************************** ***************************************************************************/ @@ -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 diff --git a/src/metricsum.h b/src/metricsum.h index ccd9a31..b724871 100644 --- a/src/metricsum.h +++ b/src/metricsum.h @@ -2,7 +2,7 @@ **************************************************************************** * Metrics UM * * file: metricsum.h * -* version: 0.2.9 * +* version: 0.3.0 * * * **************************************************************************** ***************************************************************************/ @@ -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 @@ -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 @@ -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) { @@ -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 { @@ -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 { @@ -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 { @@ -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 diff --git a/src/smallfry.h b/src/smallfry.h index 8f91004..e958eda 100644 --- a/src/smallfry.h +++ b/src/smallfry.h @@ -18,7 +18,7 @@ **************************************************************************** * Metrics PSNR * * file: metricspsnr.h * -* version: 0.2.9 * +* version: 0.3.0 * * * **************************************************************************** ***************************************************************************/ @@ -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 diff --git a/src/ssim.h b/src/ssim.h index 2481dc3..872bcb2 100644 --- a/src/ssim.h +++ b/src/ssim.h @@ -6,7 +6,7 @@ **************************************************************************** * Metrics SSIM * * file: ssim.h * -* version: 0.2.9 * +* version: 0.3.0 * * * **************************************************************************** ***************************************************************************/ @@ -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 diff --git a/src/stbimmetrics.c b/src/stbimmetrics.c index 5c950ca..a68dac0 100644 --- a/src/stbimmetrics.c +++ b/src/stbimmetrics.c @@ -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) { diff --git a/src/ycbcr.h b/src/ycbcr.h index f0ee531..ddc5a18 100644 --- a/src/ycbcr.h +++ b/src/ycbcr.h @@ -2,7 +2,7 @@ **************************************************************************** * YCbCr Filter * * file: ycbcr.h * -* version: 0.2.9 * +* version: 0.3.0 * * * **************************************************************************** ***************************************************************************/ @@ -13,7 +13,7 @@ #ifndef __YCBCR__H #define __YCBCR__H -#define YCBCR_VERSION "0.2.9" +#define YCBCR_VERSION "0.3.0" #ifdef METRICS_STATIC #define METRICSAPI static