[SciPy-User] Gaussian Filter
Matthieu Brucher
matthieu.brucher at gmail.com
Fri Sep 4 10:53:21 EDT 2009
I don't have OpenCV here, so I can't say for sure but, what is the
relative amplitude of the difference? OpenCV works on floats or
doubles? It may be due to a type difference or a small difference in
the algorithms.
Matthieu
2009/9/4 Brian Thorne <hardbyte at gmail.com>:
> Similar question, but now a bit harder. I have this code (pieced together
> from a few files) that does a gaussian filter on a single image in both
> OpenCV and in SciPy.
> It is now at a point where I cannot tell them apart with a visual
> inspection, but a imshow(image1 - image2) begs to differ. Is it going to be
> possible to get the exact same output?
>
>
> from opencv import cv
> from opencv import adaptors
> from __future__ import division
> import numpy as np
> from numpy import array, uint8
> from scipy import signal, ndimage
> @scipyFromOpenCV
> def gaussianBlur(np_image):
> """Blur an image with scipy"""
> sigma = opencvFilt2sigma(43.0)
>
> result = ndimage.filters.gaussian_filter(np_image,
> sigma=(sigma, sigma, 0),
> order=0,
> mode='reflect'
> )
> return result
> def gaussianBlur(image, filterSize=43, sigma=opencvFilt2sigma(43)):
> """Blur an image with a particular strength filter.
> Default is 43, 139 gives a very strong blur, but takes a while
> """
>
> # Carry out the filter operation
> cv.cvSmooth(image, image, cv.CV_GAUSSIAN, filterSize, 0, sigma)
> return image
> def opencvFilt2sigma(size):
> """OpenCV defaults to making sigma up with this formula.
> Learning OpenCV: computer vision with the OpenCV library
> By Gary Bradski, Adrian Kaehler pg 112"""
> return (( size*0.5 ) - 1)*0.30 + 0.80
> class scipyFromOpenCV(object):
> """This decorator can be used to wrap a function that takes
> and returns a numpy array into one that takes and retuns an
> opencv CvMat.
> """
> def __init__(self, f):
> self.f = f
> def __call__(self, image):
> # Convert CvMat to ndarray
> np_image = adaptors.Ipl2NumPy(image)
>
> # Call the original function
> np_image_filtered = self.f(np_image)
>
> # Convert back to CvMat
> return adaptors.NumPy2Ipl(np_image_filtered)
> cheers,
> Brian
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
>
--
Information System Engineer, Ph.D.
Website: http://matthieu-brucher.developpez.com/
Blogs: http://matt.eifelle.com and http://blog.developpez.com/?blog=92
LinkedIn: http://www.linkedin.com/in/matthieubrucher
More information about the SciPy-User
mailing list