gdawg / uiimage-dsp

IOS UIImage processing functions using the vDSP/Accellerate framework for speed.

Home Page:http://mad-dog-software.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

nilsou opened this issue · 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?

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?

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!

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.

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...

This stills actual problem...

This is still an actual problem

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