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
    • filter2
    • fspecial
    • imfilter

fspecial — Generate standard two-dimensional image-filter kernels.

fspecial(type, ...) creates average, disk, Gaussian, Laplacian, Laplacian-of-Gaussian, motion, Prewitt, Sobel, and unsharp correlation kernels for imfilter, filter2, and conv2.

Syntax

H = fspecial(type)
H = fspecial(type, arg1)
H = fspecial(type, arg1, arg2)

Inputs

type
Type
StringScalar
Required
Yes
Description
Filter name: average, disk, gaussian, laplacian, log, motion, prewitt, sobel, or unsharp.
arg1
Type
Any
Required
No
Description
Filter-specific size, radius, alpha, or length.
arg1
Type
Any
Required
No
Description
First filter-specific parameter.
arg2
Type
Any
Required
No
Description
Second filter-specific parameter, such as sigma or motion angle.
NameTypeRequiredDefaultDescription
typeStringScalarYes—Filter name: average, disk, gaussian, laplacian, log, motion, prewitt, sobel, or unsharp.
arg1AnyNo—Filter-specific size, radius, alpha, or length.
arg1AnyNo—First filter-specific parameter.
arg2AnyNo—Second filter-specific parameter, such as sigma or motion angle.

Returns

H
Type
NumericArray
Description
Generated 2-D correlation kernel.
NameTypeDescription
HNumericArrayGenerated 2-D correlation kernel.

Errors

RunMat:fspecial:InvalidArgument
When
Filter name or argument count shape is invalid for the selected filter type.
Message
fspecial: invalid argument
RunMat:fspecial:InvalidInput
When
Filter parameters have invalid values or unsupported input types.
Message
fspecial: invalid input
RunMat:fspecial:Internal
When
Kernel generation or provider publication fails internally.
Message
fspecial: internal kernel generation failure
IdentifierWhenMessage
RunMat:fspecial:InvalidArgumentFilter name or argument count shape is invalid for the selected filter type.fspecial: invalid argument
RunMat:fspecial:InvalidInputFilter parameters have invalid values or unsupported input types.fspecial: invalid input
RunMat:fspecial:InternalKernel generation or provider publication fails internally.fspecial: internal kernel generation failure

Filter types and defaults

average and gaussian default to 3-by-3; log defaults to 5-by-5; disk defaults to radius 5 and an 11-by-11 footprint; motion defaults to length 9 and angle 0. Laplacian, Prewitt, Sobel, and unsharp are 3-by-3. Gaussian and LoG default sigma to 0.5; Laplacian alpha defaults to 0.2.

Average, Gaussian, and LoG sizes accept a positive scalar or a two-element [rows cols] vector. Disk uses a nonnegative radius; motion rounds a positive length and uses the next odd kernel width. Laplacian and unsharp accept alpha. Prewitt and Sobel accept no extra parameters.

Smoothing kernels are normalized, while derivative and sharpening kernels use their defined scaling. Invalid filter names, argument counts, dimensions, and parameter values have stable fspecial errors. RunMat-only unsharp and nondouble numeric controls require their extension gates.

Class and execution

The ordinary host result is a dense real double column-major tensor. Exact integer structural controls are decoded without binary64 rounding; integer computational parameters must be exactly representable in binary64. An ambient RUNMAT_ACCEL_FSPECIAL_DEVICE=1 request is separately extension-gated and may publish a resident provider-precision single or double kernel for supported forms (average, Gaussian, Laplacian, Prewitt, Sobel, unsharp). Disk, LoG, and motion remain host outputs.

A provider's explicit Unsupported result may use the already-computed host kernel. Operational provider failures retain their cause and never silently replay on host. Resident results must have the expected shape, real floating class, live allocation, and exact provider owner before publication. The operation is a fusion boundary; the ambient policy reads the environment and may throw.

Examples

Seven-by-seven box filter

H = fspecial('average',7); size(H)

Expected output:

ans = [7 7]

Rectangular Gaussian kernel

H = fspecial('gaussian',[5 7],1); size(H)

Expected output:

ans = [5 7]

Circular averaging kernel

H = fspecial('disk',4); size(H)

Expected output:

ans = [9 9]

Laplacian-of-Gaussian edge kernel

H = fspecial('log',[9 9],1.4); size(H)

Expected output:

ans = [9 9]

Thirty-degree motion blur

H = fspecial('motion',15,30); size(H)

Expected output:

ans = [15 15]

RunMat unsharp extension

H = fspecial('unsharp',0.6); size(H)

Expected output:

ans = [3 3]

Using fspecial with coding agents

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

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

FAQ

Can fspecial publish a gpuArray?⌄

The separately gated RUNMAT_ACCEL_FSPECIAL_DEVICE=1 mode can publish supported kernels through an active provider. Unsupported filters or providers return the host kernel; operational provider errors do not silently fall back.

How do I specify a size?⌄

Average, Gaussian, and LoG accept a scalar side length or [rows cols]. Other filters use their documented radius, length, or alpha parameter.

Which kernels are available?⌄

Average, disk, Gaussian, Laplacian, LoG, motion, Prewitt, Sobel, and the RunMat-gated unsharp extension are implemented.

Are the kernels normalized?⌄

Average, disk, Gaussian, and motion kernels sum to one. LoG and derivative kernels instead have their defined zero-sum or sharpening scaling.

What if a parameter is invalid?⌄

Invalid names, dimensions, types, and parameter ranges raise a stable fspecial invalid-argument or invalid-input error before publication.

Are results exactly the same as MATLAB?⌄

The documented forms and defaults follow MATLAB-compatible behavior, but floating-point results may vary with implementation and provider precision; this reference does not claim bitwise or release-specific identity.

Related Image functions

Filters

filter2 · imfilter

Color

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

Io

imfinfo · imread · imwrite

Image

imhist

Source you can read

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

  • View the source for fspecial 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
  • Filter types and defaults
  • Class and execution
  • Examples
  • Seven-by-seven box filter
  • Rectangular Gaussian kernel
  • Circular averaging kernel
  • Laplacian-of-Gaussian edge kernel
  • Thirty-degree motion blur
  • RunMat unsharp extension
  • Using fspecial with coding agents
  • FAQ
  • Related Image functions
  • Filters
  • Color
  • Io
  • Image
  • Source you can read
  • About RunMat