# LensDistortion

> Undistort / redistort with radial k1, k2 (same model as the CameraTracker solve).

Undistort / redistort with radial k1, k2 (same model as the CameraTracker solve). Output STMap for the STMap node.

| Node | LensDistortion |
|---|---|
| Menu | Transform › LensDistortion |
| **Names in each format** | |
| .oink comp (JSON) | `"type": "OC_N_lensdistortion"` |
| .nk script | `LensDistortion2`, also imports `LensDistortion` ([how .nk import works](/docs/nuke-users/nk-import)) |
| Python | `nuke.createNode("LensDistortion2")` |
| Assistant (MCP) | `create_node(type="LensDistortion")` |
| Tab search | `lensdistortion`, or its initials `ld` |

![LensDistortion properties](/shots/nodes/lensdistortion@2x.webp)

## Inputs and outputs

| Port | Name | Type |
|---|---|---|
| input 0 | Image | image |
| input 1 | mask | image |
| output 0 | Image | image |

## Knobs

Panel tab **Lensdistortion**, in panel order.

| Knob | Label | Type | Default | Range / values | .nk knob | Description |
|---|---|---|---|---|---|---|
| `channels` | channels | menu | `all` | rgba, rgb, alpha, all, none |  | Layer the op applies to: rgb, rgba, alpha, all, none, <layer> or <layer>.<ch> |
| `mode` | mode | menu | `undistort` | undistort, redistort | `output` |  |
| `output` | output | menu | `image` | image (Image), stmap (STMap) | `outputType` |  |
| `k1` | k1 | float | `0` | -0.5 to 0.5 | `k1` |  |
| `k2` | k2 | float | `0` | -0.5 to 0.5 | `k2` |  |
| `center_offset` | centre offset | vector ×2 | `0, 0` | -500 to 500 | `center_offset` |  |
| `filter` | filter | menu | `cubic` | cubic (Cubic), bilinear (Bilinear) | `filter` |  |
| `mask_channel` | mask | menu | `none` | none, rgba.alpha, rgba.red, rgba.green, rgba.blue |  | Mask channel, e.g. rgba.alpha (none = no mask) |
| `inject` | inject | bool | `false` |  |  | Copy the mask into mask.a for nodes downstream |
| `invert_mask` | invert | bool | `false` |  | `invert_mask` |  |
| `fringe` | fringe | bool | `false` |  |  | Only apply the effect at the edges of the mask |
| `unpremult` | (un)premult by | menu | `none` | none, rgba.alpha |  |  |
| `invert_unpremult` | invert | bool | `false` |  |  | (Un)premultiply by 1 - alpha |
| `mix` | mix | float | `1` | 0 to 1 | `mix` |  |

### Other knobs (Python, .nk and the assistant; not on the panel)

| Knob | Label | Type | Default | Range / values | .nk knob | Description |
|---|---|---|---|---|---|---|
| `gl_color` | Viewer Controls Color | float ×3 | `0, 0, 0` | 0 to 1 |  |  |
| `postage_stamp_frame` | Static Frame | int | `1` | -2147483648 to 2147483647 |  |  |
| `lifetimeStart` | Lifetime Start | int | `0` | -2147483648 to 2147483647 |  |  |
| `lifetimeEnd` | Lifetime End | int | `100` | -2147483648 to 2147483647 |  |  |
| `useLifetime` | Use Lifetime | boolean | `false` |  |  |  |
| `cached` | Cached | boolean | `false` |  |  |  |
| `bookmark` | Bookmark | boolean | `false` |  |  |  |
| `dope_sheet` | Dope Sheet | boolean | `false` |  |  |  |
| `clone_group` | Clone Group | string |  |  |  |  |
| `link_source` | Link Source | string |  |  |  |  |
| `link_overrides` | Link Overrides | string |  |  |  |  |
| `split_views` | Split Views | string |  |  |  |  |

## Knob names in .nk scripts

| .nk knob | Knob here |
|---|---|
| `distortion1` | `k1` |
| `distortion2` | `k2` |
| `output` | `mode` |
| `outputType` | `output` |

Other .nk knobs use the same name here. See [.nk import](/docs/nuke-users/nk-import).

## Examples

Open these from **Help › Examples…**, or from the **?** menu in this node's Properties panel.

- **LensDistortion: undistort and STMap** (`examples/transform/lens_distortion.oink`): LensDistortion with a barrel k1 undistorts the Golden Gate photo. A second LensDistortion writes the same warp as an STMap (uv in red/green), and the STMap node applies it: that is how distortion is handed between packages.


---
Sources: opencomp_core/nodes/transform/lens_distortion.py, opencomp_electron/src/components/properties/knobSchema.ts, opencomp_core/nodes/help/lensdistortion.md, opencomp_core/nk/mapping.py
