簡體   English   中英

PIL圖像調整大小會改變像素值嗎?

[英]PIL image resize change the value of pixel?

我想在不更改像素值范圍的情況下調整PIL圖像的大小。 我已經嘗試過Image.resize()但是它將像素值范圍從[0,255]更改為[79,179]

我正在使用Python和PyTorch,在PyTorch中, transforms.resize()將實現Image.resize()

這是我使用的測試代碼

a = torch.randint(0,255,(500,500), dtype=torch.uint8)
print(a.size())
print(torch.max(a))
a = torch.unsqueeze(a, dim =0)
print(a.size())
compose = transforms.Compose([transforms.ToPILImage(),transforms.Resize((128,128))])
a_trans = compose(a)
print(a_trans.size)
print(a_trans.getextrema())

代碼的輸出為:

torch.Size([500, 500])
tensor(254, dtype=torch.uint8)
torch.Size([1, 500, 500])
(128, 128)
(79, 179)

所以有人可以解釋為什么輸出范圍是[79,179]? 如果我想在不更改值范圍的情況下進行大小調整,該怎么辦? 先感謝您

嘗試使用pil中實現的最近鄰居算法調整大小。 它不會改變像素

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM