pyBlur
is a simple extension to OpenCV's GaussianBlur
. There are times when you need to blur only a part of the image instead of blurring the entire image. pyBlur
can blur any arbitrary shape in an image. You just need to pass the co-ordinates and it will blur the closed polygon formed by those co-ordinates. This comes in handly when you've to blur contours as you can just pass the result of cv2.findContours
to pyBlur
's functions.
When a part of an image is blurred, most of the times it is harsh on the eyes. pyBlur
also provides a method of blurring softly such that the blurred portion blends into the image in the background.
pyblur.**BlurRect**(image, rect, ksize, sigmaX [, sigmaY])
Blurs a rectangular portion of the image defined by a numpy arrayrect
which is[x,y,width,height]
.ksize
,sigmaX
, andsigmaY
mean the same as they mean incv2.GaussianBlur
.pyblur.**BlurContours**(image, contours, ksize, sigmaX [, sigmaY])
Blurs arbitrary polygons defined by the contours.ksize
,sigmaX
, andsigmaY
mean the same as they mean incv2.GaussianBlur
.pyblur.**SoftBlurRect**(image, rect, ksize, sigmaX [,sigmaY [,mksize [,msigmaX [,msigmaY]]]], **kwargs)
Blurs a rectangular portion of the image defined by a numpy arrayrect
which is[x,y,width,height]
softly such that it blends with the background.ksize
,sigmaX
, andsigmaY
are the parameters used to blur the image once usingcv2.GaussianBlur
.mksize
,msigmaX
, andmsigmaY
are the parameters used to blur the mask usingcv2.GaussianBlur
on successive iterations.iters
can be passed tokwargs
to set the number of iterations used for soft blurring.pyblur.**SoftBlurContours**(image, contours, ksize, sigmaX [,sigmaY [,mksize [,msigmaX [,msigmaY]]]], **kwargs)
Blurs a rectangular portion of the image defined by a numpy arrayrect
which is[x,y,width,height]
softly such that it blends with the background.ksize
,sigmaX
, andsigmaY
are the parameters used to blur the image once usingcv2.GaussianBlur
.mksize
,msigmaX
, andmsigmaY
are the parameters used to blur the mask usingcv2.GaussianBlur
on successive iterations.iters
can be passed tokwargs
to set the number of iterations used for soft blurring.
(Check samples in next section)
out1 = pyblur.BlurRect(img, [500,50,100,150], 17, 5)
# Blurs rectangle with top-left point at (500,50) and of size (100,150).
# kernel = 17x17
# sigmaX = 5
out2 = pyblur.BlurContours(img, [[np.array([[500,50],[600,300],[150,200]])]], 17, 5)
# Blurs contours passed as [[np.array([[500,50],[600,300],[150,200]])]].
# The array consists of one polygon formed by points (500,50), (600,300), and (150,200).
# kernel = 17x17
# sigmaX = 5
out3 = pyblur.SoftBlurRect(img, [500,50,100,150], 27, 5)
# Soft Blurs rectangle with top-left point at (500,50) and of size (100,150).
# kernel = 27x27
# sigmaX = 5
out4 = pyblur.SoftBlurContours(img, [[np.array([[500,50],[600,300],[150,200]])],
[np.array([[800,500],[950,500],[900,650]])]], 17, 5)
# Soft Blurs contours passed as [[np.array([[500,50],[600,300],[150,200]])]].
# The array consists of two polygons formed by points \
# [(500,50), (600,300), (150,200)] and [(800,500),(950,500),(900,650)].
# kernel = 17x17
# sigmaX = 5
out5 = pyblur.SoftBlurRect(img, [500,50,100,150], 27, 5, 5, 55, iters=7)
# Soft Blurs rectangle with top-left point at (500,50) and of size (100,150).
# kernel for image = 27x27
# sigmaX for image = 5
# sigmaY for image = 5
# kernel for mask = 55x55
# no. of iterations = 7
Input