Python中提升圖片清晰度的四種方法
1、庫(kù)的安裝
庫(kù) | 用途 | 安裝 |
---|---|---|
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
庫(kù) | 用途 | 安裝 |
---|---|---|
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
庫(kù) | 用途 | 安裝 |
---|---|---|
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
庫(kù) | 用途 | 安裝 |
---|---|---|
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
庫(kù) | 用途 | 安裝 |
---|---|---|
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)文章
對(duì)python創(chuàng)建及引用動(dòng)態(tài)變量名的示例講解
今天小編就為大家分享一篇對(duì)python創(chuàng)建及引用動(dòng)態(tài)變量名的示例講解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-11-11Python實(shí)現(xiàn)孤立隨機(jī)森林算法的示例代碼
孤立森林(isolation?Forest)是一種高效的異常檢測(cè)算法,它和隨機(jī)森林類似,但每次選擇劃分屬性和劃分點(diǎn)(值)時(shí)都是隨機(jī)的,而不是根據(jù)信息增益或基尼指數(shù)來選擇。本文將用Python實(shí)現(xiàn)這一算法,需要的可以參考一下2022-03-03Python中不同進(jìn)制的語(yǔ)法及轉(zhuǎn)換方法分析
這篇文章主要介紹了Python中不同進(jìn)制的語(yǔ)法及轉(zhuǎn)換方法,結(jié)合實(shí)例形式分析了Python不同進(jìn)制的表示方法及相互轉(zhuǎn)換方法,需要的朋友可以參考下2016-07-07淺談四種快速易用的Python數(shù)據(jù)可視化方法
這篇文章主要介紹了淺談四種快速易用的Python數(shù)據(jù)可視化方法,數(shù)據(jù)可視化,是指用圖形的方式來展現(xiàn)數(shù)據(jù),從而更加清晰有效地傳遞信息,主要方法包括圖表類型的選擇和圖表設(shè)計(jì)的準(zhǔn)則,需要的朋友可以參考下2023-04-04Python使用ffmpeg實(shí)現(xiàn)將WebM文件轉(zhuǎn)換為MP4文件
這篇文章主要介紹了Python如何使用wxPython庫(kù)創(chuàng)建一個(gè)簡(jiǎn)單的GUI應(yīng)用程序,可以實(shí)現(xiàn)將WebM文件轉(zhuǎn)換為MP4文件,文中的示例代碼講解詳細(xì),感興趣的可以動(dòng)手嘗試一下2023-08-08使用python獲取csv文本的某行或某列數(shù)據(jù)的實(shí)例
下面小編就為大家分享一篇使用python獲取csv文本的某行或某列數(shù)據(jù)的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-04-04