Skip to content

Commit 44bfe25

Browse files
author
Jed Smith
committed
add distance calculation and visualization utilities.
1 parent 538826d commit 44bfe25

File tree

2 files changed

+592
-0
lines changed

2 files changed

+592
-0
lines changed

utilities/CalculateDistance.nk

Lines changed: 393 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,393 @@
1+
set cut_paste_input [stack 0]
2+
push $cut_paste_input
3+
Group {
4+
name CalculateDistance
5+
addUserKnob {20 GamutCalculateDistance_tab l GamutCalculateDistance}
6+
addUserKnob {7 shd_rolloff l "shd rolloff" t "smoothly reduce distance calculations below the specified achromatic (luminance) threshold." R 0 0.1}
7+
shd_rolloff 0.03
8+
addUserKnob {18 distance t "maximum distance found" R 1 2}
9+
distance {1 1 1}
10+
addUserKnob {6 distance_panelDropped l "panel dropped state" -STARTLINE +HIDDEN}
11+
addUserKnob {41 gamut t "The current gamut in which we are working." T Gamut.gamut_in}
12+
addUserKnob {41 src_gamut l "source gamut" t "The source gamut from which this image was transformed." -STARTLINE T Gamut.gamut_out}
13+
addUserKnob {6 use_input_image l "use input image" t "Use the input image to calculate the max distance instead of the specified gamuts." +STARTLINE}
14+
addUserKnob {22 calc_max_limit l "Calculate Max Distance" t "Calculate the max distance given current gamut and source gamut." T "def get_max(ct_node):\n max_knob = ct_node\['maxlumapixvalue']\n ct_node\['maxlumapixdata'].clearAnimated()\n ct_node\['minlumapixdata'].clearAnimated()\n ct_node\['minlumapixvalue'].clearAnimated()\n max_knob.clearAnimated()\n nuke.execute(ct_node, frame, frame)\n maxval = max(max_knob.getValue())\n maxval = round(maxval, 4)\n return maxval\n \nn = nuke.thisNode()\nframe = nuke.frame()\ndist = n\['distance']\ndist.clearAnimated()\n#dist.split()\n\nct_nodes = \[nuke.toNode('\{0\}.\{1\}max'.format(n.fullName(), c)) for c in \['r', 'g', 'b']]\n\nfor i, ct_node in enumerate(ct_nodes):\n maxval = get_max(ct_node)\n dist.setValue(maxval, i)" +STARTLINE}
15+
addUserKnob {22 set_selected_node l "Setup Selected GamutCompress" t "Set the max distance knobs on the selected GamutCompress node." T "def setup():\n if 'cyan' not in gc.knobs():\n nuke.message('Please select a GamutCompress node to populate.')\n return\n d = n\['distance']\n dist_knobs = \['cyan', 'magenta', 'yellow']\n for i, k in enumerate(dist_knobs):\n gc\[k].setValue(max(0, d.getValue(i)-1))\n\nn = nuke.thisNode()\nnuke.root().begin()\ngc = nuke.selectedNode()\n\nsetup()" +STARTLINE}
16+
}
17+
Input {
18+
inputs 0
19+
name Input
20+
xpos -40
21+
ypos -34
22+
}
23+
Dot {
24+
name Dot4
25+
xpos -6
26+
ypos 66
27+
}
28+
set N288414a0 [stack 0]
29+
Output {
30+
name Output
31+
xpos -40
32+
ypos 254
33+
}
34+
push $N288414a0
35+
Group {
36+
inputs 0
37+
name RGB
38+
xpos 180
39+
ypos -34
40+
}
41+
Constant {
42+
inputs 0
43+
color {0 0 0 0}
44+
format "4 1 0 0 4 1 1 rgbw"
45+
name Constant3
46+
note_font "Bitstream Vera Sans"
47+
xpos 510
48+
ypos -34
49+
postage_stamp false
50+
}
51+
Reformat {
52+
type "to box"
53+
box_width 3
54+
box_height 2
55+
box_fixed true
56+
name Reformat1
57+
xpos 510
58+
ypos -10
59+
}
60+
Rectangle {
61+
area {0 0 1 2}
62+
color {1 0 0 0}
63+
name Rectangle1
64+
note_font "Bitstream Vera Sans"
65+
xpos 510
66+
ypos 14
67+
}
68+
Rectangle {
69+
area {1 0 2 2}
70+
color {0 1 0 0}
71+
name Rectangle2
72+
note_font "Bitstream Vera Sans"
73+
xpos 510
74+
ypos 38
75+
}
76+
Rectangle {
77+
area {2 0 3 2}
78+
color {0 0 1 0}
79+
name Rectangle3
80+
note_font "Bitstream Vera Sans"
81+
xpos 510
82+
ypos 62
83+
}
84+
Output {
85+
name Output
86+
xpos 510
87+
ypos 110
88+
}
89+
end_group
90+
Group {
91+
name Gamut
92+
xpos 180
93+
ypos 14
94+
addUserKnob {20 GamutToXYZ_tab l GamutToXYZ}
95+
addUserKnob {4 gamut_in l "gamut in" t "Choose source gamut" M {ACES ACEScg "Filmlight E-Gamut" Rec709 Rec2020 P3D60 P3D65 "Arri AlexaWideGamut" REDWideGamutRGB "GoPro Protune Native" CanonCinemaGamut SonySGamut SonySGamut3Cine PanasonicVGamut "DJI D-Gamut" BMDWideGamutGen4 AdobeWideGamutRGB ProPhotoRGB}}
96+
gamut_in ACEScg
97+
addUserKnob {4 gamut_out l "gamut out" t "Choose destination gamut" M {ACES ACEScg "Filmlight E-Gamut" Rec709 Rec2020 P3D60 P3D65 "Arri AlexaWideGamut" REDWideGamutRGB "GoPro Protune Native" CanonCinemaGamut SonySGamut SonySGamut3Cine PanasonicVGamut "DJI D-Gamut" BMDWideGamutGen4 AdobeWideGamutRGB ProPhotoRGB}}
98+
gamut_out "Arri AlexaWideGamut"
99+
addUserKnob {6 invert +STARTLINE}
100+
invert true
101+
}
102+
Input {
103+
inputs 0
104+
name Input
105+
xpos -40
106+
ypos -130
107+
}
108+
Dot {
109+
name Dot1
110+
xpos -6
111+
ypos -78
112+
}
113+
set N290b2840 [stack 0]
114+
ColorMatrix {
115+
matrix {
116+
{{parent.mtx.matrix(which)} {parent.mtx.matrix(which)} {parent.mtx.matrix(which)}}
117+
{{parent.mtx.matrix(which)} {parent.mtx.matrix(which)} {parent.mtx.matrix(which)}}
118+
{{parent.mtx.matrix(which)} {parent.mtx.matrix(which)} {parent.mtx.matrix(which)}}
119+
}
120+
name ColorMatrix2
121+
label "RGB to XYZ"
122+
xpos 180
123+
ypos 32
124+
addUserKnob {20 Gamut}
125+
addUserKnob {3 which}
126+
which {{parent.gamut_out}}
127+
addUserKnob {12 rxy}
128+
rxy {{parent.mtx.rxy(which)} {parent.mtx.rxy(which)}}
129+
addUserKnob {12 gxy}
130+
gxy {{parent.mtx.gxy(which)} {parent.mtx.gxy(which)}}
131+
addUserKnob {12 bxy}
132+
bxy {{parent.mtx.bxy(which)} {parent.mtx.bxy(which)}}
133+
addUserKnob {12 wxy}
134+
wxy {{parent.mtx.wxy(which)} {parent.mtx.wxy(which)}}
135+
}
136+
ColorMatrix {
137+
matrix {
138+
{0.9872239828 -0.006113247015 0.01595330238}
139+
{-0.007598329335 1.001861453 0.005330037326}
140+
{0.00307257846 -0.00509596616 1.081680536}
141+
}
142+
invert {{!parent.ColorMatrix4.invert}}
143+
name ColorMatrix1
144+
label "CAT: Bradford\n ACES to D65"
145+
xpos 180
146+
ypos 101
147+
disable {{"RGBtoXYZ.wxy == XYZtoRGB.wxy"}}
148+
}
149+
ColorMatrix {
150+
matrix {
151+
{{parent.mtx.matrix(which)} {parent.mtx.matrix(which)} {parent.mtx.matrix(which)}}
152+
{{parent.mtx.matrix(which)} {parent.mtx.matrix(which)} {parent.mtx.matrix(which)}}
153+
{{parent.mtx.matrix(which)} {parent.mtx.matrix(which)} {parent.mtx.matrix(which)}}
154+
}
155+
invert true
156+
name ColorMatrix3
157+
label "XYZ to RGB"
158+
xpos 180
159+
ypos 176
160+
addUserKnob {20 Gamut}
161+
addUserKnob {3 which}
162+
which {{parent.gamut_in}}
163+
addUserKnob {12 rxy}
164+
rxy {{parent.mtx.rxy(which)} {parent.mtx.rxy(which)}}
165+
addUserKnob {12 gxy}
166+
gxy {{parent.mtx.gxy(which)} {parent.mtx.gxy(which)}}
167+
addUserKnob {12 bxy}
168+
bxy {{parent.mtx.bxy(which)} {parent.mtx.bxy(which)}}
169+
addUserKnob {12 wxy}
170+
wxy {{parent.mtx.wxy(which)} {parent.mtx.wxy(which)}}
171+
}
172+
push $N290b2840
173+
ColorMatrix {
174+
matrix {
175+
{{parent.mtx.matrix(which)} {parent.mtx.matrix(which)} {parent.mtx.matrix(which)}}
176+
{{parent.mtx.matrix(which)} {parent.mtx.matrix(which)} {parent.mtx.matrix(which)}}
177+
{{parent.mtx.matrix(which)} {parent.mtx.matrix(which)} {parent.mtx.matrix(which)}}
178+
}
179+
name RGBtoXYZ
180+
xpos -260
181+
ypos 38
182+
addUserKnob {20 Gamut}
183+
addUserKnob {3 which}
184+
which {{parent.gamut_in}}
185+
addUserKnob {12 rxy}
186+
rxy {{parent.mtx.rxy(which)} {parent.mtx.rxy(which)}}
187+
addUserKnob {12 gxy}
188+
gxy {{parent.mtx.gxy(which)} {parent.mtx.gxy(which)}}
189+
addUserKnob {12 bxy}
190+
bxy {{parent.mtx.bxy(which)} {parent.mtx.bxy(which)}}
191+
addUserKnob {12 wxy}
192+
wxy {{parent.mtx.wxy(which)} {parent.mtx.wxy(which)}}
193+
}
194+
ColorMatrix {
195+
matrix {
196+
{0.9874471426 -0.005980737507 0.01595583558}
197+
{-0.00739388587 1.001675606 0.005319938064}
198+
{0.003088310361 -0.005131930113 1.081959367}
199+
}
200+
invert {{"parent.RGBtoXYZ.wxy == 0.3127"}}
201+
name ColorMatrix4
202+
label "CAT: Bradford\n D60 to D65"
203+
xpos -260
204+
ypos 101
205+
disable {{"RGBtoXYZ.wxy == XYZtoRGB.wxy"}}
206+
}
207+
ColorMatrix {
208+
matrix {
209+
{{parent.mtx.matrix(which)} {parent.mtx.matrix(which)} {parent.mtx.matrix(which)}}
210+
{{parent.mtx.matrix(which)} {parent.mtx.matrix(which)} {parent.mtx.matrix(which)}}
211+
{{parent.mtx.matrix(which)} {parent.mtx.matrix(which)} {parent.mtx.matrix(which)}}
212+
}
213+
invert true
214+
name XYZtoRGB
215+
xpos -260
216+
ypos 182
217+
addUserKnob {20 Gamut}
218+
addUserKnob {3 which}
219+
which {{parent.gamut_out}}
220+
addUserKnob {12 rxy}
221+
rxy {{parent.mtx.rxy(which)} {parent.mtx.rxy(which)}}
222+
addUserKnob {12 gxy}
223+
gxy {{parent.mtx.gxy(which)} {parent.mtx.gxy(which)}}
224+
addUserKnob {12 bxy}
225+
bxy {{parent.mtx.bxy(which)} {parent.mtx.bxy(which)}}
226+
addUserKnob {12 wxy}
227+
wxy {{parent.mtx.wxy(which)} {parent.mtx.wxy(which)}}
228+
}
229+
Switch {
230+
inputs 2
231+
which {{parent.invert}}
232+
name switch_direction
233+
xpos -40
234+
ypos 303
235+
}
236+
Output {
237+
name Output
238+
xpos -40
239+
ypos 374
240+
}
241+
push $N290b2840
242+
ColorMatrix {
243+
matrix {
244+
{{curve 0.9525524378 0.6624541879 0.7053968906 0.4123907983 0.6369580626 0.5049495697 0.4865709841 0.6380076408 0.7352752686 0.5022571683 0.7160496712 0.7064827085 0.5990839601 0.6796444654 0.6481720209 0.6065810919 0.7165006995 0.7976718545} {curve 0 0.1340042055 0.1640413404 0.3575843275 0.1446169019 0.2646814585 0.2656676769 0.2147038579 0.06860940903 0.2929667532 0.1296834797 0.1288010478 0.2489254922 0.1522114277 0.1940581352 0.2203479856 0.1010205746 0.1351878047} {curve 9.367863095e-05 0.1561876982 0.08101774752 0.180480808 0.1688809693 0.1830150485 0.1982172877 0.09774444997 0.1465712637 0.1552320272 0.1047228053 0.1151721701 0.1024464965 0.1186000481 0.108225815 0.123526901 0.1467743814 0.03133957833}}
245+
{{curve 0.3439664543 0.2722287476 0.2801307142 0.2126390189 0.2627002299 0.237623319 0.2289745659 0.2919537723 0.2866941094 0.1387997568 0.2612613738 0.2709796727 0.2150758505 0.2606855333 0.2830046713 0.2680045366 0.258728236 0.2880405784} {curve 0.7281661034 0.6740817428 0.8202066422 0.7151686549 0.6779980659 0.6891706586 0.6917385459 0.8238410354 0.8429791331 0.910841465 0.8696421385 0.786606431 0.8850684762 0.7748944759 0.8131960034 0.8326833844 0.7246823311 0.7118694782} {curve -0.07213255018 0.05368951708 -0.1003373638 0.07219231874 0.05930171534 0.07320601493 0.07928691059 -0.1157948226 -0.1296732277 -0.04964122549 -0.1309035122 -0.05758608505 -0.1001443192 -0.03558001295 -0.09620071948 -0.1006879359 0.01658944227 8.991353388e-05}}
246+
{{curve -3.863927134e-08 -0.005574660841 -0.1037815213 0.01933082007 0 0 0 0.0027982709 -0.07968087494 0.07801423222 -0.009676366113 -0.009677864611 -0.03206583485 -0.009310216643 -0.01825834997 -0.02941203304 -2.906408625e-08 0} {curve 0 0.004060741514 -0.07290724665 0.1191947311 0.0280726999 0.0449459292 0.04511339962 -0.06703422964 -0.3473432064 -0.3148325086 -0.2364816219 0.004600019194 -0.02765839547 -0.004612449091 -0.08316776901 -0.08659287542 0.05121183768 -1.262213711e-08} {curve 1.008825183 1.010339141 1.265746474 0.950532198 1.060985088 0.9638792276 1.043944359 1.153293729 1.51608181 1.325875998 1.335215807 1.094135642 1.148782015 1.102980375 1.190483928 1.205062628 0.7738927603 0.8248898983}}
247+
}
248+
name mtx
249+
label "\n"
250+
xpos -40
251+
ypos 38
252+
addUserKnob {20 Params}
253+
addUserKnob {12 rxy}
254+
rxy {{curve 0.7347 0.713 0.8 0.64 0.708 0.68 0.68 0.684 0.780308 0.69848046 0.74 0.73 0.766 0.73 0.71 0.7177 0.7347 0.734699} {curve 0.2653 0.293 0.3177 0.33 0.292 0.32 0.32 0.313 0.304253 0.19302645 0.27 0.28 0.275 0.28 0.31 0.3171 0.2653 0.265301}}
255+
addUserKnob {12 gxy}
256+
gxy {{curve 0 0.165 0.18 0.3 0.17 0.265 0.265 0.221 0.121595 0.32955538 0.17 0.14 0.225 0.165 0.21 0.228 0.1152 0.159597} {curve 1 0.83 0.9 0.6 0.797 0.69 0.69 0.848 1.493994 1.02459662 1.14 0.855 0.8 0.84 0.88 0.8616 0.8264 0.840403}}
257+
addUserKnob {12 bxy}
258+
bxy {{curve 0.0001 0.128 0.065 0.15 0.131 0.15 0.15 0.0861 0.095612 0.10844263 0.08 0.1 0.089 0.1 0.09 0.1006 0.1566 0.036598} {curve -0.077 0.044 -0.0805 0.06 0.046 0.06 0.06 -0.102 -0.084589 -0.03467857 -0.1 -0.05 -0.087 -0.03 -0.08 -0.082 0.0177 0.000105}}
259+
addUserKnob {12 wxy}
260+
wxy {{curve 0.32168 0.32168 0.3127 0.3127 0.3127 0.32168 0.3127 0.3127 0.3127 0.3127 0.3127 0.3127 0.3127 0.3127 0.3127 0.3127 0.3457 0.345704} {curve 0.33767 0.33767 0.329 0.329 0.329 0.33767 0.329 0.329 0.329 0.329 0.329 0.329 0.329 0.329 0.329 0.329 0.3585 0.35854}}
261+
}
262+
end_group
263+
Switch {
264+
inputs 2
265+
which {{parent.use_input_image}}
266+
name Switch_distance_source
267+
xpos 180
268+
ypos 62
269+
}
270+
Group {
271+
name ColorDistance
272+
xpos 180
273+
ypos 110
274+
addUserKnob {20 ColorDistance}
275+
addUserKnob {7 shd_rolloff l "shd rolloff" R 0 0.1}
276+
shd_rolloff {{parent.shd_rolloff}}
277+
}
278+
Input {
279+
inputs 0
280+
name Input
281+
xpos -40
282+
ypos -274
283+
}
284+
Dot {
285+
name Dot5
286+
xpos -6
287+
ypos -222
288+
}
289+
set N2928e1e0 [stack 0]
290+
Dot {
291+
name Dot1
292+
xpos -116
293+
ypos -222
294+
}
295+
Expression {
296+
channel0 {rgba.red rgba.green rgba.blue none}
297+
expr0 max(r,g,b)
298+
name achromatic
299+
xpos -150
300+
ypos -177
301+
}
302+
set N29297e70 [stack 0]
303+
push $N2928e1e0
304+
Merge2 {
305+
inputs 2
306+
operation minus
307+
bbox B
308+
Achannels rgb
309+
Bchannels rgb
310+
output rgb
311+
name Merge2
312+
xpos -40
313+
ypos -177
314+
}
315+
push $N29297e70
316+
Expression {
317+
temp_name0 c_r
318+
temp_expr0 1-r
319+
temp_name1 c_g
320+
temp_expr1 1-g
321+
temp_name2 c_b
322+
temp_expr2 1-b
323+
expr0 1-(c_r<(1-thr)?c_r:(1-thr)+thr*tanh(((c_r-(1-thr))/thr)))
324+
expr1 1-(c_g<(1-thr)?c_g:(1-thr)+thr*tanh(((c_g-(1-thr))/thr)))
325+
expr2 1-(c_b<(1-thr)?c_b:(1-thr)+thr*tanh(((c_b-(1-thr))/thr)))
326+
name toe
327+
xpos -150
328+
ypos -129
329+
disable {{parent.shd_rolloff==0}}
330+
addUserKnob {20 Params_tab l Params}
331+
addUserKnob {7 thr t "complement of threshold"}
332+
thr {{parent.shd_rolloff}}
333+
}
334+
Merge2 {
335+
inputs 2
336+
operation divide
337+
bbox B
338+
Achannels rgb
339+
Bchannels rgb
340+
output rgb
341+
name Merge3
342+
xpos -40
343+
ypos -129
344+
}
345+
Output {
346+
name Output
347+
xpos -40
348+
ypos -58
349+
}
350+
end_group
351+
CurveTool {
352+
operation "Max Luma Pixel"
353+
channels {rgba.red -rgba.green -rgba.blue none}
354+
ROI {0 0 {width} {height}}
355+
autocropdata {480 270 1440 810}
356+
maxlumapixdata {{curve} {curve}}
357+
maxlumapixvalue {{curve} {curve} 0}
358+
minlumapixdata {{curve} {curve}}
359+
minlumapixvalue {{curve} {curve} 0}
360+
name rmax
361+
tile_color 0x84000000
362+
xpos 180
363+
ypos 158
364+
}
365+
CurveTool {
366+
operation "Max Luma Pixel"
367+
channels {-rgba.red rgba.green -rgba.blue none}
368+
ROI {0 0 {width} {height}}
369+
autocropdata {480 270 1440 810}
370+
maxlumapixdata {{curve x1 2} {curve x1 0}}
371+
maxlumapixvalue {{curve x1 0} {curve x1 0.9845341444} 0}
372+
minlumapixdata {{curve x1 1} {curve x1 0}}
373+
minlumapixvalue {{curve x1 0} {curve x1 0} 0}
374+
name gmax
375+
tile_color 0x84000000
376+
xpos 180
377+
ypos 182
378+
}
379+
CurveTool {
380+
operation "Max Luma Pixel"
381+
channels {-rgba.red -rgba.green rgba.blue none}
382+
ROI {0 0 {width} {height}}
383+
autocropdata {480 270 1440 810}
384+
maxlumapixdata {{curve x1 0} {curve x1 0}}
385+
maxlumapixvalue {{curve x1 0} {curve x1 0} 0.9951567054}
386+
minlumapixdata {{curve x1 2} {curve x1 0}}
387+
minlumapixvalue {{curve x1 0} {curve x1 0} 0}
388+
name bmax
389+
tile_color 0x84000000
390+
xpos 180
391+
ypos 206
392+
}
393+
end_group

0 commit comments

Comments
 (0)