views:

458

answers:

3

I have a bitmap image context and want to let this appear blurry. So best thing I can think of is a gauss algorithm, but I have no big idea about how this kind of gauss blur algorithms look like? Do you know good tutorials or examples on this? The language does not matter so much, if it's done all by hand without using language-specific API too much. I.e. in cocoa the lucky guys don't need to think about it, they just use a Imagefilter that's already there. But I don't have something like this in cocoa-touch (objective-c, iPhone OS).

+2  A: 

The Wikipedia article has a sample matrix in addition to some standard information on the subject.

aib
Is there a way of porting this 7*7 matrix into the 4*4 matrix of cocoa-touch CALayer transform matrix?
HelloMoon
No. A transform matrix is for doing coordinate transformations (translate, rotate, etc). It has no relation to a convolution matrix (used to mix pixel values together).
Liudvikas Bukys
+2  A: 

Best place for image processing is THIS. You can get matlab codes there.
And this Wolfram demo should clear any doubts about doing it by hand.

And if you don't want to learn too many things learn PIL(Python Imaging Library).

"Here" is exactly what you need.

Code copied from above link:

import ImageFilter

def filterBlur(im):

    im1 = im.filter(ImageFilter.BLUR)

    im1.save("BLUR" + ext)

filterBlur(im1)
TheMachineCharmer
does the PIL really run on the iPhone? (I don't have an iPhone, I'm just curious)
nikie
I don't know. I don't have iPhone either. :-D
TheMachineCharmer
iPhone is objective-c. I'm not sure about that python stuff, but i'd say no it doesn't run there. Correct me if I'm wrong.
HelloMoon
+4  A: 

This is actually quite simple. You have a filter pattern (also known as filter kernel) - a (small) rectangular array with coefficients - and just calculate the convolution of the image and the pattern.

for y = 1 to ImageHeight
  for x = 1 to ImageWidth
    newValue = 0
    for j = 1 to PatternHeight
      for i = 1 to PatternWidth
        newValue += OldImage[x-PatternWidth/2+i,y-PatternHeight/2+j] * Pattern[i,j]
    NewImage[x,y] = newValue

The pattern is just a Gauss curve in two dimensions or any other filter pattern you like. You have to take care at the edges of the image because the filter pattern will be partialy outside of the image. You can just assume that this pixels are balck, or use a mirrored version of the image, or what ever seems reasonable.

As a final note, there are faster ways to calculate a convolution using Fourier transforms but this simple version should be sufficent for a first test.

Daniel Brückner