-
Notifications
You must be signed in to change notification settings - Fork 0
/
denoise.py
21 lines (16 loc) · 1011 Bytes
/
denoise.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import sys, os, subprocess
file = sys.argv[1]
name = os.path.splitext(file)[0]
channels = subprocess.Popen("identify -format '%[channels]' {file}".format(file=file), shell=True, stdout=subprocess.PIPE)
channels = channels.stdout.read().decode("utf-8").strip()
print(channels)
# This conversion removes alpha channel
os.system('convert -endian LSB {file} /tmp/denoise-in.pfm'.format(file=file))
os.system('oidnDenoise --ldr /tmp/denoise-in.pfm --srgb -o /tmp/denoise-out.pfm')
if channels == 'srgba':
# Extract alpha channel and denoise it too
os.system('convert -endian LSB {file} -alpha extract -colorspace RGB -type truecolor /tmp/denoise-in-alpha.pfm'.format(file=file))
os.system('oidnDenoise --ldr /tmp/denoise-in-alpha.pfm -o /tmp/denoise-out-alpha.pfm')
os.system('convert /tmp/denoise-out.pfm /tmp/denoise-out-alpha.pfm -compose CopyOpacity -composite {name}.denoised.png'.format(name=name))
else:
os.system('convert /tmp/denoise-out.pfm {name}.denoised.png'.format(name=name))