Skip to content

Commit a41a0ce

Browse files
committed
2.6.0: added VIFP1 in SUM metric
1 parent 9bc2e72 commit a41a0ce

File tree

9 files changed

+59
-33
lines changed

9 files changed

+59
-33
lines changed

CHANGELOG

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
JPEG Recompress
22
https://github.com/ImageProcessing-ElectronicPublications/jpeg-recompress
33

4+
2.6.0 "sum"
5+
6+
Added VIFP 1 layer in SUM metric.
7+
48
2.5.9 "vifp1"
59

610
Added VIFP 1 layer metric.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Correlation | `-m cor` | [Correlation](https://en.wikipedia.org/wiki/Correl
6363
NHW | `-m nhw` | NHW convolutional metric ([original project](https://github.com/rcanut/NHW_Neatness_Metrics) -> [LibSmallFry](https://github.com/ImageProcessing-ElectronicPublications/libsmallfry))
6464
1 pair | `-m ssimfry` | `(ssim + smallfry) / 2`
6565
2 pair | `-m ssimshb` | `(ssim + shbad) / 2`
66-
SUMMARY | `-m sum` | `(ssim + smallfry + shbad + nhw) / 4` **DEFAULT**
66+
SUMMARY | `-m sum` | `(ssim + vipf1 + smallfry + shbad + nhw) / 5` **DEFAULT**
6767

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

man/man1/jpeg-compare.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.TH "jpeg-compare" 2.5.9 "15 Jan 2023" "User manual"
1+
.TH "jpeg-compare" 1 2.6.0 "31 Jan 2023" "User manual"
22

33
.SH NAME
44
jpeg-compare

man/man1/jpeg-hash.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.TH "jpeg-hash" 2.5.9 "15 Jan 2023" "User manual"
1+
.TH "jpeg-hash" 1 2.6.0 "31 Jan 2023" "User manual"
22

33
.SH NAME
44
jpeg-hash

man/man1/jpeg-recompress.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.TH "jpeg-recompress" 2.5.9 "15 Jan 2023" "User manual"
1+
.TH "jpeg-recompress" 1 2.6.0 "31 Jan 2023" "User manual"
22

33
.SH NAME
44
jpeg-recompress

man/man1/jpeg-zfpoint.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.TH "jpeg-zfpoint" 2.5.9 "15 Jan 2023" "User manual"
1+
.TH "jpeg-zfpoint" 1 2.6.0 "31 Jan 2023" "User manual"
22

33
.SH NAME
44
jpeg-zfpoint

man/man1/webp-compress.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.TH "webp-compress" 2.5.9 "15 Jan 2023" "User manual"
1+
.TH "webp-compress" 1 2.6.0 "31 Jan 2023" "User manual"
22

33
.SH NAME
44
webp-compress

src/jmetrics.c

Lines changed: 47 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,52 @@
11
#include "jmetrics.h"
22

33
#define INPUT_BUFFER_SIZE 102400
4+
#define MAX_SUM_COUNT 5
45

56
float clamp(float low, float value, float high)
67
{
78
return (value < low) ? low : ((value > high) ? high : value);
89
}
910

10-
float waverage4(float x1, float x2, float x3, float x4)
11+
float waverage(float *x, int count)
1112
{
12-
float xm, dx1, dx2 ,dx3, dx4, dxs, w1, w2, w3, w4, ws;
13-
xm = x1 + x2 + x3 + x4;
14-
xm *= 0.25f;
15-
dx1 = (x1 - xm) * (x1 - xm);
16-
dx2 = (x2 - xm) * (x2 - xm);
17-
dx3 = (x3 - xm) * (x3 - xm);
18-
dx4 = (x4 - xm) * (x4 - xm);
19-
dxs = dx1 + dx2 + dx3 + dx4;
20-
dxs *= 0.25f;
13+
int i, n;
14+
float xm, delta, dx[MAX_SUM_COUNT], dxs, w[MAX_SUM_COUNT], ws;
15+
16+
xm = 0.0f;
17+
n = 0;
18+
for (i = 0; i < count; i++)
19+
{
20+
xm += x[i];
21+
n++;
22+
}
23+
n = (n > 0) ? n : 1;
24+
xm /= (float)n;
25+
dxs = 0.0f;
26+
for (i = 0; i < count; i++)
27+
{
28+
delta = x[i] - xm;
29+
dx[i] = delta * delta;
30+
dxs += dx[i];
31+
}
32+
dxs /= (float)n;
2133
if (dxs > 0.0f)
2234
{
23-
w1 = dxs / (dxs + dx1);
24-
w2 = dxs / (dxs + dx2);
25-
w3 = dxs / (dxs + dx3);
26-
w4 = dxs / (dxs + dx4);
27-
ws = w1 + w2 + w3 + w4;
35+
ws = 0.0f;
36+
for (i = 0; i < count; i++)
37+
{
38+
w[i] = dxs / (dxs + dx[i]);
39+
ws += w[i];
40+
}
2841
if (ws > 0.0f)
29-
xm = (w1 * x1 + w2 * x2 + w3 * x3 + w4 * x4) / ws;
42+
{
43+
xm = 0.0f;
44+
for (i = 0; i < count; i++)
45+
{
46+
xm += (w[i] * x[i]);
47+
}
48+
xm /= ws;
49+
}
3050
}
3151
return xm;
3252
}
@@ -149,7 +169,7 @@ void scale(unsigned char *image, int width, int height, unsigned char **newImage
149169
{
150170
int y, x, oldY, oldX;
151171
unsigned long int k, size;
152-
172+
153173
size = (unsigned long int) newWidth * newHeight;
154174

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

296316
*buffer = malloc(sizeof chunk);
297-
317+
298318
while ((bytesRead = fread(chunk, 1, sizeof chunk, file)) > 0)
299319
{
300320
unsigned char *reallocated = realloc(*buffer, fileLen + bytesRead);
301-
321+
302322
if (reallocated)
303323
{
304324
*buffer = reallocated;
@@ -935,7 +955,7 @@ float MetricSigma(float cor)
935955

936956
float MetricCalc(int method, unsigned char *image1, unsigned char *image2, int width, int height, int components)
937957
{
938-
float diff, tmetric, tm1, tm2, tm3, tm4;
958+
float diff, tmetric, tm[MAX_SUM_COUNT];
939959

940960
// Calculate and print comparison
941961
switch (method)
@@ -984,14 +1004,16 @@ float MetricCalc(int method, unsigned char *image1, unsigned char *image2, int w
9841004
case SUMMET:
9851005
default:
9861006
tmetric = iqa_ssim(image1, image2, width, height, width * components, 0, 0);
987-
tm1 = RescaleMetric(SSIM, tmetric);
1007+
tm[0] = RescaleMetric(SSIM, tmetric);
9881008
tmetric = metric_smallfry(image1, image2, width, height);
989-
tm2 = RescaleMetric(SMALLFRY, tmetric);
1009+
tm[1] = RescaleMetric(SMALLFRY, tmetric);
9901010
tmetric = metric_sharpenbad(image1, image2, width, height);
991-
tm3 = RescaleMetric(SHARPENBAD, tmetric);
1011+
tm[2] = RescaleMetric(SHARPENBAD, tmetric);
9921012
tmetric = metric_nhw(image1, image2, width, height);
993-
tm4 = RescaleMetric(NHW, tmetric);
994-
diff = waverage4(tm1, tm2, tm3, tm4);
1013+
tm[3] = RescaleMetric(NHW, tmetric);
1014+
tmetric = iqa_vifp1(image1, image2, width, height, width * components, 0, 0);
1015+
tm[4] = RescaleMetric(VIFP1, tmetric);
1016+
diff = waverage(tm, 5);
9951017
break;
9961018
}
9971019
return diff;

src/jmetrics.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#define JMETRICS_H
2222

2323
#ifndef JMVERSION
24-
#define JMVERSION "2.5.8"
24+
#define JMVERSION "2.6.0"
2525
#endif
2626

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

209209
#endif

0 commit comments

Comments
 (0)