Question

When I apply a greyscale SVG filter to a dark image, I get significant banding in the results. The filter I am using is:

     <!doctype html>
     <html>
     <head>
     <style>
      img {
     filter: url(#grayscale); /* Firefox */     
     filter: gray; /* IE */
    -webkit-filter: grayscale(1); /* Webkit */
    }
      img:hover {
    filter: none;
    -webkit-filter: grayscale(0);
    }
       </style>
    </head>
  <body>
  <img src="http://www.walldoze.com/static/cache/2048x2048/hd-wallpapers-space-iphone-  wallpaper-retina-2048x2048-wallpaper.jpg" width="1000">
  <svg xmlns="http://www.w3.org/2000/svg">
 <filter id="grayscale" >
 <feColorMatrix type="matrix"  values="0.3333 0.3333 0.3333 0 0.001 0.3333 0.3333 0.3333 0 0.001 0.3333 0.3333 0.3333 0 0.001 0 0 0 1 0.001"/>
  </filter>
  </svg>
  </body>
  </html>

enter image description here

Was it helpful?

Solution

To get better performance, you can set the color-interpolation-filters attribute to "sRGB" on the filter property:

<filter id="greyscale" color-interpolation-filters="sRGB">
  <feColorMatrix type="saturate" values="0"/>
</filter>

color-interpolation-filters is not supported in Safari however, to the best of my knowledge

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top