Documentation
¶
Overview ¶
Package stereo makes a stereo pair of a 2D picture and its disparity: each eye is the picture shifted by half the disparity, rendered row by row so that what is nearer covers what is behind it, and what an eye sees that the picture does not (behind a nearer thing's edge) filled from the farther side.
Index ¶
- Constants
- Variables
- func ApplyInpaint(eye *mvc.Frame, holes []bool, delta []float32, top, bottom int)
- func Bars(f *mvc.Frame) (top, bottom int)
- func Curved(n, curve float32) float32
- func Dense(dm *Disparity, w, h int) []float32
- func FarLimit(v, far, knee float32) float32
- func InpaintInput(eye *mvc.Frame, holes []bool, top, bottom int) *nn.Tensor
- func Pair(f *mvc.Frame, d []float32) (left, right *mvc.Frame)
- func Redepth(g *nn.GPU, l, r *mvc.Frame, k, shift float32) (nl, nr *mvc.Frame)
- func RefineInput(y, cb, cr []byte, stride int, depth []float32, w, h int) (x *nn.Tensor, mean, sd float64)
- func Render(f *mvc.Frame, d []float32, sign float32) (eye *mvc.Frame, holes []bool)
- func ScreenFar(diagonal float64) float64
- type Converter
- func (c *Converter) Convert(f *mvc.Frame) (left, right *mvc.Frame, err error)
- func (c *Converter) Cuts() int
- func (c *Converter) Depth(f *mvc.Frame) (*Estimate, error)
- func (c *Converter) Estimate(f *mvc.Frame) (*Estimate, error)
- func (c *Converter) Eyes(e *Estimate) (left, right *mvc.Frame, s *Samples)
- func (c *Converter) Grade(e *Estimate, s Shape, flat bool) (left, right *mvc.Frame, samples *Samples)
- func (c *Converter) Next(f *mvc.Frame) (depth, disparity []float32, err error)
- func (c *Converter) Restart()
- func (c *Converter) Shape(e *Estimate) (depth, disparity []float32)
- func (c *Converter) Start(f *mvc.Frame) *Pending
- func (c *Converter) Still(e *Estimate, s Shape) (left, right *mvc.Frame)
- func (c *Converter) Window(left, right *mvc.Frame, s *Samples)
- type CreditFeatures
- type Disparity
- type Estimate
- type Filler
- type Guide
- type InpaintWeights
- type Pending
- type RefineLayer
- type RefineWeights
- type Samples
- type Shape
- type Shaper
Constants ¶
const FarKnee = 0.7
FarKnee is where, as a share of Shape.Far, the depth behind the screen starts to be eased.
const RefineMultiple = 8
RefineMultiple is what the input's sides are padded to a multiple of.
Variables ¶
var ( BaseShape = Shape{Scale: 0.00026, Offset: -0.0075} BaseRefinedShape = Shape{Scale: 0.00022, Offset: -0.0065} LargeShape = Shape{Scale: DefaultShape.Scale / 155, Offset: DefaultShape.Offset} LargeRefinedShape = Shape{Scale: RefinedShape.Scale / 155, Offset: RefinedShape.Offset} )
The shapes of the other networks' depth (depth.Model.Size), each its own scale, found as RefinedShape was. Base's depth refined (the weights learnt on Small's) on the twelve clips: depth correlation 0.859 against Small's 0.832; the made right eye 27.7 dB and VMAF 30.4 (Small's 27.5 and 29.5), on the glass clips 26.6 and 31.9 (26.8 and 33.4). Base's depth as it is: 27.3 and 26.2, the best of three scales tried. Large's is Small's scaled by the ratio of their depth's fits to the discs' (155: untuned; Large's depth measured no better than Base's).
var DefaultGuide = Guide{}
DefaultGuide is the filter the conversion uses: none for now, since tools/stereobench measures no gain from it yet (radius 8, eps 1e-3: the made right eye within 0.1 dB either way); kept to tune.
var DefaultShape = Shape{Scale: 0.0012, Offset: -0.0075}
DefaultShape is the 3D discs' depth (native and studio-converted ones, measured by tools/stereobench): the network's depth taken as it is, 0.12% of the width a unit of it, the farthest 0.75% behind the screen. A fit of the discs' disparity by the network's depth over a whole clip finds about that on every clip (0.06% to 0.19% a unit, offsets -1.4% to +0.1%), and the network's depth is steady from picture to picture, so normalising each picture's range (Budget and Screen) only loses: 1.6 dB of the made right eye against the disc's.
var InpaintLayers = []RefineLayer{ {Name: "e1a", In: 4, Out: 16, Stride: 1, Kernel: 3}, {Name: "e1b", In: 16, Out: 16, Stride: 1, Kernel: 3}, {Name: "e2a", In: 16, Out: 32, Stride: 2, Kernel: 3}, {Name: "e2b", In: 32, Out: 32, Stride: 1, Kernel: 3}, {Name: "e3a", In: 32, Out: 48, Stride: 2, Kernel: 3}, {Name: "e3b", In: 48, Out: 48, Stride: 1, Kernel: 3}, {Name: "e4a", In: 48, Out: 64, Stride: 2, Kernel: 3}, {Name: "e4b", In: 64, Out: 64, Stride: 1, Kernel: 3}, {Name: "u3", In: 64, Out: 48, Up: true}, {Name: "d3", In: 48, Out: 48, Stride: 1, Kernel: 3}, {Name: "u2", In: 48, Out: 32, Up: true}, {Name: "d2", In: 32, Out: 32, Stride: 1, Kernel: 3}, {Name: "u1", In: 32, Out: 16, Up: true}, {Name: "d1", In: 16, Out: 16, Stride: 1, Kernel: 3}, {Name: "out", In: 16, Out: 3, Stride: 1, Kernel: 3, Residual: true}, }
InpaintLayers is the filler's layers, in their order.
var RefineLayers = []RefineLayer{ {Name: "e1a", In: 4, Out: 16, Stride: 1, Kernel: 3}, {Name: "e1b", In: 16, Out: 16, Stride: 1, Kernel: 3}, {Name: "e2a", In: 16, Out: 32, Stride: 2, Kernel: 3}, {Name: "e2b", In: 32, Out: 32, Stride: 1, Kernel: 3}, {Name: "e3a", In: 32, Out: 48, Stride: 2, Kernel: 3}, {Name: "e3b", In: 48, Out: 48, Stride: 1, Kernel: 3}, {Name: "e4a", In: 48, Out: 64, Stride: 2, Kernel: 3}, {Name: "e4b", In: 64, Out: 64, Stride: 1, Kernel: 3}, {Name: "u3", In: 64, Out: 48, Up: true}, {Name: "d3", In: 48, Out: 48, Stride: 1, Kernel: 3}, {Name: "u2", In: 48, Out: 32, Up: true}, {Name: "d2", In: 32, Out: 32, Stride: 1, Kernel: 3}, {Name: "u1", In: 32, Out: 16, Up: true}, {Name: "d1", In: 16, Out: 16, Stride: 1, Kernel: 3}, {Name: "out", In: 16, Out: 1, Stride: 1, Kernel: 3, Residual: true}, }
RefineLayers is the refinement's layers, in their order.
var RefinedShape = Shape{Scale: 0.0010, Offset: -0.0075}
RefinedShape is DefaultShape for a refined depth (Converter.Refine): found as DefaultShape was, on the benchmark's twelve clips, with weights learnt from 27 other films (since 53: the same mapping, the same scores or a little better; the made right eye 27.5 dB and VMAF 29.5 against the discs', DefaultShape's on the depth as it is 26.9 and 25.7; on the four glass clips, held out of the choice, 26.8 and 33.4 against 25.7 and 26.8).
var TunedShape = Shape{Scale: 0.00115, Offset: -0.0082}
TunedShape is DefaultShape for Small's depth with its head learnt from the 3D discs (depth.BuiltinTail), found as DefaultShape was, on the benchmark's twelve clips and checked on the wide set (fifty clips of twenty-five other films), the glass clips and Avatar 3. The whole head learnt (not the tail alone) reads the scene a little differently and wants a little less scale and a shallower offset: 0.115% a unit and -0.82% of the width against the tail's 0.13% and -0.90%. The made right eye: the twelve clips 27.63 dB and VMAF 32.0 (the tail alone at its shape 27.35 and 31.1), the wide set 28.66 and 36.2 (28.59 and 35.4), the glass clips 28.23 and 48.1 (28.11 and 45.6), Avatar 3 25.65 and 29.2 (25.83 and 31.6: that film wants a shallower shape still, 0.10% and -0.60%, where it gives 25.90 and the other sets lose a dB or more; one fixed shape is a compromise between films). Deeper offsets lose on every set: the discs go farther back than this (their 5th percentile -23 px at 1920 against ours -17), but a fixed mapping placing the far end deeper misses more than it gains.
Functions ¶
func ApplyInpaint ¶ added in v0.21.0
ApplyInpaint takes the filler's corrections (Inpaint's, downloaded: [3, H, W] for the rows [top, bottom) of eye, padded) into eye's holes: a luma pixel that is a hole, a chroma sample any of whose luma pixels is.
func Curved ¶ added in v0.21.0
Curved is the nearness n (0 the farthest of a shot's range, 1 the nearest) bent by the power curve: n to it within the range, the same slope as at the range's ends beyond them (1 below, curve above), so it stays monotone and continuous; 1 (or 0) leaves it.
func Dense ¶
Dense is a measured disparity (Match's, half resolution) at the picture's size (w x h, one value a luma pixel): each row's unsure runs filled from their farther side (behind an edge, what is unsure is mostly what one eye does not see, which lies behind), then interpolated up.
func FarLimit ¶
FarLimit is a disparity v kept short of far (pixels, 0 for no limit) behind the screen: past knee (FarKnee of far) eased as x/(1+x/r), x what lies past it and r the rest of the way, which leaves the slope 1 there and tends to far. Its steps rounded one at a time, as the GPU's disparity kernel takes them.
func InpaintInput ¶ added in v0.21.0
InpaintInput is the filler's input for an eye's rows [top, bottom) (w wide: its Y, and its Cb and Cr at half size, strideY and strideC apart) and its holes (w x h of the whole eye, true in a hole): [4, H, W], the sides padded to RefineMultiple by repeating the last row and column.
func Pair ¶
Pair renders the two eyes of f (8-bit 4:2:0) for its disparity, one value a luma pixel (d[y*Width+x], in pixels between the eyes: positive nearer than the screen, the left eye's view of a point that far right of the right eye's).
func Redepth ¶
Redepth makes a stereo pair's eyes (8-bit 4:2:0, the same size) again with its depth scaled by k and moved by shift (pixels of disparity, positive nearer). The disparity is measured between the eyes, each way (Match), and each new eye is rendered from its own camera at (1-k)/2 of the way to the other, what it then sees that its camera did not (behind a nearer thing's edge) taken from the other camera's view, which saw it, rendered there too: so with k below 1, the views between the cameras, little is invented. Above 1 the views are outside the cameras', and what neither saw is filled from the farther side, as Pair fills. The shift moves the eyes apart (each half of it), black coming in at the edges. With k 1 the eyes are only shifted.
The matching is on g when it is not nil (MatchBothGPU), else on the CPU.
func RefineInput ¶
func RefineInput(y, cb, cr []byte, stride int, depth []float32, w, h int) (x *nn.Tensor, mean, sd float64)
RefineInput is the refinement's input for a picture's active rows at half size (w x h): its Y (halved), Cb and Cr, each h rows of w, stride apart, and its depth (w x h); the sides padded to RefineMultiple by repeating the last row and column. It gives the depth's mean and deviation, which the refined depth is put back to.
Types ¶
type Converter ¶
type Converter struct {
Model *depth.Model
Shaper
// Guide snaps the depth's edges to the picture's (DefaultGuide; the
// zero Guide leaves the depth as the network gives it, upsampled).
Guide Guide
// NoWindow leaves out the floating window (window.go).
NoWindow bool
// KeepCredits gives the credits (credits.go) their depth as any
// picture's, not flat.
KeepCredits bool
// Shot, when set, gives a picture's shape (by its PTS) in place of the
// Shaper's, and whether it is made flat: a stretch of the film graded
// by hand.
Shot func(pts int64) (s Shape, flat bool)
// Refine, when not nil, corrects the depth's shape (refinenet.go), on
// the depth model's backend.
Refine *RefineWeights
// KeepDepth keeps each Estimate's depth even when a GPU makes the
// eyes, for Grade to shape it again as often as asked.
KeepDepth bool
// Fill, when not nil, fills the eyes' holes (what an eye saw nothing
// of) by the hole filler (inpaintnet.go) in place of the renderer's
// carried edge, on the depth model's backend.
Fill *Filler
// contains filtered or unexported fields
}
Converter makes the stereo pairs of a 2D film's pictures, one picture after the other: the depth of the picture's active area (letterbox bars left out, at the screen) by the depth network, shaped into disparity, the eyes rendered from it. A cut, or bars that change, starts the network's and the shaping's state afresh.
func NewConverter ¶
NewConverter is a converter for a depth model.
func (*Converter) Depth ¶
Depth is Estimate without the eyes: the picture's depth kept, for Still to shape as often as asked.
func (*Converter) Estimate ¶
Estimate is the first half of Next: the picture's depth, by the network and the refinement; on a GPU, the eyes too when it can make them (Eyes gives them).
func (*Converter) Eyes ¶
Eyes is Shape and Pair of an Estimate (the GPU's, when it made them): the picture's two eyes and their disparity's samples. The Estimates must come in order.
func (*Converter) Grade ¶ added in v0.20.0
func (c *Converter) Grade(e *Estimate, s Shape, flat bool) (left, right *mvc.Frame, samples *Samples)
Grade is Still with the picture flat when asked (on the screen, as the credits are) and never flat otherwise, whatever the credits detector made of it: a hand's grading. It gives the disparity's samples too. The Estimate's depth must be there (KeepDepth, or Depth's).
func (*Converter) Next ¶
Next gives the next picture's depth and disparity: depth, the network's (larger nearer, in its own units), NaN in the letterbox bars; disparity, shaped from it (zero in the bars), in pixels, as Pair takes it. The error is the depth model's backend's (a GPU's). It is Estimate then Shape.
func (*Converter) Restart ¶ added in v0.20.0
func (c *Converter) Restart()
Restart has the next picture start the network's and the shaping's state afresh, as the first did, and not count as a cut: the film read from somewhere else.
func (*Converter) Shape ¶
Shape is the second half of Next: an Estimate's depth upsampled to the picture and shaped into disparity. The Estimates must come in order; one whose eyes the GPU made has no depth to shape and goes to Eyes.
func (*Converter) Start ¶
Start is Estimate begun: on a GPU, its work queued and not waited for, so that the caller's own (the next picture's decoding) runs beside it. One at a time: the next Start after this one's Wait.
type CreditFeatures ¶
type CreditFeatures struct {
Dark, Thin float64
}
CreditFeatures is a picture's measures of the credits (its active rows [top, bottom), every other pixel): Dark, the share that is black; Thin, the share of the rest in runs (across a row) of at most creditStroke pixels with black either side, as letters' strokes are.
func Credits ¶
func Credits(f *mvc.Frame, top, bottom int) CreditFeatures
Credits measures a picture's credit features.
func (CreditFeatures) IsCredits ¶
func (c CreditFeatures) IsCredits() bool
IsCredits reports whether a picture's features are the credits'.
type Disparity ¶
Disparity is a disparity map measured between a stereo pair's eyes, at half their resolution: D[y*W+x], in the eyes' (full resolution) pixels, positive nearer than the screen (the left eye's view of a point that far right of the right eye's), where Valid says the match is sure.
func Match ¶
Match measures the disparity between a stereo pair's eyes (8-bit 4:2:0, the same size): their luma halved, a census transform's costs aggregated along eight paths (semi-global matching), the best match to a fraction of a pixel; a match is valid when it is unique and the right eye's match of the pixel it lands on comes back to it.
type Estimate ¶
type Estimate struct {
// contains filtered or unexported fields
}
An Estimate is a picture's depth as the network (and the refinement) give it, at their size: Estimate's work, on the depth model's backend, the pictures one after the other; Shape's, on the CPU, may run beside the next picture's Estimate.
type Filler ¶ added in v0.21.0
type Filler struct {
// contains filtered or unexported fields
}
Filler is the hole filler ready to run on a backend: its weights uploaded once.
func NewFiller ¶ added in v0.21.0
func NewFiller(w *InpaintWeights) *Filler
NewFiller is a filler with weights.
func (*Filler) Fill ¶ added in v0.21.0
Fill corrects the holes of an eye's rows [top, bottom) on be: the filler run on the eye and its holes (Render's), its corrections taken in the holes. On a GPU the caller releases the pass's memory (nn.GPU.Release) after; the weights stay.
type Guide ¶
type Guide struct {
// Radius is the window's radius in pixels of the picture; zero turns
// the filter off.
Radius int
// Eps is the regularisation, in luma units squared (the picture's luma
// spread over 0..1, its 1st to 99th percentile): the larger, the less
// the depth follows the picture's finer variations.
Eps float64
}
Guide is the guided filter's settings.
type InpaintWeights ¶ added in v0.21.0
InpaintWeights is the filler's weights, each layer's as RefineWeights'.
func DecodeInpaint ¶ added in v0.21.0
func DecodeInpaint(r io.Reader) (*InpaintWeights, error)
DecodeInpaint reads the filler's weights from r.
func ReadInpaint ¶ added in v0.21.0
func ReadInpaint(path string) (*InpaintWeights, error)
ReadInpaint reads the filler's weights (as WriteTo writes them).
type Pending ¶
type Pending struct {
// contains filtered or unexported fields
}
Pending is an Estimate under way (Start's): Wait gives it.
type RefineLayer ¶
type RefineLayer struct {
Name string
In, Out int
Stride int // a convolution's: 1 or 2
Up bool // a 2x2 transposed convolution (an upsampling)
Kernel int // a convolution's: 3
Residual bool // the last: no ReLU
}
RefineLayer is one of the refinement's layers.
type RefineWeights ¶
RefineWeights is the refinement's weights: each layer's (a convolution's [Out, In, k, k], a transposed one's [In, Out, 2, 2]) and its bias.
func BuiltinRefine ¶
func BuiltinRefine() *RefineWeights
BuiltinRefine is the built-in refinement weights.
func DecodeRefine ¶
func DecodeRefine(r io.Reader) (*RefineWeights, error)
DecodeRefine reads refinement weights from r.
func ReadRefine ¶
func ReadRefine(path string) (*RefineWeights, error)
ReadRefine reads refinement weights (as WriteTo writes them).
type Samples ¶
type Samples struct {
Left, Right []float32 // the strips, a row's after the other's
Low []float32 // the lower half's
}
Samples is what of a picture's disparity the floating window and the subtitles read: its side strips (sampleEdge wide) on every other active row, and every fourth row and column of its lower half. A GPU downloads these and not the whole of it.
type Shape ¶
type Shape struct {
// Budget is the disparity across the depth's range (its 5th to 95th
// percentile; what lies beyond goes up to a quarter of it farther), as
// a fraction of the picture's width.
Budget float64
// Screen is where the screen sits in the depth range, 0 the farthest
// and 1 the nearest: what is nearer comes out of it, what is farther
// goes behind.
Screen float64
// Scale, when not zero, maps the network's depth to disparity as it
// is, not normalised a picture at a time: Scale times the depth plus
// Offset, as fractions of the width (Budget and Screen unused).
Scale, Offset float64
// Far, when not zero, is the farthest behind the screen anything may
// go, a fraction of the width: what goes past FarKnee of it is eased
// towards it, never reaching it (FarLimit).
Far float64
// Curve, when not zero or one, bends the depth within the shot's
// range (its 5th to 95th percentile, steadied over the shot as
// Budget's is), with Scale: the nearness n of a point in it (0 the
// farthest, 1 the nearest) becomes n to the power Curve (Curved), the
// ends staying. Below 1 what is between comes forward, towards the
// nearest, as the rows of a crowd a network stacks away behind each
// other; above 1 it goes back.
Curve float64
}
Shape is how depth becomes disparity.
type Shaper ¶
type Shaper struct {
Shape Shape
// contains filtered or unexported fields
}
Shaper turns a stream's depth maps into disparity: each map's range (its 5th to 95th percentile) normalised to 0..1 (what lies beyond kept to a quarter of the range more), the range steadied over the frames of a shot, then the shape's budget and screen applied.
func (*Shaper) CurveArgs ¶ added in v0.21.0
CurveArgs is the shape's curve as the disparity kernels take it: the shot's range (its farthest and its span, in the depth's units) and the power; the power 0 when the shape does not bend the depth, or the shot's range is not known yet.
func (*Shaper) Disparity ¶
Disparity is the disparity of a depth map (larger nearer, as the depth network gives it), in pixels of a picture width wide.
func (*Shaper) Range ¶ added in v0.21.0
Range is the shot's range so far, lo to hi (Steady's), and whether there is one.