-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextractCurvesFromACVFile.py
More file actions
96 lines (76 loc) · 2.68 KB
/
extractCurvesFromACVFile.py
File metadata and controls
96 lines (76 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env python
"""
DESCRIPTION
Prints the polynomials that describe a photoshop curve.
There are three curves (one per RGB channel) which you can later
use to make a custom filter for your image.
See http://www.weemoapps.com/creating-retro-and-analog-image-filters-in-mobile-apps
for the theory behind this method.
USAGE
python extractCurvesFromACVFile.py theCurveFile.acv
You need to have scipy and numpy installed.
AUTHOR
email: vassilis@weemoapps.com
twitter: @weemoapps
LICENSE
Do whatever you want, but please mention this code in your code if you modify it.
VERSION
0.1
"""
import sys, os, traceback, optparse, time
from struct import unpack
from scipy import interpolate
import numpy as np
#Here we read the .acv curve file. It will help to take a look at see the link below to lean about the .acv file format specifications
# http://www.adobe.com/devnet-apps/photoshop/fileformatashtml/PhotoshopFileFormats.htm#50577411_pgfId-1056330
def read_curve(acv_file):
curve = []
number_of_points_in_curve, = unpack("!h", acv_file.read(2))
for j in range(number_of_points_in_curve):
y, x = unpack("!hh", acv_file.read(4))
curve.append((x, y))
return curve
#Here we do the interpolation in order to get a curve out of the curve points we already have.
def return_polynomial_coefficients(curve_list):
xdata = [x[0] for x in curve_list]
ydata = [x[1] for x in curve_list]
np.set_printoptions(precision=6)
np.set_printoptions(suppress=True)
p = interpolate.lagrange(xdata, ydata)
return p
#coefficients = p.c
#print coefficients
def main ():
if (len(sys.argv) != 1):
acv_file = open(sys.argv[1], "rb")
else:
print "Wrong args. Usage: python extractCurvesFromACVFile.py curveFile.acv"
os._exit(1)
_, nr_curves = unpack("!hh", acv_file.read(4))
curves = []
for i in range(nr_curves):
curves.append(read_curve(acv_file))
compositeCurve = curves[0]
redCurve = curves[1]
greenCurve = curves[2]
blueCurve = curves[3]
print "************* Red Curve *************"
pRed = return_polynomial_coefficients(redCurve)
print pRed
print "*************************************\n"
print "************* Green Curve *************"
pGreen = return_polynomial_coefficients(greenCurve)
print pGreen
print "*************************************\n"
print "************* Blue Curve *************"
pBlue = return_polynomial_coefficients(blueCurve)
print pBlue
print "*************************************\n"
if __name__ == '__main__':
try:
main()
except Exception, e:
print 'ERROR, UNEXPECTED EXCEPTION'
print str(e)
traceback.print_exc()
os._exit(1)