Qu

image.scharr

Builtin index · Images

result = image.scharr(img, [direction="both"])

Input: img, direction · Output: result

What it is

Same signature, same direction= convention, and the same border/luma handling as image.sobel, but with the Scharr 3x3 kernel ([-3,0,3; -10,0,10; -3,0,3], transposed for the y-direction) in place of Sobel's — better rotational symmetry, the textbook reason to reach for it when the gradient's DIRECTION matters and not only where an edge is.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = image.scharr(img, [direction="both"])
img —not documented yet
direction optional (default "both")Same signature, same direction= convention, and the same border/luma handling as image.sobel, but with the Scharr 3x3 kernel ([-3,0,3.
result Mat
Returns a Mat. Added in v0.4.0.

Examples

No documentation example calls this form yet. The Images chapter is where one belongs.

How it works

sobel(img, [direction="both"]) / scharr(img, [direction="both"]) -- gradient over the image's BT.601 luma. direction="x"/"y" return the raw (signed) component Mat; the default "both" returns the gradient MAGNITUDE sqrt(gx^2 + gy^2) (see gradient_magnitude below for the same thing under its own name), which is the reading docs/design/toolkit-image.md's edges(canny | sobel | scharr) line implies for a plain sobel(img) call with no direction named. Scharr uses the same shape with the rotationally-more-symmetric 3x3 Scharr kernel in place of Sobel's. Raw floats, not an 8-bit preview image -- same reasoning as image::luma: a caller that wants a displayable edge map already has canny/edge_detect, and clamping here would throw away the sign and the exact magnitude a hand-computed test needs to check against. Named direction=, not axis=: axis= is a reserved keyword the call machinery itself intercepts (it powers the sum(M, axis=0)-style row/column reductions -- see AXIS_HONOURING/ALWAYS_ACCEPTED_KEYS), stripping it out of style into a separate numeric-only channel BEFORE any builtin dispatch ever runs, this one included. A sobel axis= kwarg would silently never reach this match arm at all -- found by a real failing test here, not by inspection: axis="y" returned the SAME magnitude axis="both" did, because style_str(style, "axis") was reading a key that had already been removed.

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.