Skip to content

Commit

Permalink
2.6.0: added VIFP1 in SUM metric
Browse files Browse the repository at this point in the history
  • Loading branch information
zvezdochiot committed Jan 31, 2023
1 parent 9bc2e72 commit a41a0ce
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 33 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
JPEG Recompress
https://github.com/ImageProcessing-ElectronicPublications/jpeg-recompress

2.6.0 "sum"

Added VIFP 1 layer in SUM metric.

2.5.9 "vifp1"

Added VIFP 1 layer metric.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Correlation | `-m cor` | [Correlation](https://en.wikipedia.org/wiki/Correl
NHW | `-m nhw` | NHW convolutional metric ([original project](https://github.com/rcanut/NHW_Neatness_Metrics) -> [LibSmallFry](https://github.com/ImageProcessing-ElectronicPublications/libsmallfry))
1 pair | `-m ssimfry` | `(ssim + smallfry) / 2`
2 pair | `-m ssimshb` | `(ssim + shbad) / 2`
SUMMARY | `-m sum` | `(ssim + smallfry + shbad + nhw) / 4` **DEFAULT**
SUMMARY | `-m sum` | `(ssim + vipf1 + smallfry + shbad + nhw) / 5` **DEFAULT**

**Note**: The SmallFry algorithm may be [patented](http://www.jpegmini.com/main/technology) so use with caution.

Expand Down
2 changes: 1 addition & 1 deletion man/man1/jpeg-compare.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH "jpeg-compare" 2.5.9 "15 Jan 2023" "User manual"
.TH "jpeg-compare" 1 2.6.0 "31 Jan 2023" "User manual"

.SH NAME
jpeg-compare
Expand Down
2 changes: 1 addition & 1 deletion man/man1/jpeg-hash.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH "jpeg-hash" 2.5.9 "15 Jan 2023" "User manual"
.TH "jpeg-hash" 1 2.6.0 "31 Jan 2023" "User manual"

.SH NAME
jpeg-hash
Expand Down
2 changes: 1 addition & 1 deletion man/man1/jpeg-recompress.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH "jpeg-recompress" 2.5.9 "15 Jan 2023" "User manual"
.TH "jpeg-recompress" 1 2.6.0 "31 Jan 2023" "User manual"

.SH NAME
jpeg-recompress
Expand Down
2 changes: 1 addition & 1 deletion man/man1/jpeg-zfpoint.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH "jpeg-zfpoint" 2.5.9 "15 Jan 2023" "User manual"
.TH "jpeg-zfpoint" 1 2.6.0 "31 Jan 2023" "User manual"

.SH NAME
jpeg-zfpoint
Expand Down
2 changes: 1 addition & 1 deletion man/man1/webp-compress.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH "webp-compress" 2.5.9 "15 Jan 2023" "User manual"
.TH "webp-compress" 1 2.6.0 "31 Jan 2023" "User manual"

.SH NAME
webp-compress
Expand Down
72 changes: 47 additions & 25 deletions src/jmetrics.c
Original file line number Diff line number Diff line change
@@ -1,32 +1,52 @@
#include "jmetrics.h"

#define INPUT_BUFFER_SIZE 102400
#define MAX_SUM_COUNT 5

float clamp(float low, float value, float high)
{
return (value < low) ? low : ((value > high) ? high : value);
}

float waverage4(float x1, float x2, float x3, float x4)
float waverage(float *x, int count)
{
float xm, dx1, dx2 ,dx3, dx4, dxs, w1, w2, w3, w4, ws;
xm = x1 + x2 + x3 + x4;
xm *= 0.25f;
dx1 = (x1 - xm) * (x1 - xm);
dx2 = (x2 - xm) * (x2 - xm);
dx3 = (x3 - xm) * (x3 - xm);
dx4 = (x4 - xm) * (x4 - xm);
dxs = dx1 + dx2 + dx3 + dx4;
dxs *= 0.25f;
int i, n;
float xm, delta, dx[MAX_SUM_COUNT], dxs, w[MAX_SUM_COUNT], ws;

xm = 0.0f;
n = 0;
for (i = 0; i < count; i++)
{
xm += x[i];
n++;
}
n = (n > 0) ? n : 1;
xm /= (float)n;
dxs = 0.0f;
for (i = 0; i < count; i++)
{
delta = x[i] - xm;
dx[i] = delta * delta;
dxs += dx[i];
}
dxs /= (float)n;
if (dxs > 0.0f)
{
w1 = dxs / (dxs + dx1);
w2 = dxs / (dxs + dx2);
w3 = dxs / (dxs + dx3);
w4 = dxs / (dxs + dx4);
ws = w1 + w2 + w3 + w4;
ws = 0.0f;
for (i = 0; i < count; i++)
{
w[i] = dxs / (dxs + dx[i]);
ws += w[i];
}
if (ws > 0.0f)
xm = (w1 * x1 + w2 * x2 + w3 * x3 + w4 * x4) / ws;
{
xm = 0.0f;
for (i = 0; i < count; i++)
{
xm += (w[i] * x[i]);
}
xm /= ws;
}
}
return xm;
}
Expand Down Expand Up @@ -149,7 +169,7 @@ void scale(unsigned char *image, int width, int height, unsigned char **newImage
{
int y, x, oldY, oldX;
unsigned long int k, size;

size = (unsigned long int) newWidth * newHeight;

*newImage = malloc(size);
Expand Down Expand Up @@ -294,11 +314,11 @@ unsigned long int readFile(char *name, void **buffer)
}

*buffer = malloc(sizeof chunk);

while ((bytesRead = fread(chunk, 1, sizeof chunk, file)) > 0)
{
unsigned char *reallocated = realloc(*buffer, fileLen + bytesRead);

if (reallocated)
{
*buffer = reallocated;
Expand Down Expand Up @@ -935,7 +955,7 @@ float MetricSigma(float cor)

float MetricCalc(int method, unsigned char *image1, unsigned char *image2, int width, int height, int components)
{
float diff, tmetric, tm1, tm2, tm3, tm4;
float diff, tmetric, tm[MAX_SUM_COUNT];

// Calculate and print comparison
switch (method)
Expand Down Expand Up @@ -984,14 +1004,16 @@ float MetricCalc(int method, unsigned char *image1, unsigned char *image2, int w
case SUMMET:
default:
tmetric = iqa_ssim(image1, image2, width, height, width * components, 0, 0);
tm1 = RescaleMetric(SSIM, tmetric);
tm[0] = RescaleMetric(SSIM, tmetric);
tmetric = metric_smallfry(image1, image2, width, height);
tm2 = RescaleMetric(SMALLFRY, tmetric);
tm[1] = RescaleMetric(SMALLFRY, tmetric);
tmetric = metric_sharpenbad(image1, image2, width, height);
tm3 = RescaleMetric(SHARPENBAD, tmetric);
tm[2] = RescaleMetric(SHARPENBAD, tmetric);
tmetric = metric_nhw(image1, image2, width, height);
tm4 = RescaleMetric(NHW, tmetric);
diff = waverage4(tm1, tm2, tm3, tm4);
tm[3] = RescaleMetric(NHW, tmetric);
tmetric = iqa_vifp1(image1, image2, width, height, width * components, 0, 0);
tm[4] = RescaleMetric(VIFP1, tmetric);
diff = waverage(tm, 5);
break;
}
return diff;
Expand Down
4 changes: 2 additions & 2 deletions src/jmetrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#define JMETRICS_H

#ifndef JMVERSION
#define JMVERSION "2.5.8"
#define JMVERSION "2.6.0"
#endif

#define MIN(a, b) ((a) < (b) ? (a) : (b))
Expand Down Expand Up @@ -204,6 +204,6 @@ float MetricCalc(int method, unsigned char *image1, unsigned char *image2, int w
float MetricSigma(float cor);
int compareFastFromBuffer(unsigned char *imageBuf1, long bufSize1, unsigned char *imageBuf2, long bufSize2, int printPrefix, int size);
int compareFromBuffer(int method, unsigned char *imageBuf1, long bufSize1, unsigned char *imageBuf2, long bufSize2, int printPrefix, int umscale, enum filetype inputFiletype1, enum filetype inputFiletype2);
float waverage4(float x1, float x2, float x3, float x4);
float waverage(float *x, int count);

#endif

0 comments on commit a41a0ce

Please sign in to comment.