Skip to content

Commit

Permalink
2.6.2: reimplementation SHARPENBAD
Browse files Browse the repository at this point in the history
  • Loading branch information
zvezdochiot committed Feb 8, 2023
1 parent 2a61c26 commit 1bdc573
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 66 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
JPEG Recompress
https://github.com/ImageProcessing-ElectronicPublications/jpeg-recompress

2.6.2 "sharpenbad"

reimplementation SHARPENBAD:
metric_sharpenbad

2.6.1 "msef"

Added MSE and MSEF metric.
Expand Down
38 changes: 25 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,34 @@ SUMMARY | `-m sum` | `(ssim + vipf1 + smallfry + shbad + nhw) / 5` **DE

"Universal Scale" of metrics (UM):
```
0.0 ... (DIRTY) ... 0.5 ... (LOW) ... 0.75 ... (MEDIUM) ... 0.875 ... (SUBHIGH) ... 0.9375 ... (HIGH) ... 0.96875 ... (VERYHIGH) ... 1.0
0.0
... (DIRTY) ...
0.5
... (LOW) ...
0.75
... (MEDIUM) ...
0.875
... (SUBHIGH) ...
0.9375
... (HIGH) ...
0.96875
... (VERYHIGH) ...
1.0
```
Trends:
```
UM = 2.42 * sqrt(sqrt(1.0 / MPE)) - 1.38
UM = 0.87 * sqrt(PNSR) - 4.70
UM = 1.02 * sqrt(sqrt(1.0 / MSEF)) - 1.49
UM = 2.87 * cor_sigma(cor_sigma(COR)) - 1.42
UM = 1.73 * cor_sigma(cor_sigma(cor_sigma(SSIM))) - 0.11
UM = 1.59 * cor_sigma(cor_sigma(MS_SSIM)) + 0.01
UM = 1.12 * cor_sigma(cor_sigma(VIFP1)) - 0.03
UM = 0.0658 * SMALLFRY - 6.07
UM = 1.00 * SHARPENBAD + 0.05
UM = 0.36 * sqrt(sqrt(1.0 / NHW)) - 0.41
cor_sigma(M) = 1.0 - sqrt(1.0 - M * M)
UM = 2.42 * sqrt(sqrt(1.0 / MPE)) - 1.38
UM = 0.87 * sqrt(PNSR) - 4.70
UM = 1.02 * sqrt(sqrt(1.0 / MSEF)) - 1.49
UM = 1.0 * cor_sigma(cor_sigma(COR))
UM = 1.51 * cor_sigma(cor_sigma(cor_sigma(SSIM)))
UM = 1.59 * cor_sigma(cor_sigma(MS_SSIM))
UM = 1.06 * cor_sigma(cor_sigma(VIFP1))
UM = 0.0658 * SMALLFRY - 6.07
UM = 1.40 * cor_sigma(SHARPENBAD)
UM = 0.222 * sqrt(sqrt(1.0 / NHW))
cor_sigma(M) = 1.0 - sqrt(1.0 - M * M)
```

#### Subsampling
Expand Down
14 changes: 7 additions & 7 deletions man/man1/jpeg-compare.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH "jpeg-compare" 1 2.6.1 "02 Feb 2023" "User manual"
.TH "jpeg-compare" 1 2.6.2 "08 Feb 2023" "User manual"

.SH NAME
jpeg-compare
Expand Down Expand Up @@ -77,13 +77,13 @@ Trends:
UM = 2.42 * sqrt(sqrt(1.0 / MPE)) - 1.38
UM = 0.87 * sqrt(PNSR) - 4.70
UM = 1.02 * sqrt(sqrt(1.0 / MSEF)) - 1.49
UM = 2.87 * cor_sigma(cor_sigma(COR)) - 1.42
UM = 1.73 * cor_sigma(cor_sigma(cor_sigma(SSIM))) - 0.11
UM = 1.59 * cor_sigma(cor_sigma(MS_SSIM)) + 0.01
UM = 1.12 * cor_sigma(cor_sigma(VIFP1)) - 0.03
UM = 1.0 * cor_sigma(cor_sigma(COR))
UM = 1.51 * cor_sigma(cor_sigma(cor_sigma(SSIM)))
UM = 1.59 * cor_sigma(cor_sigma(MS_SSIM))
UM = 1.06 * cor_sigma(cor_sigma(VIFP1))
UM = 0.0658 * SMALLFRY - 6.07
UM = 1.00 * SHARPENBAD + 0.05
UM = 0.36 * sqrt(sqrt(1.0 / NHW)) - 0.41
UM = 1.40 * cor_sigma(SHARPENBAD)
UM = 0.222 * sqrt(sqrt(1.0 / NHW))
cor_sigma(M) = 1.0 - sqrt(1.0 - M * M)

.SH COPYRIGHT
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" 1 2.6.1 "02 Feb 2023" "User manual"
.TH "jpeg-hash" 1 2.6.2 "08 Feb 2023" "User manual"

.SH NAME
jpeg-hash
Expand Down
14 changes: 7 additions & 7 deletions man/man1/jpeg-recompress.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH "jpeg-recompress" 1 2.6.1 "02 Feb 2023" "User manual"
.TH "jpeg-recompress" 1 2.6.2 "08 Feb 2023" "User manual"

.SH NAME
jpeg-recompress
Expand Down Expand Up @@ -148,13 +148,13 @@ Trends:
UM = 2.42 * sqrt(sqrt(1.0 / MPE)) - 1.38
UM = 0.87 * sqrt(PNSR) - 4.70
UM = 1.02 * sqrt(sqrt(1.0 / MSEF)) - 1.49
UM = 2.87 * cor_sigma(cor_sigma(COR)) - 1.42
UM = 1.73 * cor_sigma(cor_sigma(cor_sigma(SSIM))) - 0.11
UM = 1.59 * cor_sigma(cor_sigma(MS_SSIM)) + 0.01
UM = 1.12 * cor_sigma(cor_sigma(VIFP1)) - 0.03
UM = 1.0 * cor_sigma(cor_sigma(COR))
UM = 1.51 * cor_sigma(cor_sigma(cor_sigma(SSIM)))
UM = 1.59 * cor_sigma(cor_sigma(MS_SSIM))
UM = 1.06 * cor_sigma(cor_sigma(VIFP1))
UM = 0.0658 * SMALLFRY - 6.07
UM = 1.00 * SHARPENBAD + 0.05
UM = 0.36 * sqrt(sqrt(1.0 / NHW)) - 0.41
UM = 1.40 * cor_sigma(SHARPENBAD)
UM = 0.222 * sqrt(sqrt(1.0 / NHW))
cor_sigma(M) = 1.0 - sqrt(1.0 - M * M)

.SH COPYRIGHT
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" 1 2.6.1 "02 Feb 2023" "User manual"
.TH "jpeg-zfpoint" 1 2.6.2 "08 Feb 2023" "User manual"

.SH NAME
jpeg-zfpoint
Expand Down
14 changes: 7 additions & 7 deletions man/man1/webp-compress.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH "webp-compress" 1 2.6.1 "02 Feb 2023" "User manual"
.TH "webp-compress" 1 2.6.2 "08 Feb 2023" "User manual"

.SH NAME
webp-compress
Expand Down Expand Up @@ -112,13 +112,13 @@ Trends:
UM = 2.42 * sqrt(sqrt(1.0 / MPE)) - 1.38
UM = 0.87 * sqrt(PNSR) - 4.70
UM = 1.02 * sqrt(sqrt(1.0 / MSEF)) - 1.49
UM = 2.87 * cor_sigma(cor_sigma(COR)) - 1.42
UM = 1.73 * cor_sigma(cor_sigma(cor_sigma(SSIM))) - 0.11
UM = 1.59 * cor_sigma(cor_sigma(MS_SSIM)) + 0.01
UM = 1.12 * cor_sigma(cor_sigma(VIFP1)) - 0.03
UM = 1.0 * cor_sigma(cor_sigma(COR))
UM = 1.51 * cor_sigma(cor_sigma(cor_sigma(SSIM)))
UM = 1.59 * cor_sigma(cor_sigma(MS_SSIM))
UM = 1.06 * cor_sigma(cor_sigma(VIFP1))
UM = 0.0658 * SMALLFRY - 6.07
UM = 1.00 * SHARPENBAD + 0.05
UM = 0.36 * sqrt(sqrt(1.0 / NHW)) - 0.41
UM = 1.40 * cor_sigma(SHARPENBAD)
UM = 0.222 * sqrt(sqrt(1.0 / NHW))
cor_sigma(M) = 1.0 - sqrt(1.0 - M * M)

.SH COPYRIGHT
Expand Down
60 changes: 34 additions & 26 deletions src/jmetrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,10 @@ enum METHOD parseMethod(const char *s)

float RescaleMetric(int currentmethod, float value)
{
float k1, k0;

k1 = 1.0f;
k0 = 0.0f;
switch (currentmethod)
{
case MSE:
Expand All @@ -913,8 +917,8 @@ float RescaleMetric(int currentmethod, float value)
value = 1.0f / value;
value = sqrt(value);
value = sqrt(value);
value *= 2.42f;
value -= 1.38f;
k1 = 2.42f;
k0 = -1.38f;
}
else
{
Expand All @@ -923,17 +927,23 @@ float RescaleMetric(int currentmethod, float value)
break;
case PSNR:
value = sqrt(value);
value *= 0.87f;
value -= 4.70f;
k1 = 0.87f;
k0 = -4.70f;
break;
case COR:
value = MetricSigma(value);
value = MetricSigma(value);
k1 = 1.0f;
k0 = 0.0f;
break;
case MSEF:
if (value > 0.0f)
{
value = 1.0f / value;
value = sqrt(value);
value = sqrt(value);
value *= 1.02f;
value -= 1.49f;
k1 = 1.02f;
k0 = -1.49f;
}
else
{
Expand All @@ -944,50 +954,48 @@ float RescaleMetric(int currentmethod, float value)
value = MetricSigma(value);
value = MetricSigma(value);
value = MetricSigma(value);
value *= 1.73f;
value -= 0.11f;
k1 = 1.51f;
k0 = 0.0f;
break;
case MS_SSIM:
value = MetricSigma(value);
value = MetricSigma(value);
value *= 1.59f;
value += 0.01f;
k1 = 1.59f;
k0 = 0.0f;
break;
case VIFP1:
value = MetricSigma(value);
value = MetricSigma(value);
value *= 1.12f;
value -= 0.03f;
k1 = 1.06f;
k0 = 0.0f;
break;
case SMALLFRY:
value *= 0.0658f;
value -= 6.07f;
k1 = 0.0658f;
k0 = -6.07f;
break;
case SHARPENBAD:
value *= 1.00f;
value += 0.05f;
break;
case COR:
value = MetricSigma(value);
value = MetricSigma(value);
value *= 2.87f;
value -= 1.42f;
k1 = 1.40f;
k0 = 0.0f;
break;
case NHW:
if (value > 0.0f)
{
value = 1.0f / value;
value = sqrt(value);
value = sqrt(value);
value *= 0.36f;
value -= 0.41f;
k1 = 0.222f;
k0 = 0.0f;
}
else
{
value = 1.0f;
}
break;
}
value *= k1;
value += k0;

return value;
}

Expand Down Expand Up @@ -1096,7 +1104,7 @@ float MetricCalc(int method, unsigned char *image1, unsigned char *image2, int w
diff = metric_smallfry(image1, image2, width, height);
break;
case SHARPENBAD:
diff = metric_sharpenbad(image1, image2, width, height);
diff = metric_sharpenbad(image1, image2, width, height, 1);
break;
case COR:
diff = metric_cor(image1, image2, width, height);
Expand All @@ -1114,7 +1122,7 @@ float MetricCalc(int method, unsigned char *image1, unsigned char *image2, int w
case SSIMSHBAD:
tmetric = iqa_ssim(image1, image2, width, height, width * components, 0, 0);
diff = RescaleMetric(SSIM, tmetric);
tmetric = metric_sharpenbad(image1, image2, width, height);
tmetric = metric_sharpenbad(image1, image2, width, height, 1);
diff += RescaleMetric(SHARPENBAD, tmetric);
diff *= 0.5f;
break;
Expand All @@ -1124,7 +1132,7 @@ float MetricCalc(int method, unsigned char *image1, unsigned char *image2, int w
tm[0] = RescaleMetric(SSIM, tmetric);
tmetric = metric_smallfry(image1, image2, width, height);
tm[1] = RescaleMetric(SMALLFRY, tmetric);
tmetric = metric_sharpenbad(image1, image2, width, height);
tmetric = metric_sharpenbad(image1, image2, width, height, 1);
tm[2] = RescaleMetric(SHARPENBAD, tmetric);
tmetric = metric_nhw(image1, image2, width, height);
tm[3] = RescaleMetric(NHW, tmetric);
Expand Down
2 changes: 1 addition & 1 deletion 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.6.1"
#define JMVERSION "2.6.2"
#endif

#define MIN(a, b) ((a) < (b) ? (a) : (b))
Expand Down
6 changes: 3 additions & 3 deletions src/jpeg-recompress.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ int main (int argc, char **argv)
int method = SUMMET;

// Number of binary search steps
int attempts = 7;
int attempts = 8;

float target = 0.0f;
int preset = MEDIUM;

// Min/max JPEG quality
int jpegMin = 40;
int jpegMax = 98;
int jpegMin = 1;
int jpegMax = 99;

int force = 0;
int ycbcr = 0;
Expand Down

0 comments on commit 1bdc573

Please sign in to comment.