提高图像清晰度的python代码
时间: 2023-11-12 10:14:07 浏览: 114
以下是一些提高图像清晰度的Python代码:
1. 使用OpenCV库的图像模糊函数
```
import cv2
img = cv2.imread('image.jpg')
blur = cv2.GaussianBlur(img, (5, 5), 0)
cv2.imshow('Original', img)
cv2.imshow('Blur', blur)
cv2.waitKey(0)
```
2. 使用scikit-image库的锐化函数
```
from skimage import io, filters
img = io.imread('image.jpg', as_gray=True)
sharp = filters.unsharp_mask(img, radius=1, amount=1.5)
io.imshow(img)
io.imshow(sharp)
io.show()
```
3. 使用Pillow库的图像增强功能
```
from PIL import Image, ImageEnhance
img = Image.open('image.jpg')
enhancer = ImageEnhance.Sharpness(img)
enhanced_img = enhancer.enhance(2)
enhanced_img.show()
```
4. 使用TensorFlow库的超分辨率模型
```
import tensorflow as tf
from tensorflow.keras.models import load_model
import numpy as np
img = cv2.imread('image.jpg')
model = load_model('superresolution.h5')
upsampled = cv2.resize(img, None, fx=2, fy=2, interpolation=cv2.INTER_CUBIC)
upsampled = np.expand_dims(upsampled, axis=0)
superres = model.predict(upsampled)
superres = np.squeeze(superres, axis=0)
cv2.imshow('Original', img)
cv2.imshow('Superresolution', superres)
cv2.waitKey(0)
```
阅读全文