uiimage-dsp icon indicating copy to clipboard operation
uiimage-dsp copied to clipboard

Gaussian Blur give images a black border on left and right side

Open nilsou opened this issue 13 years ago • 5 comments

When applying a gaussian blurr to images, the returned image has two black bands on each side.

This must have something to do with difficulty to apply the filter at the edge of the image but I don't really know how to deal with it...

Any idea?

nilsou avatar Jul 23 '12 19:07 nilsou

Oops just saw that there is another issue about that...

However, is there a way to have edge pixels averaged with transparent ones. instead of black ones?

nilsou avatar Jul 23 '12 19:07 nilsou

Yeah on the edges you end up with the average calculation being low because of the "missing" pixels off each side.

I get around this in one of my apps by cropping and slightly resizing the picture, it's been a while since I looked at this code in depth but I'll open it up and have a think about whether that could be done, might make for better results!

gdawg avatar Jul 24 '12 13:07 gdawg

It should be optional for the core convolution engine, as there's no "right" answer, for example:

  1. you might want zero pixels at the edges
  2. or you might want to only process the pixels that are fully covered by the matrix (ignore those that slip off the edge.)
  3. or you might want to wrap around,
  4. or you might want to duplicate the edge pixels to provide cover for the real edge pixels.

... those are the usual strategies off the top of my head.

jasonm23 avatar Dec 10 '12 09:12 jasonm23

Sorry I've been so slow getting back to this,

based on the way the Accelerate.Framework works I'm thinking the best option would be to duplicate the edge pixels prior to the convolution call then crop the resulting image back down to the original size.

I think anything else would result in extra vDSP calls (and associated data-type) shuffling which is a bit cumbersome, compilcated (and slow!)

I haven't been active on this in quite a while but might have cause to look into it again in the next few weeks.

TBC...

gdawg avatar Jan 30 '13 00:01 gdawg

This stills actual problem...

k06a avatar Aug 20 '13 19:08 k06a

This is still an actual problem

beatboxerish avatar Mar 14 '23 11:03 beatboxerish

Sorry this library is essentially abandoned at this point and I wouldn't recommend using it in new projects.

Apple's Core Image library provides similar functionality and be my choice if I were to look into this in 2023.

If for some reason you're stuck with this library it's worth noting (as @jasonm23 does above) that there is no one true correct solution to this problem. The algorithm combines each pixel with weighted values from it's neighbours therefore at the edges (where some neighbours are missing) it's simply not possible to calculate the correct value due to missing inputs.

Some workarounds you might want to consider are:

  • cropping the result
  • expanding the image, projecting the edge pixels outwards then cropping the result back to the original size

gdawg avatar Mar 18 '23 18:03 gdawg