我在使用Image.filter(ImageFilter.BLUR)方法模糊图像时遇到问题。使用PIL的模糊图像上的图像边缘不会模糊不清
我的代码:
#Open the image from the ImageField
fp_big = open(self.image_big.path, 'rb')
im_big = Image.open(StringIO(fp_big.read()))
#Resize the image
im_big.thumbnail(size_big, Image.ANTIALIAS)
#Blur the image
im_big = im_big.convert('RGB')
for i in range(10):
im_big = im_big.filter(ImageFilter.BLUR)
#Save the images
temp_handle_big = StringIO()
im_big.save(temp_handle_big, PIL_TYPE)
temp_handle_big.seek(0)
#Save image to a SimpleUploadedFile which can be saved into ImageField
suf_big = SimpleUploadedFile('%s' % os.path.split(self.image_big.name)[-1], temp_handle_big.read(), content_type=IMG_TYPE)
#Delete old images and close fps
fp_big.close()
os.remove(original_path_big)
虽然这个代码工作正常,结果是部分错:
正如你所看到的,图像的边缘不正确模糊。有谁知道为什么发生这种情况?
Thx提前。
我不太了解PIL,但这可能与图像模糊有关。我模糊图像的方式是将它分解为一个像素矩阵,并根据它周围的像素或其周围像素的某个深度修改每个像素的值。因此,bluring可能仅出现在图像像素明暗处的设定深度,或者由于不能应用卷积,因此图像的部分不会变得模糊。或者我只是在说胡话。我不知道。我不是医生。 –