Qu

imadjust

Builtin index · Images

result = imadjust(img, [in_low=], [in_high=], [out_low=0.0], [out_high=1.0], [gamma=1.0])

Input: img, in_low, in_high, out_low, out_high, gamma · Output: result

What it is

img is an Image. in_low/in_high are optional named numbers in [0,1], the input intensity range to stretch from; when both are omitted they auto-default to the image's own 1st/99th percentile (all channel bytes pooled) — robust to outlier pixels, like MATLAB's stretchlim. out_low/out_high are optional named numbers in [0,1] (default 0.0/1.0), the output range to stretch to. gamma is an optional named number (default 1.0) applying a power-law curve after the linear stretch. MATLAB-style contrast stretch, applied identically and independently to each of R/G/B.

Overloads

2 forms. Each carries its own inputs, outputs and worked example — pick the tab for the one you are calling.

CodeInputOutputDescription
result = imadjust(img, [in_low=], [in_high=], [out_low=0.0], [out_high=1.0], [gamma=1.0])
img Imageimg is an Image.
in_low number, optionalin_low/in_high given explicitly.
in_high number, optionalin_low/in_high given explicitly.
out_low number, optional (default 0.0)The stretch maps exactly that input range to out_low..out_high linearly — passing the image's own full byte range (in_low=0.0, in_high=1.0) is a no-op that leaves a low-contrast image just as flat as it started.
out_high number, optional (default 1.0)The stretch maps exactly that input range to out_low..out_high linearly — passing the image's own full byte range (in_low=0.0, in_high=1.0) is a no-op that leaves a low-contrast image just as flat as it started.
gamma number, optional (default 1.0)gamma is an optional named number (default 1.0) applying a power-law curve after the linear stretch.
result Image
—

Examples

Written for this form and run by the build -- the output below is what the engine actually produced.

m = [40, 42, 41, 43; 44, 40, 250, 41]
img = image_from_matrix(m)
fixed = imadjust(img, in_low=0.0, in_high=1.0)
print(imhist(fixed, n_bins=8))   # [0, 7, 0, 0, 0, 0, 0, 1] -- unchanged, still clustered in one bin

output
[0, 7, 0, 0, 0, 0, 0, 1]
CodeInputOutputDescription
result = imadjust(img, [in_low=], [in_high=], [out_low=0.0], [out_high=1.0], [gamma=1.0])
img Imageimg is an Image.
in_low number, optionalWhen both in_low and in_high are left out, they default to the image's own 1st/99th percentile of pooled channel bytes rather than 0.0/1.0 — a robust, data-driven stretch (MATLAB's stretchlim), not a no-op.
in_high number, optionalWhen both in_low and in_high are left out, they default to the image's own 1st/99th percentile of pooled channel bytes rather than 0.0/1.0 — a robust, data-driven stretch (MATLAB's stretchlim), not a no-op.
out_low number, optional (default 0.0)out_low/out_high are optional named numbers in [0,1] (default 0.0/1.0), the output range to stretch to.
out_high number, optional (default 1.0)out_low/out_high are optional named numbers in [0,1] (default 0.0/1.0), the output range to stretch to.
gamma number, optional (default 1.0)gamma is an optional named number (default 1.0) applying a power-law curve after the linear stretch.
result Image
The exact same source image that stayed flat above spreads across the full range once the percentile-based stretch kicks in.

Examples

Written for this form and run by the build -- the output below is what the engine actually produced.

m = [40, 42, 41, 43; 44, 40, 250, 41]
img = image_from_matrix(m)
auto = imadjust(img)
print(imhist(auto, n_bins=8))   # [7, 0, 0, 0, 0, 0, 0, 1] -- stretched out to both ends of the range

output
[7, 0, 0, 0, 0, 0, 0, 1]

How it works

imadjust(img, [in_low=, in_high=, out_low=0.0, out_high=1.0], [gamma=1.0]) — MATLAB-style contrast stretch, applied identically and independently to each of R/G/B (see image::Image::adjust's doc comment for why NOT luma-based). When BOTH in_low/in_high are omitted, they auto-default to the image's own 1st/99th percentile (all channel bytes pooled — see percentile_range's doc comment for that simplification), robust to a few outlier pixels the way MATLAB's own stretchlim auto-range is, rather than the literal (outlier-sensitive) min/max.

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