简体   繁体   English

如何使用 pytorch 对图像进行双三次上采样?

[英]How to perform bicubic upsampling of image using pytorch?

I have png image.我有png图像。 I want to upsample it using bicubic interpolation.我想使用双三次插值对其进行上采样。 I found this function in pytorch:我在 pytorch 中找到了这个 function:

nn.functional.upsample(mode = "bicubic)

https://pytorch.org/docs/stable/generated/torch.nn.Upsample.html https://pytorch.org/docs/stable/generated/torch.nn.Upsample.html

But how to apply to my png image?但是如何应用于我的 png 图像? Should I turn my image into some torch tesnor?我应该把我的形象变成一些火炬张量吗? I just haven't found any example of using this function exactly on png image我只是没有找到任何在 png 图像上使用此 function 的示例

You can do this你可以这样做

import torch 
import torchvision.transforms as transforms
from PIL import Image


t = transforms.ToTensor()
img = Image.open("Table.png")

b = torch.nn.functional.upsample(t(img).unsqueeze(0),(500,400),mode = "bicubic")

you can also apply Bicubic using Image您还可以使用图像应用双三次

img = Image.open("Table.png")
re = img.resize((400, 400),Image.BICUBIC)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM