RunMat
  • Pricing
RunMat
GitHub
GitHub
Sign inTry in browser
DesktopRuntimePhysicsCADAdministrationAgent

Get RunMat updates

New releases, guides and examples.

Product+
  • Runtime
  • GPU
  • Parallel
  • Compile
  • Interop and MEX
  • Simulation
  • MCAD
  • ECAD
  • Enterprise
  • AI integrations
  • Pricing
  • Download
Math+
  • Signal processing
  • Linear algebra
  • Statistics
  • Curve fitting
  • Differential equations
  • Control systems
  • Optimization
  • Finance
  • Data and tables
  • Plotting
Physics+
  • Simulation overview
  • Structural
  • Thermal
  • Electromagnetic
  • Joule heating
  • Thermal stress
  • Acoustics
  • Fluid flow
  • Conjugate heat transfer
  • Fluid–structure
  • What is FEA
Industries+
  • Aerospace
  • Automotive and transportation
  • Defense
  • Electronics and semiconductors
  • Energy
  • Industrial machinery
  • Life sciences
  • Quantitative finance
Learn+
  • Guides
  • Docs
  • Function reference
  • Language reference
  • Migration guide
  • Changelog
  • MATLAB Online
  • MATLAB AI agent
  • For students
Compare+
  • RunMat vs MATLAB
  • RunMat vs Ansys
  • RunMat vs SOLIDWORKS
  • RunMat vs Altium
  • RunMat vs Cadence
  • RunMat vs COMSOL
  • RunMat vs Python
  • RunMat vs Julia
  • RunMat vs Physics AI
  • RunMat vs Octave
  • Benchmarks
  • MATLAB alternatives
  • All comparisons
Company+
  • About
  • Blog
  • Contact
  • Source code↗
  • License
  • Privacy
  • Terms

Product

  • Runtime
  • GPU
  • Parallel
  • Compile
  • Interop and MEX
  • Simulation
  • MCAD
  • ECAD
  • Enterprise
  • AI integrations
  • Pricing
  • Download

Math

  • Signal processing
  • Linear algebra
  • Statistics
  • Curve fitting
  • Differential equations
  • Control systems
  • Optimization
  • Finance
  • Data and tables
  • Plotting

Physics

  • Simulation overview
  • Structural
  • Thermal
  • Electromagnetic
  • Joule heating
  • Thermal stress
  • Acoustics
  • Fluid flow
  • Conjugate heat transfer
  • Fluid–structure
  • What is FEA

Industries

  • Aerospace
  • Automotive and transportation
  • Defense
  • Electronics and semiconductors
  • Energy
  • Industrial machinery
  • Life sciences
  • Quantitative finance

Learn

  • Guides
  • Docs
  • Function reference
  • Language reference
  • Migration guide
  • Changelog
  • MATLAB Online
  • MATLAB AI agent
  • For students

Compare

  • RunMat vs MATLAB
  • RunMat vs Ansys
  • RunMat vs SOLIDWORKS
  • RunMat vs Altium
  • RunMat vs Cadence
  • RunMat vs COMSOL
  • RunMat vs Python
  • RunMat vs Julia
  • RunMat vs Physics AI
  • RunMat vs Octave
  • Benchmarks
  • MATLAB alternatives
  • All comparisons

Company

  • About
  • Blog
  • Contact
  • Source code↗
  • License
  • Privacy
  • Terms
GitHubXLinkedIn

© Dystr, Inc. · RunMat v0.7.1, Nov 17, 2026

RunMat® is a registered trademark of Dystr, Inc. MATLAB® is a registered trademark of The MathWorks, Inc. RunMat is not affiliated with, endorsed by, or sponsored by The MathWorks, Inc.

/
See all docs
Builtin Reference
    • imhist

imhist — Compute or display grayscale and indexed-image histograms.

imhist counts grayscale intensities or indexed-image colormap entries. Programmatic calls return double column vectors for counts and optional bin locations; host statement-form calls display a bar-chart histogram when presentation is available.

Syntax

imhist(I)
imhist(I, n)
imhist(X, map)
counts = imhist(I)
counts = imhist(I, n)
[counts, binLocations] = imhist(I)
All supported imhist forms
imhist(I)
imhist(I, n)
imhist(X, map)
counts = imhist(I)
counts = imhist(I, n)
[counts, binLocations] = imhist(I)
[counts, binLocations] = imhist(I, n)
counts = imhist(X, map)
[counts, binLocations] = imhist(X, map)

Inputs

I
Type
Any
Required
Yes
Description
Grayscale intensity image.
n
Type
NumericScalar
Required
Yes
Default
256
Description
Number of bins.
X
Type
Any
Required
Yes
Description
Indexed image matrix.
map
Type
NumericArray
Required
Yes
Description
Colormap with one RGB row per indexed-image bin.
NameTypeRequiredDefaultDescription
IAnyYes—Grayscale intensity image.
nNumericScalarYes256Number of bins.
XAnyYes—Indexed image matrix.
mapNumericArrayYes—Colormap with one RGB row per indexed-image bin.

Returns

counts
Type
NumericArray
Description
Histogram bin counts as a column vector.
binLocations
Type
NumericArray
Description
Intensity or colormap-index bin locations as a column vector.
NameTypeDescription
countsNumericArrayHistogram bin counts as a column vector.
binLocationsNumericArrayIntensity or colormap-index bin locations as a column vector.

Returned values from imhist depend on how many outputs the caller requests.

Errors

RunMat:imhist:InvalidArgument
When
Image input, bin count, or colormap arguments are malformed or unsupported.
Message
imhist: invalid argument
RunMat:imhist:UnsupportedImage
When
Input cannot be interpreted as a grayscale or indexed image.
Message
imhist: unsupported image input
RunMat:imhist:PlotFailed
When
Statement-form histogram rendering fails.
Message
imhist: plotting failed
IdentifierWhenMessage
RunMat:imhist:InvalidArgumentImage input, bin count, or colormap arguments are malformed or unsupported.imhist: invalid argument
RunMat:imhist:UnsupportedImageInput cannot be interpreted as a grayscale or indexed image.imhist: unsupported image input
RunMat:imhist:PlotFailedStatement-form histogram rendering fails.imhist: plotting failed
RunMat:imhist:TooManyOutputsMore than two outputs are requested.imhist: too many output arguments
RunMat:imhist:InternalInternal histogram assembly fails.imhist: internal error

Forms and bins

imhist(I) uses 256 bins for numeric grayscale data and two bins for logical data. imhist(I,n) uses a positive integer-valued scalar n up to one million bins. [counts,binLocations] returns the class-wide bin centers as a second double column vector.

imhist(X,map) counts indexed values into one bin per row of a nonempty double Nx3 RGB colormap. Each colormap component must be finite and in [0,1]. Floating indexed values use one-based indices; uint8, uint16, and logical indexed values use zero-based indices. Nonfinite, fractional, and out-of-range indices reject.

Floating grayscale images must be finite normalized single or double values in [0,1]. Grayscale int8, int16, int32, uint8, uint16, and uint32 use their full class ranges; int64 and uint64 image classes reject without lossy conversion. Counts and locations are double arrays.

Execution and compatibility

A native typed-integer scalar bin count is a RunMat-only extension. MATLAB-compatible mode accepts the documented positive integer-valued floating scalar form and rejects the extension before data access.

Grayscale gpuArray input is downloaded non-destructively through its owning provider, counted on the host, and programmatic outputs are restored to the same owner when supported. Unsupported automatic restoration may retain the host result; operational provider failures remain errors. Indexed gpuArray input is unsupported. Histogram assembly terminates fusion chains; there is no histogram provider kernel.

For host input, a zero-output statement call displays a bar chart when a graphics host is available; no-plot, headless, and non-main-thread presentation unavailability completes without a visible figure. Existing resident zero-output calls return host counts instead of plotting. That resident behavior remains distinct from programmatic restored outputs.

The computation is a host materialization boundary, not an arbitrary CPU fallback for an existing provider histogram kernel. Download, output upload, graphics presentation, suspension, and error ordering use their existing shared owners. Graphics figures are local state, not portable values for worker or foreign-runtime transfer.

Examples

Count intensities in a byte image

I = uint8([0 1 1; 2 2 2]);
[counts, bins] = imhist(I);
[peak, idx] = max(counts);
[bins(idx), peak]

Expected output:

ans =
     2     3

Use fewer bins for a normalized image

I = [0 0.25 0.5 1.0];
[counts, bins] = imhist(I, 3);
counts

Expected output:

ans =
     1
     2
     1

Histogram an indexed image

X = [1 2; 3 2];
map = [1 0 0; 0 1 0; 0 0 1];
[counts, bins] = imhist(X, map);
counts

Expected output:

ans =
     1
     2
     1

Display a histogram

I = uint8([0 64 128; 128 192 255]);
counts = imhist(I);
imhist(I);

Using imhist with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how imhist changes the result.

Run a small imhist example, explain the result, then change one input and compare the output.

FAQ

Why does imhist reject double values greater than 1?⌄

Floating grayscale images represent normalized intensities in [0,1]. Use uint8 or uint16 for byte or word intensities.

How are indexed image offsets handled?⌄

Double and single indexed images use one-based indices. uint8, uint16, and logical indexed images use zero-based indices.

Does statement-form imhist always render a plot?⌄

Host calls render when a graphics backend and presentation context are available. Headless/no-plot presentation unavailability completes without a visible figure; existing resident zero-output calls return host counts.

Related Image functions

Filters

filter2 · fspecial · imfilter

Color

gray2rgb · hsv2rgb · im2double · im2uint16 · im2uint8 · ind2rgb · lab2rgb · rgb2gray · rgb2hsv · rgb2lab

Io

imfinfo · imread · imwrite

Source you can read

Every RunMat function's source is public. Read exactly how imhist is executed, line by line, in Rust.

  • View the source for imhist in Rust on GitHub
  • Learn how the RunMat runtime works
  • Found a bug? Open an issue with a minimal reproduction.

About RunMat

RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/license.

  • RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
  • Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.

Download RunMatOpen Sandbox
On this page
  • Syntax
  • Inputs
  • Returns
  • Errors
  • Forms and bins
  • Execution and compatibility
  • Examples
  • Count intensities in a byte image
  • Use fewer bins for a normalized image
  • Histogram an indexed image
  • Display a histogram
  • Using imhist with coding agents
  • FAQ
  • Related Image functions
  • Filters
  • Color
  • Io
  • Source you can read
  • About RunMat