Page 1 of 1

Wierd lensdistortion behaviour. Bug or improper use?

PostPosted: Fri Feb 02, 2018 9:11 pm
by ThomasManz
I was just playing around with lensdistortion workflow and came accross an unexpected result.
I put together a slapcomp with free images to recreate the situation:
Code: Select all
Composition {
   CurrentTime = 0,
   RenderRange = { 0, 1000 },
   GlobalRange = { 0, 1000 },
   CurrentID = 65,
   PlaybackUpdateMode = 0,
   Version = "Fusion 9.0.2 build 15",
   SavedOutputs = 2,
   HeldTools = 0,
   DisabledTools = 0,
   LockedTools = 0,
   AudioOffset = 0,
   AutoRenderRange = true,
   Resumable = true,
   OutputClips = {
   },
   Tools = {
      Loader1 = Loader {
         Clips = {
            Clip {
               ID = "Clip1",
               Filename = "night-sky-2211032_1920.jpg",
               FormatID = "JpegFormat",
               StartFrame = 1920,
               LengthSetManually = true,
               TrimIn = 0,
               TrimOut = 0,
               ExtendFirst = 0,
               ExtendLast = 0,
               Loop = 0,
               AspectMode = 0,
               Depth = 0,
               TimeCode = 0,
               GlobalStart = 0,
               GlobalEnd = 0
            }
         },
         Inputs = {
            ["Gamut.SLogVersion"] = Input { Value = FuID { "SLog2" }, },
         },
         ViewInfo = OperatorInfo { Pos = { 422.935, 275.05 } },
      },
      Loader2 = Loader {
         Clips = {
            Clip {
               ID = "Clip1",
               Filename = "brasilia-1959067_1920.jpg",
               FormatID = "JpegFormat",
               StartFrame = 1920,
               LengthSetManually = true,
               TrimIn = 0,
               TrimOut = 0,
               ExtendFirst = 0,
               ExtendLast = 0,
               Loop = 0,
               AspectMode = 0,
               Depth = 0,
               TimeCode = 0,
               GlobalStart = 0,
               GlobalEnd = 0
            }
         },
         Inputs = {
            ["Gamut.SLogVersion"] = Input { Value = FuID { "SLog2" }, },
         },
         ViewInfo = OperatorInfo { Pos = { 656, 83.0503 } },
      },
      ColorCorrector2 = ColorCorrector {
         Inputs = {
            WheelTintAngle1 = Input { Value = -0.5, },
            WheelTintLength1 = Input { Value = 0.0114, },
            MasterRGBGain = Input { Value = 0.893, },
            ColorRanges = Input {
               Value = ColorCurves {
                  Curves = {
                     {
                        Points = {
                           { 0, 1 },
                           { 0.4, 0.2 },
                           { 0.6, 0 },
                           { 1, 0 }
                        }
                     },
                     {
                        Points = {
                           { 0, 0 },
                           { 0.4, 0 },
                           { 0.6, 0.2 },
                           { 1, 1 }
                        }
                     }
                  }
               },
            },
            HistogramIgnoreTransparent = Input { Value = 1, },
            Input = Input {
               SourceOp = "LensDistort1",
               Source = "Output",
            },
         },
         ViewInfo = OperatorInfo { Pos = { 656, 214 } },
      },
      Polygon1 = PolylineMask {
         DrawMode = "InsertAndModify",
         DrawMode2 = "InsertAndModify",
         Inputs = {
            MaskWidth = Input { Value = 1920, },
            MaskHeight = Input { Value = 1080, },
            PixelAspect = Input { Value = { 1, 1 }, },
            ClippingMode = Input { Value = FuID { "None" }, },
            Polyline = Input {
               SourceOp = "Polygon1Polyline",
               Source = "Value",
            },
            Polyline2 = Input {
               Value = Polyline {
               },
               Disabled = true,
            },
         },
         ViewInfo = OperatorInfo { Pos = { 1054.52, 186 } },
      },
      Polygon1Polyline = BezierSpline {
         SplineColor = { Red = 173, Green = 255, Blue = 47 },
         NameSet = true,
         KeyFrames = {
            [0] = { 0, Flags = { Linear = true, LockedY = true }, Value = Polyline {
                  Closed = true,
                  Points = {
                     { X = 0.128823533654213, Y = -0.452928870916367, LX = 0.00155732787451978, LY = -0.0179081824291743, RX = -0.0117647072965024, RY = 0.135285913736418 },
                     { Linear = true, X = 0.0935294106602669, Y = -0.0470711290836334, LX = 0.0117647072965024, LY = -0.135285913736418, RX = 0.01490196115246, RY = 0.0341701532091888 },
                     { Linear = true, X = 0.138235300779343, Y = 0.055439330637455, LX = -0.01490196115246, LY = -0.0341701532091888, RX = 0.00901960562257205, RY = -0.00104602513577649 },
                     { Linear = true, X = 0.165294110774994, Y = 0.0523012541234493, LX = -0.00901960562257205, LY = 0.00104602513577649, RX = 0.0011764728789236, RY = -0.0101115756422655 },
                     { Linear = true, X = 0.168823525309563, Y = 0.0219665262848139, LX = -0.0011764728789236, LY = 0.0101115756422655, RX = 0.00450980528896932, RY = 0.00871687617563388 },
                     { Linear = true, X = 0.182352945208549, Y = 0.0481171533465385, LX = -0.00450980528896932, LY = -0.00871687617563388, RX = 0.00980392022460116, RY = 0.000348675523259826 },
                     { Linear = true, X = 0.211764708161354, Y = 0.049163181334734, LX = -0.00980392022460116, LY = -0.000348675523259826, RX = 0.0296078403440176, RY = -0.168758715353543 },
                     { Linear = true, X = 0.300588229193407, Y = -0.457112964725894, LX = -0.0296078403440176, LY = 0.168758715353543, RX = -0.0133333334969539, RY = -0.0108089259146314 },
                     { Linear = true, X = 0.260588228702545, Y = -0.489539742469788, LX = 0.0133333334969539, LY = 0.0108089259146314, RX = -0.0350980370184955, RY = 0.00313807315241177 },
                     { X = 0.155294120311737, Y = -0.480125516653061, LX = 0.00470588501761937, LY = 6.35949137906935e-09, RX = -0.01019041964286, RY = -1.37712429490365e-08 }
                  }
               } }
         }
      },
      Polygon2 = PolylineMask {
         DrawMode = "InsertAndModify",
         DrawMode2 = "InsertAndModify",
         Inputs = {
            MaskWidth = Input { Value = 1920, },
            MaskHeight = Input { Value = 1080, },
            PixelAspect = Input { Value = { 1, 1 }, },
            ClippingMode = Input { Value = FuID { "None" }, },
            Polyline = Input {
               SourceOp = "Polygon2Polyline",
               Source = "Value",
            },
            Polyline2 = Input {
               Value = Polyline {
               },
               Disabled = true,
            },
            EffectMask = Input {
               SourceOp = "Polygon1",
               Source = "Mask",
            }
         },
         ViewInfo = OperatorInfo { Pos = { 1054.52, 245 } },
      },
      Polygon2Polyline = BezierSpline {
         SplineColor = { Red = 96, Green = 255, Blue = 47 },
         NameSet = true,
         KeyFrames = {
            [0] = { 0, Flags = { Linear = true, LockedY = true }, Value = Polyline {
                  Closed = true,
                  Points = {
                     { X = 0.52823531627655, Y = -0.401673644781113, LX = 0.0402691411463316, LY = -0.0122487881214573, RX = -0.0298039289549285, RY = 0.00906555244447131 },
                     { Linear = true, X = 0.438823521137238, Y = -0.374476999044418, LX = 0.0298039289549285, LY = -0.00906555244447131, RX = -0.0478431344967262, RY = -0.0125522973896569 },
                     { X = 0.295294106006622, Y = -0.412133902311325, LX = 0.0447058707125047, LY = -0.00209206130714195, RX = -0.0548829468617915, RY = 0.00256830898764514 },
                     { X = 0.130588233470917, Y = -0.412133902311325, LX = 0.0305882334709168, LY = -0.00418411151634629, RX = -0.0770520448918333, RY = 0.0105398158640466 },
                     { X = -0.101176470518112, Y = -0.401673644781113, LX = 0.0400000000701231, LY = -0.00209205482295398, RX = -0.0984169210026169, RY = 0.00514733984707066 },
                     { X = -0.396470576524734, Y = -0.389121353626251, LX = 0.0988235411223243, LY = 0.00627613591349886, RX = -0.0267216539405036, RY = -0.00169705244377412 },
                     { X = -0.476470589637756, Y = -0.378661096096039, LX = 0.0266391795862591, LY = -0.00607865498699325, RX = 0.00549019654591878, RY = 0.0223152049748302 },
                     { Linear = true, X = -0.46000000834465, Y = -0.311715483665466, LX = -0.00549019654591878, LY = -0.0223152049748302, RX = -0.0227450952576656, RY = 0.0104602518773312 },
                     { Linear = true, X = -0.52823531627655, Y = -0.280334740877151, LX = 0.0227450952576656, LY = -0.0104602518773312, RX = -0.00588235270743276, RY = -0.084379353117577 },
                     { Linear = true, X = -0.545882374398849, Y = -0.533472800229883, LX = 0.00588235270743276, LY = 0.084379353117577, RX = 0.0952941279785306, RY = -0.016736400135724 },
                     { Linear = true, X = -0.259999990463257, Y = -0.583682000637054, LX = -0.0952941279785306, LY = 0.016736400135724, RX = 0.277647055644615, RY = -0.00697350327439887 },
                     { X = 0.572941184043884, Y = -0.604602515697479, LX = 0.00470588992623733, LY = -0.0167364069108684, RX = -0.0182704881776362, RY = 0.0649786394059633 }
                  }
               } }
         }
      },
      LensDistort1 = LensDistort {
         Inputs = {
            LensDistortionModel = Input { Value = 1, },
            ["DEClassicLDModel.Distortion"] = Input { Value = 0.5, },
            ["DEClassicLDModel.CurvatureX"] = Input { Value = 0.0979, },
            ["DEClassicLDModel.CurvatureY"] = Input { Value = 0.2063, },
            ["DEClassicLDModel.QuarticDistortion"] = Input { Value = 0.5, },
            ["DE4RadialFisheyeDegree8Release2.DistortionDegree2"] = Input { Value = 0.385, },
            ["DE4RadialFisheyeDegree8Release2.QuarticDistortionDegree4"] = Input { Value = 0.5, },
            ["DE4RadialFisheyeDegree8Release2.Degree6"] = Input { Value = -0.4462, },
            ["DE4RadialFisheyeDegree8Release2.Degree8"] = Input { Value = 0.1031, },
            ApertureW = Input { Value = 0.8314961, },
            ApertureH = Input { Value = 0.4677165, },
            LensShiftY = Input { Value = -0.2, },
            Input = Input {
               SourceOp = "Loader2",
               Source = "Output",
            },
         },
         ViewInfo = OperatorInfo { Pos = { 656, 162 } },
      },
      ChannelBooleans2 = ChannelBoolean {
         Inputs = {
            ToRed = Input { Value = 2, },
            ToGreen = Input { Value = 2, },
            Background = Input {
               SourceOp = "LensDistort1",
               Source = "Output",
            },
         },
         ViewInfo = OperatorInfo { Pos = { 860.521, 162 } },
      },
      ColorCorrector1 = ColorCorrector {
         Inputs = {
            MasterRGBContrast = Input { Value = 1.596, },
            MasterRGBGain = Input { Value = 1.459, },
            ColorRanges = Input {
               Value = ColorCurves {
                  Curves = {
                     {
                        Points = {
                           { 0, 1 },
                           { 0.4, 0.2 },
                           { 0.6, 0 },
                           { 1, 0 }
                        }
                     },
                     {
                        Points = {
                           { 0, 0 },
                           { 0.4, 0 },
                           { 0.6, 0.2 },
                           { 1, 1 }
                        }
                     }
                  }
               },
            },
            HistogramIgnoreTransparent = Input { Value = 1, },
            Input = Input {
               SourceOp = "ChannelBooleans2",
               Source = "Output",
            },
         },
         ViewInfo = OperatorInfo { Pos = { 860.521, 196 } },
      },
      LumaKeyer1 = LumaKeyer {
         Inputs = {
            MatteContrast = Input { Value = 0.275, },
            Invert = Input { Value = 1, },
            ["Solid.Matte"] = Input {
               SourceOp = "Polygon2",
               Source = "Mask",
            },
            ["Solid.MaskNest"] = Input { Value = 1, },
            ["Garbage.MaskNest"] = Input { Value = 1, },
            Input = Input {
               SourceOp = "ColorCorrector1",
               Source = "Output",
            },
         },
         ViewInfo = OperatorInfo { Pos = { 860.521, 245 } },
      },
      ChannelBooleans1 = ChannelBoolean {
         Inputs = {
            Operation = Input { Value = 6, },
            ToRed = Input { Value = 3, },
            ToGreen = Input { Value = 3, },
            ToBlue = Input { Value = 3, },
            Background = Input {
               SourceOp = "ColorCorrector2",
               Source = "Output",
            },
            Foreground = Input {
               SourceOp = "LumaKeyer1",
               Source = "Output",
            },
         },
         ViewInfo = OperatorInfo { Pos = { 656, 333 } },
      },
      Merge1 = Merge {
         Inputs = {
            Background = Input {
               SourceOp = "Loader1",
               Source = "Output",
            },
            Foreground = Input {
               SourceOp = "ChannelBooleans1",
               Source = "Output",
            },
            PerformDepthMerge = Input { Value = 0, },
         },
         ViewInfo = OperatorInfo { Pos = { 511, 501 } },
      },
      LensDistort1_1 = LensDistort {
         CtrlWZoom = false,
         Inputs = {
            Mode = Input { Value = 0, },
            LensDistortionModel = Input { Value = 1, },
            ["DEClassicLDModel.Distortion"] = Input { Value = 0.5, },
            ["DEClassicLDModel.CurvatureX"] = Input { Value = 0.0979, },
            ["DEClassicLDModel.CurvatureY"] = Input { Value = 0.2063, },
            ["DEClassicLDModel.QuarticDistortion"] = Input { Value = 0.5, },
            ["DE4RadialFisheyeDegree8Release2.DistortionDegree2"] = Input { Value = 0.385, },
            ["DE4RadialFisheyeDegree8Release2.QuarticDistortionDegree4"] = Input { Value = 0.5, },
            ["DE4RadialFisheyeDegree8Release2.Degree6"] = Input { Value = -0.4462, },
            ["DE4RadialFisheyeDegree8Release2.Degree8"] = Input { Value = 0.1031, },
            ApertureW = Input { Value = 0.8314961, },
            ApertureH = Input { Value = 0.4677165, },
            LensShiftY = Input { Value = -0.2, },
            Input = Input {
               SourceOp = "Merge1",
               Source = "Output",
            },
         },
         ViewInfo = OperatorInfo { Pos = { 511, 566.365 } },
      }
   },
   Views = {
      {
         FrameTypeID = "ChildFrame",
         Mode = 3,
         LayoutPreset = 0,
         Left = 0,
         Top = 27,
         Width = 1920,
         Height = 913,
         Views = ordered() {
            Main = MultiView {
               Active = "Flow",
               ViewList = ordered() {
                  Flow = "FlowView",
                  Console = "ConsoleView",
                  Timeline = "TimelineView",
                  Spline = "SplineEditorView",
                  Info = "InfoView",
                  Chat = "ChatView"
               },
               Flow = FlowView {
                  Flags = {
                     Navigator = true,
                     AutoHideNavigator = true,
                     ConnectedSnap = true,
                     AutoSnap = true,
                     RemoveRouters = true
                  },
                  NavigatorSize = { 200, 140 },
                  Direction = "Horizontal",
                  PipeStyle = "Direct",
                  Scale = 1,
                  Offset = { 235.296, -286.541 }
               },
               Timeline = TimelineView {
                  TreeControlState = {
                  },
                  DisplayMode = "All Tools",
                  ShowCurrentTimeTools = false,
                  Filter = "Show All",
                  ShowSelectedTools = false,
                  ShowAnimatedToolsOnly = false,
                  ShowEditBoxes = false,
                  KeyFrameView = {
                     Position = { Left = 150, Bottom = 1047 },
                     ScaleX = 0.623229461756374,
                     OffsetX = -49.8583569405099,
                     OffsetY = 0,
                     AutoScaling = "scroll",
                     AutoSnapTo = "frame",
                     AutoSnapToGuidelines = true,
                     GuidelinesGrabEnabled = true,
                     GuidelinesSnapTo = "none"
                  },
                  Spreadsheet = { LeftPos = 150, Visible = false }
               },
               Spline = SplineEditorView {
                  LeftPos = 256,
                  ScaleX = 0.2,
                  ScaleY = 0.00338983050847458,
                  OffsetX = -3.8,
                  OffsetY = 0,
                  AutoScaling = "scroll",
                  AutoSnapTo = "frame",
                  AutoSnapToGuidelines = true,
                  GuidelinesSnapTo = "frame",
                  ShowKeyMarkers = false,
                  IndependentHandles = false,
                  ShowNonSplineModifiers = false,
                  GuidelinesGrabEnabled = true,
                  ShowOneToolOnly = false,
                  ShowSelectedTools = false,
                  ShowAllInputs = false,
                  Filter = "Show All"
               },
            },
            Controls = MultiView {
               Active = "Tools",
               ViewList = ordered() {
                  Tools = "ControlView",
                  Modifiers = "ModifierView"
               },
            },
            Left = "PreviewContainer",
            Right = "PreviewContainer",
            Transport = "TransportView",
            Time = "TimeView"
         },
         Layout = {
            Columns = 2,
            RatioX = 1,
            RatioY = 1,
            {
               Rows = 3,
               RatioX = 0.714360313315927,
               RatioY = 0.00987925356750823,
               {
                  Columns = 2,
                  RatioX = 1,
                  RatioY = 0.556906077348066,
                  { ID = "Left", RatioX = 0.493772893772894, RatioY = 100.799603174603, Pop = true },
                  { ID = "Right", RatioX = 0.506227106227106, Pop = true },
                  Pop = true
               },
               { ID = "Main", RatioY = 0.379005524861878, Pop = true },
               { ID = "Time", SnapY = 56, Flat = true }
            },
            {
               Rows = 2,
               PixelX = 545,
               { ID = "Controls", RatioX = 1, RatioY = 1 },
               { ID = "Transport", FixedY = -2 }
            }
         }
      }
   },
   Prefs = {
      Comp = {
         Views = {
            Right = {
               Viewer = {
                  ScaleMode = 1,
               },
            },
            Left = {
               Viewer = {
                  Channel = 4294967295,
                  ScaleMode = 1,
               },
               MaterialViewer = {
                  Camera = {
                     Rotation = {
                        X = 15,
                        Y = -20,
                        Z = 0
                     }
                  }
               }
            },
            View1 = {
            },
         },
         FrameFormat = {
            GuideRatio = 1.77777777777778,
         },
         PolyKeyListDlg = {
            Window = {
               Left = 907,
               Top = 224
            }
         },
         Paths = {
         },
         QuickTime = {
         },
      }
   }
}



The source images you can download for free:
background sky
foreground

I wanted to do the basic workflow of undistorting my image, replacing the background and reapply the original lensdistortion. At the Merge1 everything looks fine but the reapplication of the lensdistionrtion right after that (LensDistort1_1) behaves rather odd to me. It doesn't distort the output of the merge as if it was one image but rather the foreground and the background seperately and underneath that even the original image peaks through.
Is that a bug or am I doing something wrong?

Re: Wierd lensdistortion behaviour. Bug or improper use?

PostPosted: Mon Feb 05, 2018 12:23 am
by Miltos Pilalitos
There are a number of things you have done wrong in this comp.

1) you are keying the undistorted foreground which means the parts of the image you pushed out of the frame will not be keyed. So when you bring them back in with a redistortion they will not let your background pass through. So, first key the foreground image and THEN apply the lens undistortion on it.

2) Usually in VFX you undistort the background before adding 3D elements to it and then redistorting the final composite to match what was initially shot. It looks like you have done the opposite. Undistorted the foreground to match a background that has no lens distortion. Not sure what you are trying to do but probably you should not reapply lens distortion back in.

If however you want to have a distorted background matching your foreground, skip the foreground distortion removal/redistortion because it is unnecessary and then:

3) Add a transform tool before your final merge and scale the background up so when it is distorted (angle of view will enlarge) at the end of the pipeline you will have enough out of frame information to fill in the blanks.

In short, what you are seeing in your test is normal behavior and there is no bug.

Re: Wierd lensdistortion behaviour. Bug or improper use?

PostPosted: Mon Feb 05, 2018 7:36 am
by alan bovine
Miltos Pilalitos wrote:2) Usually in VFX you undistort the background before adding 3D elements to it and then redistorting the final composite to match what was initially shot. It


A better way is to only undistort the plate for tracking only and only redistort the CG you're adding. That way you avoid any filtering on the original plate at all and if you'can be a bit forward thinking you only need to add the distortion once.

Re: Wierd lensdistortion behaviour. Bug or improper use?

PostPosted: Mon Feb 05, 2018 9:24 am
by ThomasManz
Miltos Pilalitos wrote:There are a number of things you have done wrong in this comp.

1) you are keying the undistorted foreground which means the parts of the image you pushed out of the frame will not be keyed. So when you bring them back in with a redistortion they will not let your background pass through. So, first key the foreground image and THEN apply the lens undistortion on it.

oic, it's not the background showing throgh, it's the piece that didn't got keyed. My bad.

Miltos Pilalitos wrote:2) Usually in VFX you undistort the background before adding 3D elements to it and then redistorting the final composite to match what was initially shot. It looks like you have done the opposite. Undistorted the foreground to match a background that has no lens distortion. Not sure what you are trying to do but probably you should not reapply lens distortion back in.

Veto. That depends on the shot. In a case where the background is a liveaction plate and you want to composit something onto that you are right. But if you have a shot like this, where the liveaction is the foreground, you obviously would also undistort that foreground, wouldn't you?
Although I indeed find Alans solution to be better, at least in an extreme fisheye distortion example like this.

Re: Wierd lensdistortion behaviour. Bug or improper use?

PostPosted: Mon Feb 05, 2018 10:54 am
by alan bovine
Veto. That depends on the shot. In a case where the background is a liveaction plate and you want to composit something onto that you are right. But if you have a shot like this, where the liveaction is the foreground, you obviously would also undistort that foreground, wouldn't you?


I wouldn't. Its a better practice to match the CG to the plate than the other way around in most cases. There are exceptions of course but the general rule of thumb is to avoid messing with the plate unless there's a specific need.