아이공의 AI 공부 도전기

Pytorch-wavelet 설치 및 사용법

 

 

Pytorch-wavelet 설치

 

https://pypi.org/project/pytorch-wavelet/

 

pytorch-wavelet

 

pypi.org

 

command에 아래 명령어를 통한 설치 (필자 : Anaconda prompt)

pip install pytorch-wavelet

 

github

 

https://github.com/kellman/pytorch_wavelet

 

GitHub - kellman/pytorch_wavelet: A differentiable Haar wavelet operator implementation in Pytorch.

A differentiable Haar wavelet operator implementation in Pytorch. - GitHub - kellman/pytorch_wavelet: A differentiable Haar wavelet operator implementation in Pytorch.

github.com

 

 

Pytorch-wavelet 사용법

 

1) 패키지를 불러온다.

import pytorch_wavelet

 

2) 이미지를 불러와서 torch tensor 형태로 구성한다.

 

3) 계층에 따른  wavelet decomposition을 진행한다.

 

 

 

 

 

 

코드

import torch
import matplotlib.pyplot as plt
import pytorch_wavelet as wavelet
import cv2
import numpy as np

img_path = './data/baboon.png'
img = cv2.imread(img_path, cv2.IMREAD_UNCHANGED)

img_01 = img.astype(np.float32) / 255.
img_01 = img_01[:, :, [2,1,0]]

x = torch.from_numpy(img_01)
a = wavelet.visualize(x, Nlayers = 1)

plt.figure()
plt.subplot(121)
plt.imshow(x)
plt.title('Image')
plt.subplot(122)
plt.imshow(a)
plt.title('Wavelet Decomposition')
plt.show()

 

 

공유하기

facebook twitter kakaoTalk kakaostory naver band
loading