libvips / libvips

A fast image processing library with low memory needs.

Home Page:https://libvips.github.io/libvips/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pyvips - Gaussian Blur has black outline around image

sairam-haribabu opened this issue · comments

When performing gaussian blur with the setting below, the output image has a weird black outline around it.

image = image.gaussblur(sigma, min_ampl=0.1, precision="float")
Source image:
cathub-resized

Output (sigma = 10)
cathub-blur-r-30

I'm trying to find a fix for the black outline around the image. Hoping to see some output like this:

9MB-Cathub-magick-gaussian-blur-1

Environment
(please complete the following information)

  • OS: MacOS 13.6
  • Vips: 8.15

PS: Issue observed best using the browser's light mode

TIA!

Hello @sairam-haribabu,

That's the edge of the image being blended into your PNG background, which is black. Try dropping the alpha:

vips extract_band whipped.png x.png 0 --n 3

ie. starting from band 0, extract three bands (bands are always RGBA) to make:

x

You can see your image is really on a black background, it's only the transparent alpha which makes it seem white. When you blur it, you are seeing these black pixels.

To fix this, flatten out the alpha against white to set the background pixels, reattach the alpha, then blur.

fixed_rgba = image.flatten(background=255).bandjoin(image[3])
image = fixed_rgba.gaussblur(5)

To make:

x

You'll find it looks correct on a white and on a black background.