How do you refer to the width of image in Custom Nodes?

Get answers to your questions about color grading, editing and finishing with DaVinci Resolve.
  • Author
  • Message
Offline

smith99

  • Posts: 17
  • Joined: Wed Sep 05, 2018 1:13 pm
  • Real Name: David Smith

How do you refer to the width of image in Custom Nodes?

PostSun Sep 09, 2018 4:16 am

On page 1590 of the Davinci Resolve 15 Manual for the Custom Node in Fusion tab, it states that you refer to Point In 1 X as p1x but in practice this does not work and I have to specify PointIn1.X

I am trying to work out the angle of a line based on two points by doing a calculation based on the slope/gradient of a line something like deg(atan((PointIn1.X-PointIn2.X)/(PointIn1.Y-PointIn2.Y))) but this is giving the wrong result i'm assuming because X and Y vary from 0 to 1 in both directions, but the aspect ratio of the screen does not, so if the aspect ratio of the screen was 1.7:1 I would have to use that number to multiply X to get the correct slope/angle.

My question is, what is the variable name to get the Width/Height or Aspect ratio of the screen/image/MediaIn1?

The manual suggests this as ax for Image Aspect X (and ay)
could also use w - Width of Image
but neither ax or w work, just like p1x did not work.
Offline

Okke Verbart

  • Posts: 293
  • Joined: Tue Jan 17, 2017 8:40 pm

Re: How do you refer to the width of image in Custom Nodes?

PostSun Sep 09, 2018 4:41 pm

Hey Dilbert - w and h should just work.

For example, if in the red channel you put h/w and you attach a 1920 by 1080 input image to input 1, then the value of the red channel becomes approx 0.56 (i.e. 1080/1920)
www.ablackbirdcalledsue.com
Offline

Okke Verbart

  • Posts: 293
  • Joined: Tue Jan 17, 2017 8:40 pm

Re: How do you refer to the width of image in Custom Nodes?

PostSun Sep 09, 2018 4:50 pm

Oh, and btw: ax and ay refer to the pixel aspect ratio... so if you work with square pixels, this is 1 for both. I have to say that the manual is not very clear on that.
www.ablackbirdcalledsue.com
Offline

Okke Verbart

  • Posts: 293
  • Joined: Tue Jan 17, 2017 8:40 pm

Re: How do you refer to the width of image in Custom Nodes?

PostSun Sep 09, 2018 5:25 pm

Oh, and as for the challenge.... see code below (just paste in the Fusion tab --> will generate a custom tool). In short: I set up 2 points, one at 0,0 (bottom left) and the other one at 1,1 (top right). Then in the intermediate tab I calculate an i1 ( p2x-p1x) and i2 (p2y-p1y). And then finally in the red channel (just to illustrate): atan((i2/i1)*(h/w))/100 --> when connecting a 1920 x 1080 image to input1, this yields approx 0.29 (as it was divided by 100)... i.e. 29 degrees.

Code: Select all
{
   Tools = ordered() {
      CustomTool1 = Custom {
         CtrlWZoom = false,
         Inputs = {
            PointIn1 = Input { Value = { 0, 0 }, },
            PointIn2 = Input { Value = { 0.989583333333333, 0.992592592592593 }, },
            LUTIn1 = Input {
               SourceOp = "CustomTool1LUTIn1",
               Source = "Value",
            },
            LUTIn2 = Input {
               SourceOp = "CustomTool1LUTIn2",
               Source = "Value",
            },
            LUTIn3 = Input {
               SourceOp = "CustomTool1LUTIn3",
               Source = "Value",
            },
            LUTIn4 = Input {
               SourceOp = "CustomTool1LUTIn4",
               Source = "Value",
            },
            Intermediate1 = Input { Value = "p2x-p1x", },
            Intermediate2 = Input { Value = "p2y-p1y", },
            RedExpression = Input { Value = "atan((i2/i1)*(h/w))/100", },
            PointControls = Input { Value = 1, },
         },
         ViewInfo = OperatorInfo { Pos = { 550, 247.5 } },
      },
      CustomTool1LUTIn1 = LUTBezier {
         KeyColorSplines = {
            [0] = {
               [0] = { 0, RH = { 0.333333333333333, 0.333333333333333 }, Flags = { Linear = true } },
               [1] = { 1, LH = { 0.666666666666667, 0.666666666666667 }, Flags = { Linear = true } }
            }
         },
         SplineColor = { Red = 204, Green = 0, Blue = 0 },
         NameSet = true,
      },
      CustomTool1LUTIn2 = LUTBezier {
         KeyColorSplines = {
            [0] = {
               [0] = { 0, RH = { 0.333333333333333, 0.333333333333333 }, Flags = { Linear = true } },
               [1] = { 1, LH = { 0.666666666666667, 0.666666666666667 }, Flags = { Linear = true } }
            }
         },
         SplineColor = { Red = 0, Green = 204, Blue = 0 },
         NameSet = true,
      },
      CustomTool1LUTIn3 = LUTBezier {
         KeyColorSplines = {
            [0] = {
               [0] = { 0, RH = { 0.333333333333333, 0.333333333333333 }, Flags = { Linear = true } },
               [1] = { 1, LH = { 0.666666666666667, 0.666666666666667 }, Flags = { Linear = true } }
            }
         },
         SplineColor = { Red = 0, Green = 0, Blue = 204 },
         NameSet = true,
      },
      CustomTool1LUTIn4 = LUTBezier {
         KeyColorSplines = {
            [0] = {
               [0] = { 0, RH = { 0.333333333333333, 0.333333333333333 }, Flags = { Linear = true } },
               [1] = { 1, LH = { 0.666666666666667, 0.666666666666667 }, Flags = { Linear = true } }
            }
         },
         SplineColor = { Red = 204, Green = 204, Blue = 204 },
         NameSet = true,
      }
   },
   ActiveTool = "CustomTool1"
}
www.ablackbirdcalledsue.com
Offline

smith99

  • Posts: 17
  • Joined: Wed Sep 05, 2018 1:13 pm
  • Real Name: David Smith

Re: How do you refer to the width of image in Custom Nodes?

PostMon Sep 10, 2018 2:56 am

Okke Verbart wrote:Hey Dilbert - w and h should just work.

For example, if in the red channel you put h/w and you attach a 1920 by 1080 input image to input 1, then the value of the red channel becomes approx 0.56 (i.e. 1080/1920)


Hi, thanks for your input, what you put was helpful.

I am using the fusion tab and in a custom tool taking something like Number in 1 field, right clicking and choosing expression, then in that box I am typing in values like p1x or w and these don't work.
Values that did work for me were things like pi, PointIn1.X, time.

Were you putting the formulae in an expression box or somewhere else? I am on Davinci Resolve version 15.0.1.003. I noticed that you were not converting from radians to degrees, I wonder if this is a version difference thing or that I am using an expression field (i.e. an issue with the expression field) and you are using something different.
Last edited by smith99 on Mon Sep 10, 2018 3:07 am, edited 3 times in total.
Offline

smith99

  • Posts: 17
  • Joined: Wed Sep 05, 2018 1:13 pm
  • Real Name: David Smith

Re: How do you refer to the width of image in Custom Nodes?

PostMon Sep 10, 2018 2:58 am

Okke Verbart wrote:Oh, and btw: ax and ay refer to the pixel aspect ratio... so if you work with square pixels, this is 1 for both. I have to say that the manual is not very clear on that.


That makes sense, I should use w and h and not the pixel aspect ratio - yes, I misunderstood that documentation. I'll re-read that part later.
Offline

Okke Verbart

  • Posts: 293
  • Joined: Tue Jan 17, 2017 8:40 pm

Re: How do you refer to the width of image in Custom Nodes?

PostMon Sep 10, 2018 7:16 am

Hey David -

I am using the fusion tab and in a custom tool taking something like Number in 1 field, right clicking and choosing expression, then in that box I am typing in values like p1x or w and these don't work.
Values that did work for me were things like pi, PointIn1.X, time.


Yes, it's a bit confusing, but in essence, these (w, h, ax etc) are only available to parts of the custom tool: channels, inter and setup tab. These all deal with the actual processing of the image and take input from the variables defined on the controls tab. Now on the controls tab itself, you use "normal" expressions and you can link those to other nodes. Here you can find the height of the image1 input1 with:
Code: Select all
Image1.Width

and Height:
Code: Select all
Image1.Height


So you could use those for instance for Number in 1 or 2.

Were you putting the formulae in an expression box or somewhere else? I am on Davinci Resolve version 15.0.1.003. I noticed that you were not converting from radians to degrees, I wonder if this is a version difference thing or that I am using an expression field (i.e. an issue with the expression field) and you are using something different.


This is something you find in Fusion a fair bit: inconsistencies in expressions syntax, units etc. depending on where you use it. Seems that in the "normal" expressions tan/atan etc deal with radians, whereas on the channels, intermediate and setup tab it deals with degrees.

You can test this with an example. Pipe a standard background into a custom tool and then display the custom tool in the viewer. Then in the controls tab for Number in 1 type the expression:

Code: Select all
atan(1)


This yields 0.785, which is indeed in radians. Converting this, as you had correctly stated yields the degrees:

Code: Select all
deg(atan(1))


This yields 45.

However, if you move over to the channels tab and for the red channel type in:

Code: Select all
atan(1)/100


If you then hover over the image in the viewer (now showing a dark red) you see 0.447. I think this is a type of rounding error, but would round up to 0.45 (i.e. 45 degrees divided by 100). Now, here's the thing, since the Fusion update last December (2017), you now have maths functions that deal with radians, for example (again, use it for example in the red channel)

Code: Select all
atanr(1)


This yields 0.785

I just checked it in Resolve on the Fusion tab, and it works the same there.
www.ablackbirdcalledsue.com
Offline

smith99

  • Posts: 17
  • Joined: Wed Sep 05, 2018 1:13 pm
  • Real Name: David Smith

Re: How do you refer to the width of image in Custom Nodes?

PostMon Sep 10, 2018 10:57 am

Thanks a lot, I think I am getting it now as a Davinci Resolve newbie...

After watching a youtube video, I think the person making it made me think that the custom node is a way to do expressions and gather input that can be connected to other controls. For example you could put the number 5 into Number in 1 field and then use that variable to control cloning so that a single line turns in to 5 rotated lines and so on. While you can do that, that is not the primary purpose of the custom node.

The custom node is a way to accept image inputs in to the controls panel - the gui for connecting other inputs, this is then available to the setup (run once) and intermediate tabs (run once for each pixel). All this is then available to the channels tab as a way to effect change to the rgba values of an image.

I'm guessing the custom node can take 1-3 images and do things with them putting the values on the output. It can also take an effect mask to limit the scope of the custom node.

Does that sound like I am on the right track - I guess I was using the tool for something it wasn't really designed for - as a way to share 4 x/y values and 8 numbers.
Offline

Okke Verbart

  • Posts: 293
  • Joined: Tue Jan 17, 2017 8:40 pm

Re: How do you refer to the width of image in Custom Nodes?

PostMon Sep 10, 2018 3:18 pm

Yeh, you're on the right track. Having said that, the beauty of Fusion is that you can use the nodes for lots of different purposes, and I think there are a fair few people that use the Custom Tool just the way you describe it. Personally, I mostly use it to manipulate images, but have definitely also used it in the way you describe. There's a lot of fun to be had with it for sure!
www.ablackbirdcalledsue.com

Return to DaVinci Resolve

Who is online

Users browsing this forum: ammar.istanbuli, Bing [Bot], Google [Bot], la_jarre_a_son, Leslie Wand, RawwRaww, Tony359 and 275 guests