Skip to content

Commit 1bdc573

Browse files
committed
2.6.2: reimplementation SHARPENBAD
1 parent 2a61c26 commit 1bdc573

10 files changed

+91
-66
lines changed

CHANGELOG

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
JPEG Recompress
22
https://github.com/ImageProcessing-ElectronicPublications/jpeg-recompress
33

4+
2.6.2 "sharpenbad"
5+
6+
reimplementation SHARPENBAD:
7+
metric_sharpenbad
8+
49
2.6.1 "msef"
510

611
Added MSE and MSEF metric.

README.md

+25-13
Original file line numberDiff line numberDiff line change
@@ -71,22 +71,34 @@ SUMMARY | `-m sum` | `(ssim + vipf1 + smallfry + shbad + nhw) / 5` **DE
7171

7272
"Universal Scale" of metrics (UM):
7373
```
74-
0.0 ... (DIRTY) ... 0.5 ... (LOW) ... 0.75 ... (MEDIUM) ... 0.875 ... (SUBHIGH) ... 0.9375 ... (HIGH) ... 0.96875 ... (VERYHIGH) ... 1.0
74+
0.0
75+
... (DIRTY) ...
76+
0.5
77+
... (LOW) ...
78+
0.75
79+
... (MEDIUM) ...
80+
0.875
81+
... (SUBHIGH) ...
82+
0.9375
83+
... (HIGH) ...
84+
0.96875
85+
... (VERYHIGH) ...
86+
1.0
7587
```
7688
Trends:
7789
```
78-
UM = 2.42 * sqrt(sqrt(1.0 / MPE)) - 1.38
79-
UM = 0.87 * sqrt(PNSR) - 4.70
80-
UM = 1.02 * sqrt(sqrt(1.0 / MSEF)) - 1.49
81-
UM = 2.87 * cor_sigma(cor_sigma(COR)) - 1.42
82-
UM = 1.73 * cor_sigma(cor_sigma(cor_sigma(SSIM))) - 0.11
83-
UM = 1.59 * cor_sigma(cor_sigma(MS_SSIM)) + 0.01
84-
UM = 1.12 * cor_sigma(cor_sigma(VIFP1)) - 0.03
85-
UM = 0.0658 * SMALLFRY - 6.07
86-
UM = 1.00 * SHARPENBAD + 0.05
87-
UM = 0.36 * sqrt(sqrt(1.0 / NHW)) - 0.41
88-
89-
cor_sigma(M) = 1.0 - sqrt(1.0 - M * M)
90+
UM = 2.42 * sqrt(sqrt(1.0 / MPE)) - 1.38
91+
UM = 0.87 * sqrt(PNSR) - 4.70
92+
UM = 1.02 * sqrt(sqrt(1.0 / MSEF)) - 1.49
93+
UM = 1.0 * cor_sigma(cor_sigma(COR))
94+
UM = 1.51 * cor_sigma(cor_sigma(cor_sigma(SSIM)))
95+
UM = 1.59 * cor_sigma(cor_sigma(MS_SSIM))
96+
UM = 1.06 * cor_sigma(cor_sigma(VIFP1))
97+
UM = 0.0658 * SMALLFRY - 6.07
98+
UM = 1.40 * cor_sigma(SHARPENBAD)
99+
UM = 0.222 * sqrt(sqrt(1.0 / NHW))
100+
101+
cor_sigma(M) = 1.0 - sqrt(1.0 - M * M)
90102
```
91103

92104
#### Subsampling

man/man1/jpeg-compare.1

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.TH "jpeg-compare" 1 2.6.1 "02 Feb 2023" "User manual"
1+
.TH "jpeg-compare" 1 2.6.2 "08 Feb 2023" "User manual"
22

33
.SH NAME
44
jpeg-compare
@@ -77,13 +77,13 @@ Trends:
7777
UM = 2.42 * sqrt(sqrt(1.0 / MPE)) - 1.38
7878
UM = 0.87 * sqrt(PNSR) - 4.70
7979
UM = 1.02 * sqrt(sqrt(1.0 / MSEF)) - 1.49
80-
UM = 2.87 * cor_sigma(cor_sigma(COR)) - 1.42
81-
UM = 1.73 * cor_sigma(cor_sigma(cor_sigma(SSIM))) - 0.11
82-
UM = 1.59 * cor_sigma(cor_sigma(MS_SSIM)) + 0.01
83-
UM = 1.12 * cor_sigma(cor_sigma(VIFP1)) - 0.03
80+
UM = 1.0 * cor_sigma(cor_sigma(COR))
81+
UM = 1.51 * cor_sigma(cor_sigma(cor_sigma(SSIM)))
82+
UM = 1.59 * cor_sigma(cor_sigma(MS_SSIM))
83+
UM = 1.06 * cor_sigma(cor_sigma(VIFP1))
8484
UM = 0.0658 * SMALLFRY - 6.07
85-
UM = 1.00 * SHARPENBAD + 0.05
86-
UM = 0.36 * sqrt(sqrt(1.0 / NHW)) - 0.41
85+
UM = 1.40 * cor_sigma(SHARPENBAD)
86+
UM = 0.222 * sqrt(sqrt(1.0 / NHW))
8787
cor_sigma(M) = 1.0 - sqrt(1.0 - M * M)
8888

8989
.SH COPYRIGHT

man/man1/jpeg-hash.1

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.TH "jpeg-hash" 1 2.6.1 "02 Feb 2023" "User manual"
1+
.TH "jpeg-hash" 1 2.6.2 "08 Feb 2023" "User manual"
22

33
.SH NAME
44
jpeg-hash

man/man1/jpeg-recompress.1

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.TH "jpeg-recompress" 1 2.6.1 "02 Feb 2023" "User manual"
1+
.TH "jpeg-recompress" 1 2.6.2 "08 Feb 2023" "User manual"
22

33
.SH NAME
44
jpeg-recompress
@@ -148,13 +148,13 @@ Trends:
148148
UM = 2.42 * sqrt(sqrt(1.0 / MPE)) - 1.38
149149
UM = 0.87 * sqrt(PNSR) - 4.70
150150
UM = 1.02 * sqrt(sqrt(1.0 / MSEF)) - 1.49
151-
UM = 2.87 * cor_sigma(cor_sigma(COR)) - 1.42
152-
UM = 1.73 * cor_sigma(cor_sigma(cor_sigma(SSIM))) - 0.11
153-
UM = 1.59 * cor_sigma(cor_sigma(MS_SSIM)) + 0.01
154-
UM = 1.12 * cor_sigma(cor_sigma(VIFP1)) - 0.03
151+
UM = 1.0 * cor_sigma(cor_sigma(COR))
152+
UM = 1.51 * cor_sigma(cor_sigma(cor_sigma(SSIM)))
153+
UM = 1.59 * cor_sigma(cor_sigma(MS_SSIM))
154+
UM = 1.06 * cor_sigma(cor_sigma(VIFP1))
155155
UM = 0.0658 * SMALLFRY - 6.07
156-
UM = 1.00 * SHARPENBAD + 0.05
157-
UM = 0.36 * sqrt(sqrt(1.0 / NHW)) - 0.41
156+
UM = 1.40 * cor_sigma(SHARPENBAD)
157+
UM = 0.222 * sqrt(sqrt(1.0 / NHW))
158158
cor_sigma(M) = 1.0 - sqrt(1.0 - M * M)
159159

160160
.SH COPYRIGHT

man/man1/jpeg-zfpoint.1

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.TH "jpeg-zfpoint" 1 2.6.1 "02 Feb 2023" "User manual"
1+
.TH "jpeg-zfpoint" 1 2.6.2 "08 Feb 2023" "User manual"
22

33
.SH NAME
44
jpeg-zfpoint

man/man1/webp-compress.1

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.TH "webp-compress" 1 2.6.1 "02 Feb 2023" "User manual"
1+
.TH "webp-compress" 1 2.6.2 "08 Feb 2023" "User manual"
22

33
.SH NAME
44
webp-compress
@@ -112,13 +112,13 @@ Trends:
112112
UM = 2.42 * sqrt(sqrt(1.0 / MPE)) - 1.38
113113
UM = 0.87 * sqrt(PNSR) - 4.70
114114
UM = 1.02 * sqrt(sqrt(1.0 / MSEF)) - 1.49
115-
UM = 2.87 * cor_sigma(cor_sigma(COR)) - 1.42
116-
UM = 1.73 * cor_sigma(cor_sigma(cor_sigma(SSIM))) - 0.11
117-
UM = 1.59 * cor_sigma(cor_sigma(MS_SSIM)) + 0.01
118-
UM = 1.12 * cor_sigma(cor_sigma(VIFP1)) - 0.03
115+
UM = 1.0 * cor_sigma(cor_sigma(COR))
116+
UM = 1.51 * cor_sigma(cor_sigma(cor_sigma(SSIM)))
117+
UM = 1.59 * cor_sigma(cor_sigma(MS_SSIM))
118+
UM = 1.06 * cor_sigma(cor_sigma(VIFP1))
119119
UM = 0.0658 * SMALLFRY - 6.07
120-
UM = 1.00 * SHARPENBAD + 0.05
121-
UM = 0.36 * sqrt(sqrt(1.0 / NHW)) - 0.41
120+
UM = 1.40 * cor_sigma(SHARPENBAD)
121+
UM = 0.222 * sqrt(sqrt(1.0 / NHW))
122122
cor_sigma(M) = 1.0 - sqrt(1.0 - M * M)
123123

124124
.SH COPYRIGHT

src/jmetrics.c

+34-26
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,10 @@ enum METHOD parseMethod(const char *s)
903903

904904
float RescaleMetric(int currentmethod, float value)
905905
{
906+
float k1, k0;
907+
908+
k1 = 1.0f;
909+
k0 = 0.0f;
906910
switch (currentmethod)
907911
{
908912
case MSE:
@@ -913,8 +917,8 @@ float RescaleMetric(int currentmethod, float value)
913917
value = 1.0f / value;
914918
value = sqrt(value);
915919
value = sqrt(value);
916-
value *= 2.42f;
917-
value -= 1.38f;
920+
k1 = 2.42f;
921+
k0 = -1.38f;
918922
}
919923
else
920924
{
@@ -923,17 +927,23 @@ float RescaleMetric(int currentmethod, float value)
923927
break;
924928
case PSNR:
925929
value = sqrt(value);
926-
value *= 0.87f;
927-
value -= 4.70f;
930+
k1 = 0.87f;
931+
k0 = -4.70f;
932+
break;
933+
case COR:
934+
value = MetricSigma(value);
935+
value = MetricSigma(value);
936+
k1 = 1.0f;
937+
k0 = 0.0f;
928938
break;
929939
case MSEF:
930940
if (value > 0.0f)
931941
{
932942
value = 1.0f / value;
933943
value = sqrt(value);
934944
value = sqrt(value);
935-
value *= 1.02f;
936-
value -= 1.49f;
945+
k1 = 1.02f;
946+
k0 = -1.49f;
937947
}
938948
else
939949
{
@@ -944,50 +954,48 @@ float RescaleMetric(int currentmethod, float value)
944954
value = MetricSigma(value);
945955
value = MetricSigma(value);
946956
value = MetricSigma(value);
947-
value *= 1.73f;
948-
value -= 0.11f;
957+
k1 = 1.51f;
958+
k0 = 0.0f;
949959
break;
950960
case MS_SSIM:
951961
value = MetricSigma(value);
952962
value = MetricSigma(value);
953-
value *= 1.59f;
954-
value += 0.01f;
963+
k1 = 1.59f;
964+
k0 = 0.0f;
955965
break;
956966
case VIFP1:
957967
value = MetricSigma(value);
958968
value = MetricSigma(value);
959-
value *= 1.12f;
960-
value -= 0.03f;
969+
k1 = 1.06f;
970+
k0 = 0.0f;
961971
break;
962972
case SMALLFRY:
963-
value *= 0.0658f;
964-
value -= 6.07f;
973+
k1 = 0.0658f;
974+
k0 = -6.07f;
965975
break;
966976
case SHARPENBAD:
967-
value *= 1.00f;
968-
value += 0.05f;
969-
break;
970-
case COR:
971977
value = MetricSigma(value);
972-
value = MetricSigma(value);
973-
value *= 2.87f;
974-
value -= 1.42f;
978+
k1 = 1.40f;
979+
k0 = 0.0f;
975980
break;
976981
case NHW:
977982
if (value > 0.0f)
978983
{
979984
value = 1.0f / value;
980985
value = sqrt(value);
981986
value = sqrt(value);
982-
value *= 0.36f;
983-
value -= 0.41f;
987+
k1 = 0.222f;
988+
k0 = 0.0f;
984989
}
985990
else
986991
{
987992
value = 1.0f;
988993
}
989994
break;
990995
}
996+
value *= k1;
997+
value += k0;
998+
991999
return value;
9921000
}
9931001

@@ -1096,7 +1104,7 @@ float MetricCalc(int method, unsigned char *image1, unsigned char *image2, int w
10961104
diff = metric_smallfry(image1, image2, width, height);
10971105
break;
10981106
case SHARPENBAD:
1099-
diff = metric_sharpenbad(image1, image2, width, height);
1107+
diff = metric_sharpenbad(image1, image2, width, height, 1);
11001108
break;
11011109
case COR:
11021110
diff = metric_cor(image1, image2, width, height);
@@ -1114,7 +1122,7 @@ float MetricCalc(int method, unsigned char *image1, unsigned char *image2, int w
11141122
case SSIMSHBAD:
11151123
tmetric = iqa_ssim(image1, image2, width, height, width * components, 0, 0);
11161124
diff = RescaleMetric(SSIM, tmetric);
1117-
tmetric = metric_sharpenbad(image1, image2, width, height);
1125+
tmetric = metric_sharpenbad(image1, image2, width, height, 1);
11181126
diff += RescaleMetric(SHARPENBAD, tmetric);
11191127
diff *= 0.5f;
11201128
break;
@@ -1124,7 +1132,7 @@ float MetricCalc(int method, unsigned char *image1, unsigned char *image2, int w
11241132
tm[0] = RescaleMetric(SSIM, tmetric);
11251133
tmetric = metric_smallfry(image1, image2, width, height);
11261134
tm[1] = RescaleMetric(SMALLFRY, tmetric);
1127-
tmetric = metric_sharpenbad(image1, image2, width, height);
1135+
tmetric = metric_sharpenbad(image1, image2, width, height, 1);
11281136
tm[2] = RescaleMetric(SHARPENBAD, tmetric);
11291137
tmetric = metric_nhw(image1, image2, width, height);
11301138
tm[3] = RescaleMetric(NHW, tmetric);

src/jmetrics.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#define JMETRICS_H
2222

2323
#ifndef JMVERSION
24-
#define JMVERSION "2.6.1"
24+
#define JMVERSION "2.6.2"
2525
#endif
2626

2727
#define MIN(a, b) ((a) < (b) ? (a) : (b))

src/jpeg-recompress.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ int main (int argc, char **argv)
4343
int method = SUMMET;
4444

4545
// Number of binary search steps
46-
int attempts = 7;
46+
int attempts = 8;
4747

4848
float target = 0.0f;
4949
int preset = MEDIUM;
5050

5151
// Min/max JPEG quality
52-
int jpegMin = 40;
53-
int jpegMax = 98;
52+
int jpegMin = 1;
53+
int jpegMax = 99;
5454

5555
int force = 0;
5656
int ycbcr = 0;

0 commit comments

Comments
 (0)