Skip to content

Commit

Permalink
fractional improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Artoriuz committed Jan 28, 2024
1 parent aad718c commit ddfe535
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 4 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.\ArtCNN_C4F16.png, 0.005601357197683343, 35.7403993580635, 0.9904909031229484, 0.9989654356979804
.\ArtCNN_C4F16_LL.png, 0.006343756541762611, 34.50056758931284, 0.9897800006133683, 0.9985779114639624
.\ravu-zoom-ar-r3.png, 0.006091159025887937, 34.6927139254382, 0.9884723573169553, 0.9987004637110991
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from scipy.ndimage import convolve
import numpy as np
import cv2
import glob
import skimage

def msssim(im1, im2, data_range = 255, channel_axis = None):
level = 5
weights = np.array([0.0448, 0.2856, 0.3001, 0.2363, 0.1333])
downsample_filter = np.ones((2, 2))/4.0
msssim = []
for _ in range(level):
ssim_res = skimage.metrics.structural_similarity(im1 = im1, im2 = im2, data_range = data_range, channel_axis = channel_axis)
msssim.append(ssim_res)
if channel_axis:
filtered_im1 = np.zeros_like(im1)
filtered_im2 = np.zeros_like(im2)
for channel in range(channel_axis):
filtered_im1[:, :, channel] = convolve(im1[:, :, channel], downsample_filter, mode='reflect')
filtered_im2[:, :, channel] = convolve(im2[:, :, channel], downsample_filter, mode='reflect')
im1 = filtered_im1[::2, ::2, :]
im2 = filtered_im2[::2, ::2, :]
else:
filtered_im1 = convolve(im1, downsample_filter, mode='reflect')
filtered_im2 = convolve(im2, downsample_filter, mode='reflect')
im1 = filtered_im1[::2, ::2]
im2 = filtered_im2[::2, ::2]
return np.average(np.array(msssim), weights=weights)

output_file = open("benchmark_result.txt", "w")

print("Starting benchmarks")

reference = cv2.imread('./reference.png', cv2.IMREAD_COLOR)
reference = cv2.cvtColor(reference, cv2.COLOR_BGR2GRAY, 0).astype(float) / 255.0

filelist = sorted(glob.glob('./*.png'))
for myFile in filelist:
if not "downscaled" in myFile:
image = cv2.imread(myFile, cv2.IMREAD_COLOR)
image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY, 0).astype(float) / 255.0

mae_score = np.mean(np.absolute(reference - image))
psnr_score = skimage.metrics.peak_signal_noise_ratio(reference, image)
ssim_score = skimage.metrics.structural_similarity(reference, image, data_range = 1, channel_axis = None)
msssim_score = msssim(reference, image, data_range = 1, channel_axis = None)

print(f"{myFile} - MAE: {mae_score}, PSNR: {psnr_score}, SSIM: {ssim_score}, MS-SSIM: {msssim_score}\n")
output_file.write(f"{myFile}, {mae_score}, {psnr_score}, {ssim_score}, {msssim_score}\n")

output_file.close()
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 38 additions & 4 deletions blog/mpv_upscaling.html
Original file line number Diff line number Diff line change
Expand Up @@ -977,17 +977,51 @@ <h3 id="fractional_upsampling_results">Fractional Upsampling Results</h3>
</tbody>
</table>
</p>
<h3 id="fractional_upsampling_results_gamma">Fractional Upsampling Results (Gamma Light)</h3>
<p>
<table>
<tbody>
<tr>
<td>Shader/Filter</td>
<td>MAE</td>
<td>PSNR</td>
<td>SSIM</td>
<td>MS-SSIM</td>
</tr>
<tr>
<td>ArtCNN_C4F16</td>
<td>5.60E-03</td>
<td>35.7404</td>
<td>0.9905</td>
<td>0.9990</td>
</tr>
<tr>
<td>ravu-zoom-ar-r3</td>
<td>6.09E-03</td>
<td>34.6927</td>
<td>0.9885</td>
<td>0.9987</td>
</tr>
<tr>
<td>ArtCNN_C4F16_LL</td>
<td>6.34E-03</td>
<td>34.5006</td>
<td>0.9898</td>
<td>0.9986</td>
</tr>
</tbody>
</table>
</p>
<h3 id="fractional_upsampling_commentary">Fractional Upsampling Commentary</h3>
<p>
The numbers are all closer together at 1.33x, which shows that your choice of scaler becomes less relevant as you decrease the scaling factor.
</p>
<p>
We can see that the LL variant of ArtCNN is obviously topping the chart here as well, but the gamma variants are all way lower. This happens because when we downsample the image from 2x to 1.33x we're throwing alway most
of the extra information and RAVU is excellent at such a low scaling factor.
We can see that the LL variant of ArtCNN is obviously topping the LL chart here as well, but the gamma variants are all way lower. This happens because when we downsample the image from 2x to 1.33x we're throwing alway most
of the extra information and RAVU is excellent at such a low scaling factor. When testing in gamma light, the normal variant of ArtCNN goes back up but that's also expected.
</p>
<p>
My recommendation here is ravu-zoom-ar-r3. This shader can output to the target resolution directly and it's way faster than the neural networks (which includes NNEDI3). If you know the content has been downsampled in linear light though,
the linear light variant of ArtCNN is always going to be the best option.
My recommendation here is ravu-zoom-ar-r3. This shader can output to the target resolution directly and it's way faster than the neural networks (which includes NNEDI3).
</p>
<h3 id="chroma_shaders">Chroma Shaders</h3>
<p>
Expand Down

0 comments on commit ddfe535

Please sign in to comment.