魔杖Python中的魔杖selective_blur()函数
可以在Python中使用 Wand 库执行的另一种模糊是选择性模糊。选择性模糊类似于正常模糊。不同之处在于它只影响图像中对比度低于给定量子阈值的部分。此函数中引入了一个名为阈值的新属性。
Syntax :
Python3
Python3
Python3
# import display() to show final image
from wand.display import display
# import Image from wand.image module
from wand.image import Image
# read file using Image function
with Image(filename ="koala.jpeg") as img:
# perform adaptive blur effect
# using adaptive_blur() function
img.selective_blur(radius = 8, sigma = 4,
threshold = 0.25 * img.quantum_range)
# save final image
img.save(filename ="mb_koala.jpeg")
# display final image
display(img)
Parameters :Parameter Input Type Description radius numbers.Real the radius of the, in pixels, not counting the center pixel. sigma numbers.Real the standard deviation, in pixels threshold number.Real Only pixels within contrast threshold are effected.
使用的图像:
示例 #1:
Python3
wand.image.selective_blur(radius= radius_value, sigma= sigma_value,
threshold= thrshold_value,
channel = "optional_channel_value")
# radius should always be greater than sigma(standard deviation)
输出:
示例 #2:将阈值增加到 0.5。
Python3
# import display() to show final image
from wand.display import display
# import Image from wand.image module
from wand.image import Image
# read file using Image function
with Image(filename ="koala.jpeg") as img:
# perform adaptive blur effect using
# adaptive_blur() function
img.selective_blur(radius = 8, sigma = 4,
threshold = 0.15 * img.quantum_range)
# save final image
img.save(filename ="mb_koala.jpeg")
# display final image
display(img)
输出: