Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

A discrete cosine transform (DCT) expresses a finite sequence of real-valued samples as a set of weighted cosine patterns. Each output coefficient indicates how much a particular cosine basis pattern contributes to the input. In technical work, specify the DCT type and normalization: those choices affect the formula, coefficient values, and reconstruction.

What does DCT mean?

DCT stands for discrete cosine transform. It is a transform that maps a finite sequence of real samples into coefficients in a cosine basis. You can interpret the original samples as a weighted sum of cosine patterns at different frequencies.

The transform does not produce one universal set of coefficients for a given input. Several DCT definitions use different cosine sampling and endpoint conventions, and normalization choices can rescale the results.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What are the DCT types?

DCT-I, DCT-II, DCT-III, and DCT-IV are distinct transforms. Their formulas differ in how the cosine patterns are indexed and sampled. SciPy documents these four types in its dct function reference; the broader theory describes eight types.

  • DCT-I: Uses endpoint samples and a denominator of N−1. In SciPy, the input length must be greater than one.
  • DCT-II: Uses half-sample offsets in the input indexing. It is the type most commonly meant by “the DCT.”
  • DCT-III: Uses a different cosine indexing pattern from type II and is commonly used as its inverse.
  • DCT-IV: Uses half-sample offsets for both index factors.

For that reason, a technical statement or software call that says only “DCT” may be ambiguous. Name the type when the precise coefficients or reconstruction matter.

What does the DCT-II formula calculate?

For a length-N sequence x[n], SciPy defines its unnormalized type-II transform as:

y[k] = 2 Σn=0N−1 x[n] cos(π(2n+1)k/(2N)), for 0 ≤ k < N.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Here, n indexes the input samples and k indexes the output coefficients. Each coefficient is a weighted sum of the input values against one cosine pattern; the half-sample offset appears in the term 2n+1. This is the unnormalized type-II definition, not a convention shared by every library or every DCT type. The SciPy FFT tutorial provides formulas and orthonormal-scaling context for common DCT types.

How are DCT-II and DCT-III related?

Type III is commonly the inverse transform for type II, but the scaling depends on the convention. In SciPy’s unnormalized convention, DCT-III reverses DCT-II up to a factor of 2N. With orthonormal scaling, type III is exactly the inverse of type II.

Do not assume that a forward transform and inverse call from different libraries use matching coefficients or scaling. Check both the type and normalization documented by each implementation.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Why does normalization change DCT coefficients?

Normalization determines where scaling factors are applied. It changes coefficient magnitudes and, when paired with the corresponding inverse convention, supports reconstruction of the input. SciPy’s scipy.fft.dct supports norm="backward", norm="forward", and norm="ortho", plus an orthogonalize option.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Backward: Leaves the forward DCT unscaled and applies 1/N scaling to the inverse, using the logical transform size.
  • Forward: Applies the 1/N factor to the forward transform instead.
  • Ortho: Applies scaling intended to make the transform orthonormal. For types I–III, SciPy’s default orthogonalization further adjusts the formula to make the coefficient matrix orthonormal.

These are SciPy API conventions, not universal defaults. When comparing values or documenting a result, state the type, normalization, and orthogonalization setting.

How do you calculate a DCT in Python with SciPy?

SciPy documents the function as scipy.fft.dct(x, type=2, norm=...). It defaults to type II and transforms along the last axis unless you specify another axis. You can also provide an optional transform length.

For reproducibility, record the SciPy version along with the type, normalization, orthogonalization setting, and any axis or length choices that affect the operation. The cited API reference reports SciPy v1.18.0; defaults and available options should be checked against the version used in a project.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.