Python中提升圖片清晰度的四種方法
1、庫的安裝
| 庫 | 用途 | 安裝 |
|---|---|---|
| pillow | 圖片相關(guān) | pip install pillow -i https://pypi.tuna.tsinghua.edu.cn/simple/ |
| cv2 | 視圖相關(guān) | pip install opencv-python -i https://pypi.tuna.tsinghua.edu.cn/simple/ |
| torch | 視圖相關(guān) | ppip install torch -i https://pypi.tuna.tsinghua.edu.cn/simple/ |
| torchvision | 視圖相關(guān) | ppip install torchvision -i https://pypi.tuna.tsinghua.edu.cn/simple/ |
2、實(shí)現(xiàn)方法
方法1—PIL
| 庫 | 用途 | 安裝 |
|---|---|---|
| pillow | 圖片相關(guān) | pip install pillow -i https://pypi.tuna.tsinghua.edu.cn/simple/ |
示例代碼
from PIL import Image, ImageFilter
# 打開圖片
image = Image.open('input_image.jpg')
# 應(yīng)用銳化濾鏡
sharpened_image = image.filter(ImageFilter.SHARPEN)
# 保存結(jié)果
sharpened_image.save('sharpened_image.jpg')
方法2—cv2
| 庫 | 用途 | 安裝 |
|---|---|---|
| cv2 | 視圖相關(guān) | pip install opencv-python -i https://pypi.tuna.tsinghua.edu.cn/simple/ |
示例代碼
import cv2
import numpy as np
# 讀取圖片
image = cv2.imread('input_image.jpg')
# 高斯模糊
blurred = cv2.GaussianBlur(image, (0, 0), 3)
# 銳化
sharpened = cv2.addWeighted(image, 1.5, blurred, -0.5, 0)
# 保存結(jié)果
cv2.imwrite('sharpened_image.jpg', sharpened)
方法3—torch
| 庫 | 用途 | 安裝 |
|---|---|---|
| cv2 | 視圖相關(guān) | pip install opencv-python -i https://pypi.tuna.tsinghua.edu.cn/simple/ |
| torch | 視圖相關(guān) | ppip install torch -i https://pypi.tuna.tsinghua.edu.cn/simple/ |
| torchvision | 視圖相關(guān) | ppip install torchvision -i https://pypi.tuna.tsinghua.edu.cn/simple/ |
示例代碼
import cv2
import torch
from torchvision.transforms import ToTensor, ToPILImage
# 加載預(yù)訓(xùn)練的ESRGAN模型
model = torch.hub.load('xinntao/ESRGAN', 'esrgan', pretrained=True)
model.eval()
# 讀取圖片
image = cv2.imread('input_image.jpg')
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
image = ToTensor()(image).unsqueeze(0)
# 使用模型進(jìn)行超分辨率
with torch.no_grad():
output = model(image)
# 保存結(jié)果
output_image = ToPILImage()(output.squeeze(0))
output_image.save('super_resolution_image.jpg')
方法4—waifu2x
| 庫 | 用途 | 安裝 |
|---|---|---|
| waifu2x | 視圖相關(guān) | ppip install waifu2x -i https://pypi.tuna.tsinghua.edu.cn/simple/ |
示例代碼
from waifu2x import Waifu2x
# 創(chuàng)建waifu2x對(duì)象
waifu2x = Waifu2x()
# 提升圖片清晰度
waifu2x.upscale_image('input_image.jpg', 'output_image.jpg')
到此這篇關(guān)于Python中提升圖片清晰度的四種方法的文章就介紹到這了,更多相關(guān)Python提升圖片清晰度內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Python編程itertools模塊處理可迭代集合相關(guān)函數(shù)
本篇博客將為你介紹Python函數(shù)式編程itertools模塊中處理可迭代集合的相關(guān)函數(shù),有需要的朋友可以借鑒參考下,希望可以有所幫助2021-09-09
Python數(shù)組變形的幾種實(shí)現(xiàn)方法
本文主要介紹了Python數(shù)組變形的幾種實(shí)現(xiàn)方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-05-05
PyTorch搭建LSTM實(shí)現(xiàn)多變量多步長時(shí)序負(fù)荷預(yù)測
這篇文章主要為大家介紹了PyTorch搭建LSTM實(shí)現(xiàn)多變量多步長時(shí)序負(fù)荷預(yù)測,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-05-05
python中redis查看剩余過期時(shí)間及用正則通配符批量刪除key的方法
這篇文章主要介紹了python中redis查看剩余過期時(shí)間及用正則通配符批量刪除key的方法,需要的朋友可以參考下2018-07-07
使用Python Fast API發(fā)布API服務(wù)的過程詳解
這篇文章主要介紹了使用Python Fast API發(fā)布API服務(wù),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-04-04
python中dict獲取關(guān)鍵字與值的實(shí)現(xiàn)
這篇文章主要介紹了python中dict獲取關(guān)鍵字與值的實(shí)現(xiàn)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-05-05

