Skip to content

Discrete cosine transform

Express a signal using cosine basis functions with an implicit even boundary extension.

Try it on your image ↓

VISUAL WALKTHROUGHSignal
REFERENCE INPUTSpatial samples

A smooth component and a rapid component are mixed together.

RESULTReconstruct a smoother signal

The inverse cosine transform of the retained coefficients preserves broad variation and loses fine oscillation.

STEP 03 / 03

Reconstruct with the inverse cosine transform.

Computed 64-sample teaching example, separate from the native OpenCV runtime.

Try it on an image

YOUR IMAGE · REAL OPENCV

Experiment at pixel level

Open full lab ↗

Compute the grayscale cosine transform after padding to even dimensions. Preview shows log absolute coefficients, DC at the upper left.

The engine loads on your first run. Your images stay in this browser.

Input448 × 320
OutputWaiting for a result

Scroll over either image to zoom at the pointer. Use the scrollbars to pan both views over the same relative area. Zoom is relative to the input; pixel coordinates belong to each image. Warps can change scene correspondence.

Pixel inspector RGBA · native values · matched scale · 9 × 9 output pixels
Hover to inspect. Click to pin a pixel.
Input
Select a pixel

Output
Select a pixel

Sample models and licenses

When to use it

Compact smooth image content into a small set of coefficients or study block compression.

How it works

  1. 01Project samples onto cosine basis functions.
  2. 02Retain or modify selected frequency coefficients.
  3. 03Reconstruct with the inverse cosine transform.

samples ↔ weighted cosine basis functions

What to tune

DFT_INVERSE selects reconstruction in dct; check supported dimensions and floating-point depth.

Where it breaks down

Removing high frequencies loses detail; independent block processing can introduce visible block boundaries.

TypeScript API

Open an entry for its exact overloads, parameter descriptions, result ownership and pinned upstream source.

All of these calls execute on the CPU. Native objects need explicit disposal. See matrices and ownership and build compatibility.