Skip to main content
Glama

auto_stretch

Apply PixInsight's auto-stretch to a view, using STF-based clipping and midtones balance to enhance faint details. Adjusts per-channel or linked RGB with configurable target background and shadows clipping.

Instructions

Stretch a view in place with PixInsight's auto-stretch (the ScreenTransferFunction Auto Stretch computation), applied as a HistogramTransformation. Per channel, sigma = 1.4826 × MAD (the median absolute deviation from the median). A channel whose median is below 0.5 gets shadows clipping c0 = median + shadows_clipping × sigma, clamped to [0,1] (0 when sigma is 0), and midtones balance m = MTF(target_bg, median − c0), where MTF(m, x) = (m − 1)·x / ((2m − 1)·x − m); a channel whose median is above 0.5 is treated as inverted: highlights clipping c1 = median − shadows_clipping × sigma (1 when sigma is 0) and m = MTF(c1 − median, target_bg). linked: one transform for R, G and B, with c0 (or c1) the mean over channels of the per-channel clipping points (a channel with sigma 0 adds 0, or 1 for c1) and the mean median in place of the median; the image is treated as inverted only when every channel median is above 0.5. The defaults of shadows_clipping, target_bg and linked are PixInsight's auto-stretch defaults. Fails, changing nothing, when the clipping point leaves no range for a midtones balance.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
linkedNoColour images: true computes one transform for R, G and B; false computes one per channel. Ignored for mono images
view_idYesView ID to stretch
target_bgNoTarget background level, strictly between 0 and 1
shadows_clippingNoClipping point relative to the median, in units of sigma = 1.4826 × MAD

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.2.1

TDQS

A4.6/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the full burden and does so thoroughly. It discloses the exact formula (sigma = 1.4826 × MAD), per-channel vs linked behavior, inversion handling, clamping behavior, defaults, and failure mode ('Fails, changing nothing, when the clipping point leaves no range'). This is exemplary behavioral disclosure.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is dense and information-rich, with every sentence contributing algorithmic detail. It is front-loaded with the main action and then details the math. It is longer than ideal, but the complexity of the algorithm justifies the length. No wasted words, though the MTF formula could be seen as heavy for a tool description.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (4 params, no output schema, no annotations), the description is remarkably complete. It covers the algorithm, parameter semantics, edge cases (sigma 0, inverted channels, linked mode), defaults, and failure behavior. An agent has everything needed to invoke it correctly and predict outcomes.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so the baseline is 3. The description adds significant meaning beyond the schema: it explains how shadows_clipping and target_bg are used in the MTF formula, how linked affects the computation, and the exact role of each parameter. It doesn't explicitly restate each parameter's type/default, but the schema already covers that. The added algorithmic context elevates it above baseline.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states a specific verb ('Stretch a view in place') and resource (PixInsight's auto-stretch via ScreenTransferFunction/HistogramTransformation), and distinguishes it from generic stretch tools by specifying the exact algorithm. It clearly identifies what the tool does and how it differs from siblings like robust_median_stretch or stretch_stars.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description explains the algorithm and defaults, and the schema notes 'linked' is ignored for mono images. It does not explicitly state when to use this tool versus alternatives like robust_median_stretch or stretch_stars, but the detailed algorithm description implies its use case (PixInsight auto-stretch). Clear context is provided, but no explicit exclusions or alternative routing.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.