> [Site index](https://perfectvector.com/llms.txt) — available pages and descriptions.

# Increase SVG Contrast With feComponentTransfer

> Use feComponentTransfer to increase SVG contrast around mid-gray. Calculate the slope and intercept, set sRGB, and check opacity with five measured swatches.

Source: https://perfectvector.com/blog/svg-fecomponenttransfer-contrast

Language: en
Author: Irene Kim
Published: 2026-11-26T08:00:00+09:00

To increase SVG contrast with `feComponentTransfer`, set the same linear slope above 1 on red, green, and blue. Use an intercept of `(1 - slope) / 2` to keep the midpoint at half-scale. Start with `slope="1.5"` and `intercept="-0.25"`, set `color-interpolation-filters="sRGB"`, and omit `feFuncA` to preserve input opacity. [W3C Filter Effects specification](https://www.w3.org/TR/filter-effects-1/#feComponentTransferElement)

## Calculate the intercept for the gray you want to keep

The [Filter Effects specification](https://www.w3.org/TR/filter-effects-1/#transfer-function-element-attributes) defines the linear transfer as `output = slope × input + intercept`, with channel values on a scale from 0 to 1. A pivot is the input value that should come out unchanged. Substituting the pivot for both input and output gives `intercept = pivot × (1 - slope)`.

With a pivot of 0.5 and a slope of 1.5, the intercept is −0.25. An input of 0.25 becomes 0.125, 0.5 stays at 0.5, and 0.75 becomes 0.875. A slope of 1 and intercept of 0 leave the channel alone. A slope between 0 and 1 draws values toward the pivot.

The calculation happens in the filter's color space. SVG filter primitives start in `linearRGB`, so the tutorial sets `color-interpolation-filters="sRGB"` to work with the channel values of ordinary hex swatches. The pivot is an sRGB channel value in this example. [W3C color-interpolation-filters property](https://www.w3.org/TR/filter-effects-1/#propdef-color-interpolation-filters)

The renderer clamps each output channel to the valid range. At these settings, any input at or below 1/6 maps to 0 and any at or above 5/6 maps to 1. If two shades merge at either end, try a smaller slope and recalculate the intercept. On colored artwork, an individual channel can clip before the others, so also inspect colors you need to preserve. [W3C filter primitive overview](https://www.w3.org/TR/filter-effects-1/#FilterPrimitivesOverview)

## Compare two copies of the same swatches

Save the sample as `swatches.svg` in a text editor. The first copy uses the original fills. The second applies the filter to a group containing the same artwork. For your own artwork, place the relevant elements in a group and put the filter reference on that group. [W3C SVG grouping](https://www.w3.org/TR/SVG2/struct.html#Groups)

```svg
<svg xmlns="http://www.w3.org/2000/svg" width="600" height="460"
     viewBox="0 0 600 460">
  <defs>
    <filter id="contrast" color-interpolation-filters="sRGB">
      <feComponentTransfer in="SourceGraphic">
        <feFuncR type="linear" slope="1.5" intercept="-0.25"/>
        <feFuncG type="linear" slope="1.5" intercept="-0.25"/>
        <feFuncB type="linear" slope="1.5" intercept="-0.25"/>
      </feComponentTransfer>
    </filter>
    <g id="swatches">
      <rect x="20" y="20" width="104" height="105" fill="#202020"/>
      <rect x="134" y="20" width="104" height="105" fill="#505050"/>
      <rect x="248" y="20" width="104" height="105" fill="#808080"/>
      <rect x="362" y="20" width="104" height="105" fill="#b0b0b0"/>
      <rect x="476" y="20" width="104" height="105" fill="#e0e0e0"/>
      <rect x="248" y="151" width="104" height="60" fill="#808080"
            fill-opacity="0.5"/>
    </g>
  </defs>
  <use href="#swatches"/>
  <g transform="translate(0 230)" filter="url(#contrast)">
    <use href="#swatches"/>
  </g>
</svg>
```

We rendered the sample to a transparent PNG in [resvg](https://github.com/linebender/resvg) 0.47.0 and sampled each swatch at its center. The five opaque grays measured **32, 80, 128, 176, 224** before filtering and **0, 56, 128, 200, 255** after. The smaller, half-opacity swatch had an alpha value of **128 out of 255 in both renders**. These are 8-bit measurements from this renderer. The opaque mid-gray stayed at 128. The translucent swatch came out at RGB 126 instead of 128, with the same alpha.

![Five gray swatches spread toward black and white after the sRGB filter, while the center gray and the lower swatch's measured alpha stay the same](https://perfectvector.com/blog/svg-fecomponenttransfer-contrast/workflow-proof.webp)

*Center samples from the same SVG in resvg 0.47.0. The top row in each panel is opaque. The smaller rectangle separately checks 50% source opacity.*

## Check the filter in your destination

1. Open the saved SVG in the renderer you use to deliver the artwork, then compare the two solid strips.
2. Check for darker shadows, lighter highlights, and a middle gray close to its original appearance.
3. View the partial-opacity swatch over both a light and a dark background. Repeat that check on any translucent edges in your own artwork.

If both strips still look identical, check that the group's `filter="url(#contrast)"` matches the filter ID and that the destination renders SVG filters. If the dark and light ends change but the middle gray shifts, confirm `sRGB` is set and the same intercept is on all three color channels. If your destination needs newly editable colors on the paths, edit their source paints. The [SVG feColorMatrix guide](https://perfectvector.com/blog/svg-fecolormatrix) shows how to distinguish a rendered effect from a fill edit.

## Start with editable source artwork

PerfectVector can turn a flat raster logo or icon into editable SVG paths when the original vector is unavailable. Apply the filter to the SVG master if you have it. To cut out faint pixels by opacity, use an [SVG alpha threshold](https://perfectvector.com/blog/svg-alpha-threshold) instead.

[Vectorize the source image](https://perfectvector.com/image-to-vector), then open the SVG and inspect the smallest shape you need to keep before applying the contrast filter to a copy.

## FAQ

### What slope and intercept increase SVG contrast?

Use a slope above 1 on all three color channels. To keep 0.5 fixed, set the intercept to (1 − slope) / 2. For a slope of 1.5, the intercept is −0.25.

### How do I keep transparency when increasing SVG contrast?

Omit feFuncA or set it to identity. That preserves input alpha. Apply the linear transfer to red, green, and blue, and test a partially transparent edge or swatch in your destination.

### Why did my SVG contrast filter shift mid-gray?

Check the filter's working space and intercept. Half-scale in linearRGB is a different displayed gray than half-scale in sRGB. Set color-interpolation-filters to sRGB if the pivot comes from an sRGB swatch.

## Sources

1. [W3C — Filter Effects Module Level 1](https://www.w3.org/TR/filter-effects-1/) — Defines the linear transfer, identity for missing channels, output clamping, and filter color space.
2. [W3C — SVG 2 grouping](https://www.w3.org/TR/SVG2/struct.html#Groups) — Defines the group that holds the artwork and carries the filter reference.
3. [Linebender — resvg](https://github.com/linebender/resvg) — Documents the SVG renderer used for the swatch comparison.

## Explore

- [Read the HTML article](https://perfectvector.com/blog/svg-fecomponenttransfer-contrast)
- [SVG Grain Texture: Keep Noise Inside Your Artwork](https://perfectvector.com/blog/svg-feturbulence-grain.md)
- [SVG feComposite: Compare in, out and xor Artwork](https://perfectvector.com/blog/svg-composite-artwork.md)
- [Product facts](https://perfectvector.com/product-facts.md)
- [FAQ](https://perfectvector.com/faq.md)
- [Pricing and credits](https://perfectvector.com/pricing.md)
